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

//Add the event listener for handling mouse click on menu

//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.

R Vashi

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.