Displaying context menu in Flex

Hi All,

In this article I will show how to display context menu in Flex. You can easily customize it to suitable look and feel.

//Create a menu items collection
var tmpArr:ArrayCollection=new ArrayCollection();
tmpArra.addItem({label: “Menu 1”});
tmpArra.addItem({label: “Menu 2”});
tmpArra.addItem({label: “Menu 3”});
tmpArra.addItem({label: “Menu 4”});

//Create Menu proeprty, which is going to hold the Menu items collection i.e the array created above
var myMenu:Menu = Menu.createMenu(null, tmpArra, false);

//Define the Label field
myMenu.labelField=”label”

//Add the event listener for handling mouse click on menu
myMenu.addEventListener(MenuEvent.ITEM_CLICK,itemClickInfo);

//declare the location where menu gets appear
myMenu.show((event.stageX-100), event.stageY);

//Item click handler
private function itemClickInfo(event:MenuEvent):void {
var label:String=event.item.label;
if(label==”Menu 1″){
..add your logic
}
}

Hope this helps.


Thanks
R Vashi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s