开发者

How create Context menu in AIR application plus how add sub menu against any parent item in Flex?

How create Context menu 开发者_运维问答in AIR application plus how add sub menu against any parent item in Flex?


couldn't be simpler, as for flex I am not sure, but I think its even easier.

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

//create a new context menu to replace the default
var myContextMenu:ContextMenu = new ContextMenu();

//hide the default items
myContextMenu.hideBuiltInItems();

//create custom items:
var myMenuItem1:ContextMenuItem = new ContextMenuItem("Item 1");
var myMenuItem2:ContextMenuItem = new ContextMenuItem("Item 2");
var myMenuItem3:ContextMenuItem = new ContextMenuItem("Item 3");

//listen to the events of those items
myMenuItem1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,handleMenuItems);
myMenuItem2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,handleMenuItems);
myMenuItem3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,handleMenuItems);

//put those items inside an array
var myItems:Array = [myMenuItem1,myMenuItem2,myMenuItem3];

//put the array containing the items inside the contextMenut
myContextMenu.customItems = myItems;

//now you can apply the context menu on any display object or the root mc
this.contextMenu = myContextMenu;

//now handle clicks
function handleMenuItems(event:ContextMenuEvent):void
{
    switch (event.currentTarget)
    {
        case myMenuItem1:
            trace("you clicked the first menu Item");
        break;

        case myMenuItem2:
            trace("you clicked the second menu Item");
        break;

        case myMenuItem3:
            trace("you clicked the third menu Item");
        break;
    }
}


Have you tried........ google?

http://www.adobe.com/devnet/air/flex/quickstart/articles/adding_menus.html

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/ContextMenu.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜