The following example shows how you can add custom context menu items to a Flex application by creating new ContextMenuItem objects and adding them to the Flex application’s customItems array (via the contextMenu property).
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2008/11/07/adding-custom-context-menu-items-to-a-flex-application/ --> <mx:Application name="Application_contextMenu_test" xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" initialize="init();"> <mx:Script> <![CDATA[ private function init():void { var customMenuItem1:ContextMenuItem = new ContextMenuItem("Flex SDK " + mx_internal::VERSION, false, false); var customMenuItem2:ContextMenuItem = new ContextMenuItem("Player " + Capabilities.version, false, false); var contextMenuCustomItems:Array = application.contextMenu.customItems; contextMenuCustomItems.push(customMenuItem1); contextMenuCustomItems.push(customMenuItem2); } ]]> </mx:Script> <mx:Label text="Right click to see custom context menu items." /> </mx:Application>
View source is enabled in the following example.

{ 9 comments… read them below or add one }
Could not see any of the GUMBO examples. “It says download
error. Try to download again?” I have Flash 10 installed in
my computer. I am using a XP machine.
Ram,
This isn’t a Gumbo example (and should only require Flash Player 9.0.115.0), but what version of Flash Player 10 are you using? http://blog.flexexamples.com/about-you/
Does this happen in all browsers, or just one?
Peter
Very Nice Example
I extended your example by adding an event listener and navigating to a webpage!
It works fine, but when i do right click on a swf loader, it doesnt navigate to webpage (seems like it simply bypass the event)
Could you please find the solution of this problem?
My code is here
//in initApp
mx.core.Application.application.contextMenu.hideBuiltInItems();
var mnuCRight:ContextMenuItem = new ContextMenuItem(“Copyright © 2008″, true);
mnuCRight.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, ctMenu);
mx.core.Application.application.contextMenu.customItems.push(mnuCRight);
//function
private function ctMenu(event:ContextMenuEvent):void
{
navigateToURL(new URLRequest(“www.myweb.com”), “_blank”);
}
Nice, but dont let your immagination be kissed by the idea to add “select all” menu item. You’ll never see it :( Maybe its a “reserved” label …
Massic,
Correct, “Select All” is a reserved/restricted word. For a complete list, see http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/ui/ContextMenuItem.html
Peter
Hi,i want to ask..What should i do suppose i want to add a link to the context menu items on it??Thanks…
What About Example for Flex 4 beta 2?
@MechanisM,
It’s almost exactly the same, except replace
application.contextMenu.customItemswithFlexGlobals.topLevelApplication.contextMenu.customItems, as seen in the following example:Peter
New example posted; “Adding custom context menu items to a Flex 4 application”
Peter