AS3: Right Click & Context Menu
This tutorial will teach you how to create a custom right click menu or context menu in Flash ActionScript 3.
Accomplishing this task will require using the ContextMenu Class and the ContextMenuItem Class.
Step 1: Create a new Flash movie with the ActionScript version set to 3.0. The background color, frame rate and the stage size do not matter for this tutorial.

Step 2: Right-click the only frame and select Actions to open Actions panel.

Step 3:Copy and paste this code to your Actions panel.
var MyMenu:ContextMenu = new ContextMenu();
var menu_Item1:ContextMenuItem=new ContextMenuItem(”item 1″);
var menu_Item2:ContextMenuItem=new ContextMenuItem(”item 2″);
var menu_Item3:ContextMenuItem=new ContextMenuItem(”item 3″);
var menu_Item4:ContextMenuItem=new ContextMenuItem(”Go to alltutz.com!”);menu_Item4.separatorBefore=true;
menu_Item4.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, OpenAllTutz);
function OpenAllTutz(event : ContextMenuEvent):void {
var url:URLRequest=new URLRequest(”http://www.alltutz.com“);
navigateToURL(url,”_blank”);
}MyMenu.hideBuiltInItems();
MyMenu.customItems.push(menu_Item1, menu_Item2, menu_Item3, menu_Item4);this.contextMenu=MyMenu;
Note: As you can see it’s very simple to make your custom contact menu. You can add as many as items that you want. We can also create listener functions to carry out some other tasks as well. For example, here we have added a listener function to menu_Item4 to open a link to alltutz.com homepage!
That’s it, We are done! You can now test the movie and see your custom context menu
!
Downloads:
Flash CS3: Right Click & Context Menu
Flash CS4: Right Click & Context Menu









Follow AllTutz on Twitter
Hello from Russia!
Can I quote a post in your blog with the link to you?