Tips: How To Customize Right-click Menu In ActionScript 3

apple-menu-icon Somebody who read Replace the Flex’s Default Right Click Menu asked how to do the same with Flash AS3. In fact, AS3 provides the class named ContextMenu to controls the menu, and classes that handle the ContextMenuItem properties and ContextMenuEvent events.

The following is part description of ContextMenu class, you can get more details on Adobe Livedocs.

The ContextMenu class provides control over the items in the Flash Player context menu. Users open the context menu by right-clicking (Windows) or Control-clicking (Macintosh) Flash Player. You can use the methods and properties of the ContextMenu class to add custom menu items, control the display of the built-in context menu items (for example, Zoom In and Print), or create copies of menus.

I built a simple fla, which add two items on the top. Here is live demo( Right click pls )

How To Customize Right-click Menu In ActionScript 3

Here is AS3 source code:

var menuItem1:ContextMenuItem = new ContextMenuItem("Welcome to Ntt.cc");
var menuItem2:ContextMenuItem = new ContextMenuItem("Contact Us");
menuItem1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,reg);
menuItem2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,F);
var myMenu:ContextMenu = new ContextMenu();
myMenu.hideBuiltInItems();
myMenu.customItems.push(menuItem1);
myMenu.customItems.push(menuItem2);
contextMenu = myMenu;
function reg(e:ContextMenuEvent) {
var tagetURL:URLRequest = new URLRequest("http://ntt.cc/");
navigateToURL(tagetURL);
}
function F(e:ContextMenuEvent) {
var tagetURL:URLRequest = new URLRequest("http://ntt.cc/about/");
navigateToURL(tagetURL);
}
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to Ntt.cc

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

Leave a Reply