Add Context menu in Adobe AIR or FLEX.

By | January 15, 2011

This sample shows how to add a menu to your context menu or the right click of your menu in Adobe AIR. AIR Uses the ContextMenu class to add menu to your mouse right click.

  import flash.events.ContextMenuEvent;
   import mx.controls.Alert;
   // call this function to create context menu in AIR and FLex
   private function createContextMenu():void
   {
      var myContextMenu:ContextMenu = new ContextMenu();
     this.contextMenu = myContextMenu;       //add menu items

     var myMenuItem1:ContextMenuItem = new ContextMenuItem('Menu Item 1');
     var myMenuItem2:ContextMenuItem = new ContextMenuItem('Menu Item 2');

     myContextMenu.customItems = [myMenuItem1, myMenuItem2 ];

     //add event listeners to menu items
     myMenuItem1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemClick1);
     myMenuItem2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemClick2);

    }     // listener functions for context menu items
       private function menuItemClick1(event:Event):void
       {
        //Write here the code for on click of item 1
        Alert.show('Menu Item 1 clicked');
       }
       private function menuItemClick2(event:Event):void{
           //Write here the code for on click of item 2
           Alert.show('Menu Item 2 clicked');
   }
 ]]>

2 thoughts on “Add Context menu in Adobe AIR or FLEX.

  1. Pingback: How to display a context menu from a fragment? | Free Tools Successful Bloggers Are Using

  2. Pingback: How to display a context menu from a fragment? | All Things Gadget

Leave a Reply

Your email address will not be published. Required fields are marked *