1 Reply Latest reply on Mar 11, 2010 10:15 AM by Peter deHaan

    cannot create ContextMenu

    Expedition_Cirkus Level 1

      I'm trying to create a contextMenu, but without any success at all.

       

      Basically I have this for the main mxml application:

       

      [Bindable]

      public var pCM:ContextMenu;

       

      private function onCreationComplete ():void {

           createCM ();

      }

      public function createCM ():void {

           pCM = new ContextMenu ();

           pCM.hideBuiltInItems();

           var tCMI:ContextMenuItem = new ContextMenuItem ("Test menu");

           tCMI.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onContextMenuTest);

           pCM.customItems.push (tCMI);

      }

      public function onContextMenuTest (evt:ContextMenuEvent):void {

           Alert.show("CM success");

      }

       

      I then add this to a top-level component by using contextMenu="{pCM}"

       

      But I cannot see the menu, what am I doing wrong?

       

      I'm using SDK 4.1 build 14632

        • 1. Re: cannot create ContextMenu
          Peter deHaan Level 4

          Works for me:

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark"
                         xmlns:mx="library://ns.adobe.com/flex/mx"
                         contextMenu="{pCM}"
                         creationComplete="onCreationComplete();">
             
              <fx:Script>
                  <![CDATA[
                      import mx.controls.Alert;
                     
                      [Bindable]
                      public var pCM:ContextMenu;
                     
                      private function onCreationComplete ():void {
                          createCM ();
                      }
                      public function createCM ():void {
                          pCM = new ContextMenu ();
                          pCM.hideBuiltInItems();
                         
                          var tCMI:ContextMenuItem = new ContextMenuItem ("Test menu");
                          tCMI.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onContextMenuTest);
                          pCM.customItems.push (tCMI);
                      }
                     
                      protected function onContextMenuTest(evt:ContextMenuEvent):void {
                          Alert.show("OK, thanks");
                      }
                  ]]>
              </fx:Script>
             
          </s:Application>

           

          Peter

          1 person found this helpful