martedì, giugno 17, 2008

Flash Context Menu

A nice code example I adapted from a larger masterwork Filippo Lughi. I highly recommend checking out his awesome site: http://www.FlepStudio.org.

It’s sometimes a great feature to be able to redefine the context (right-click) menu in a Flash project.

import flash.events.ContextMenuEvent;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;

initMenu();

function initMenu():void
{
var contextMenuStr:String='Mr. Entropy';
var cm:ContextMenu=new ContextMenu();
var item:ContextMenuItem=new ContextMenuItem(contextMenuStr);
cm.hideBuiltInItems();
cm.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,itemHandler1);
this.contextMenu=cm;
}

function itemHandler1(event:ContextMenuEvent):void
{
var url:String='http://www.mrentropy.com/';
var request:URLRequest=new URLRequest(url);
navigateToURL(request,'_parent');

}