开发者

How to open a menu automatically with a shortcut?

I have a MenuBar which contains general menu items like File, View, Tools ,Help. I have sub items in each of those menuitems. The problem is that i want to open the 'File' menu automatically when i press Alt+f key. I could capture the keyevents on the view.

But how to open the File Menu of the MenuBar (what is the function that needs to be called from MenuBar Class to popup those sub menuitems) ? I have searched for some information on google .. but cudnt find. or else if u have any better solution or example ..plz do post it.

<root>
    <menuitem label="File">
        <menuitem label="New" enabled="false"/>
        <menuitem label="Open.." enabled="false"/>
        <menuitem label="Save" enabled="false"/>
        <menuitem label="Restore" enabled="false"/>
        <menuitem label开发者_开发问答="Print" enabled="true"/> 
        <menuitem type="seperator" enabled="false"/> 
        <menuitem label="Exit" enabled="true"/>    
    </menuitem> 
    <menuitem label="View" accesskey="v">
        <menuitem label="Zoom In" enabled="true" maxValue="200"/>
        <menuitem label="Zoom Out" enabled="true" maxValue="25"/>
    </menuitem>       
    <menuitem label="Tools" enabled="false">
        <menuitem label="item1" enabled="false"/>
        <menuitem label="item2" enabled="false"/>
    </menuitem> 

</root>

Thanks in advance :)

Sriss


To open a menu at its position :

var fileMenu:Menu = mnuBar.getMenuAt(0);
pnt : Point = new Point(mnuBar.x,mnuBar.y + mnuBar.height);
pnt = localToGlobal(pnt);
fileMenu.show(pnt.x,pnt.y);  


I solved it :)

var fileMenu:Menu = myMenuBar.getMenuAt(0);

fileMenu.show();

It works, but now the problem is .. the submenu is popping out at (0,0) location of the application not at the file Menu item ..!!!


It's a fake Menu!

A better way to do it is:

e.preventDefault();     // will play against pressed ESC, too
menuBar.setFocus();
menuBar.dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, false, false, 0, Keyboard.RIGHT));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜