The following example shows how you can add a custom context menu item to a Sprite object by setting the Sprite’s contextMenu property to a ContextMenu object.
Full code after the jump.
// ActionScript 3.0 var red_cmi:ContextMenuItem = new ContextMenuItem("red"); red_cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, cmi_menuItemSelect); var cm:ContextMenu = new ContextMenu(); cm.customItems.push(red_cmi); cm.hideBuiltInItems(); var spr:Sprite = new Sprite(); spr.contextMenu = cm; spr.graphics.beginFill(0x000000); spr.graphics.drawRect(0, 0, 120, 90); spr.graphics.endFill(); spr.x = 10; spr.y = 10; addChild(spr); function cmi_menuItemSelect(evt:ContextMenuEvent):void { spr.graphics.clear(); spr.graphics.beginFill(0xFF0000); spr.graphics.drawRect(0, 0, 120, 90); spr.graphics.endFill(); }
{ 0 comments… add one now }