Changing the right click menu content in Flash with ContextMenu object
You have probably noticed many times that some Flash websites have customised right click menus. Usually Flash developers remove standard options like Zoom In and Out, Show All and Quality settings. But you can also add your own options and make them interact with your project.
Picture below represents how the standard context menu usually looks like.

In my project I want to remove all standard built - in options and add three new. The first one will be information about the author and will open a homepage website. Two other options will allow user to rotate the cards left and right.
Right click on below Flash object and select "Rotate left" or "Rotate right" to see how this work.
To start off, I create a new ContexMenu object. Then, using hideBuiltInItems() method I remove the standard options. At this stage, the context menu would look like on the picture below:

Next I create the new menu items by creating the ContextMenuItem objects. As a parameter I pass a string value representing labels like "Rotate left"... etc. ContextMenu object has an array named "customItems" to associate all the new menu options, so I use a push() method to add them.
As I want to action my menu items, I add event listeners exactly the same way as for mouse events, only the Event type is different: ContextMenuEvent.MENU_ITEM_SELECT. Then, I create the standard event handler functions to rotate banners left, right and to open my homepage.
The last and very important thing is to associate my ContexMenu object to the contextMenu property of the main movie clip.
Note that importing below classes is required (when you work from document class rather than coding from frames):
import flash.events.ContextMenuEvent;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
Sample code:
1 |
//create my context menu object |
There are few things to note. Some of the menu item captions are reserved for security reasons and can't be used (Adobe, Macromedia, Flash Player, Settings). Others can be used only with conjunction with others (Print, Zoom in etc...).
There is also no way to remove "About Flash" and "Settings" menu items.

