Right mouse click menu example
Line Break
Author: Roelof (11 Articles) - Author Website
Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer, travelling or just being lazy. He is also the co-owner of Flex-Blog.com.
Ever wondered how to add your own right click menu item in the Context Menu of your Flex Application.
In this example I will show you step by step how to achieve this, with ofcourse a small demo application to show the result.
Step 1: Import the FlexGlobals in your Script section
1 2 | // Context Menu Import import mx.core.FlexGlobals; |
Step 2: Add some Bindable variables.
1 2 3 | // Context Menu Variables [Bindable] private var cm:ContextMenu; [Bindable] private var myContextMenuItem:ContextMenuItem; |
Step 3: Create a function (which you should call on initialize) to add the Context Menu Item.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | private function addItemToContextMenu():void { // Create new instance of contextMenuItem (put your own text in it :-)) myContextMenuItem = new ContextMenuItem("Let's visit Flex-Blog.com!", false, true, true); // Add event listener (handles the click on the item) myContextMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, myContextMenuItem_menuItemSelect); // Get the Context Menu cm = FlexGlobals.topLevelApplication.contextMenu; // Hide default context menu items cm.hideBuiltInItems(); // Add item cm.customItems.push(myContextMenuItem); } Step 4: Create the Event Handler for the click on your menu item. In this example we will open the url http://www.flex-blog.com. [cc lang="actionscript"] // The Event Handler private function myContextMenuItem_menuItemSelect(evt:ContextMenuEvent):void { // Navigate to Flex-Blog.com when the item is clicked navigateToURL(new URLRequest("http://www.flex-blog.com")); } |
Thats it! You have now created your own Context Menu Item to your Context.
And ofcourse the demo (View Source is enabled).
For more examples how to use this check out our WordPress Contact Form Plugin and our WordPress Flash CountDown Plugin.
Related posts:


(