开发者

creating submenu's in flex context menu

Is there any workaround to c开发者_Go百科reate submenu in a flex context menu other than stopping right click from javascript.

Regards,


Hi Frank,

Yes, I want to create submenus in a context menu. Can you help me here.

Regards,


Hi Frank,

I need the context menu for the application not for datagrid.

In my initial question the phrase "other than stopping right click from javascript" means

"catch the right click in html, call a javascript function and over js call a as function."

The project that you have specified does the above procedure. I don't want to use this

procedure. Is there any other way for achieving submenus in a flex context menu. Could you

please tell me if so..

Regards, Arvind


Yes, there is.

I don't know, what you exactly mean with this:

other than stopping right click from javascript.

But, if you want to create a entry in submenu, do this:

//Instance of my own class
private var myContext:myContextMenu = new myContextMenu();
application.contextMenu = myContext.myContextMenu;

//Here is the Class:
package com.my.components
{
    /* ////////////////////////////////////////////
    ///// My Context Menü /////////////////////
    ///////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////////////////////
    //to use:                                                                      //
    // private var myContext:MyContextMenu = new MyContextMenu();                  //
    // init() in creationComplete                                                  //
    // application.contextMenu = myContext.myContextMenu;                          //
    ////////////////////////////////////////////////////////////////////////////// */


    import flash.display.Sprite;
    import flash.events.ContextMenuEvent;
    import flash.net.URLRequest;
    import flash.net.navigateToURL;
    import flash.text.TextField;
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuBuiltInItems;
    import flash.ui.ContextMenuItem;

    public class MyContextMenu extends Sprite
    {

        public var myContextMenu:ContextMenu;
        private var menuLabel:String = String.fromCharCode(169)+" My Company GmbH";

        public function MyContextMenu()
        {
            myContextMenu = new ContextMenu;
            removeDefaultItems();
            addCustomItems();
            myContextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, menuSelectHandler);

            super();
        }

        private function removeDefaultItems():void
        {
            myContextMenu.hideBuiltInItems();
            var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
            defaultItems.print = true;
        }

        private function addCustomItems():void
        {
            var item:ContextMenuItem = new ContextMenuItem(menuLabel);
            myContextMenu.customItems.push(item);
            item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemSelectHandler);
        }

        private function menuSelectHandler(event:ContextMenuEvent):void
        {
        }

        private function menuItemSelectHandler(event:ContextMenuEvent):void
        {
            navigateToURL(new URLRequest('http://www.my-company.de'));
        }

        private function createLabel():TextField
        {
            var txtField:TextField = new TextField();
            //txtField.text = textLabel;
            txtField.text = "RightClickHere";
            return txtField;
        }
    }
}

Have fun

EDIT: There is an interesting project here. They catch the right click in html, call a javascript function and over js call a as function.

Unfortunately, the limitation of FP or NativeMenu APi allowed just on level contextmenu. Read here

Frank

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜