开发者

Flex ActionScript XMLList Menu Bar problem

开发者 https://www.devze.com 2023-02-28 13:05 出处:网络
I am working in Flex 4, and wana use MenuBar control, 开发者_StackOverflow中文版it requires XMLList to populate its items, but the problem is, i want to apply if conditions on sub items of my menu, le

I am working in Flex 4, and wana use MenuBar control, 开发者_StackOverflow中文版it requires XMLList to populate its items, but the problem is, i want to apply if conditions on sub items of my menu, let me explain my problem with example:

var menubarXML:XMLList;

menubarXML=
<>
   <menuitem label="File">
   <menuitem label="New Sheet" data="new_sheet"/>
   <menuitem label="Open Existing" data="open_sheet"/>
   <menuitem label="Print" data="print"/>
   //i want to apply condition here     
   <menuitem label="Save" data="save_pdf"/>
   <menuitem label="Exit" data="exit"/>
   </menuitem>
</>

For example, how can i apply condition like if (anyflag==true) disable my save menu sub item, of course the question is simple, and this issue can easily be tackled in Java and PHP.


Have an attribute in your XML with enable = true or false;

<menuitem label="File">
<menuitem label="New Sheet" data="new_sheet" enable = "true"/>
<menuitem label="Open Existing" data="open_sheet" enable = "true"/>
<menuitem label="Print" data="print" enable = "false"/>
</menuitem>

Now while parsing your xml check whether the enable is true or false, based on that you can control your menu and its child items.


You can also define you own discriptor for your menu in which you override method isEnabled to enable or disable an items using tag on renderering sample is as

public class MyDescriptor extends DefaultDataDescriptor
{

    public function MyDescriptor()
    {
        super();

    }

    override public function isEnabled(node:Object):Boolean
    {
                    return 'true'==node.anytag;
    }

}

and Menu is then created as

menu = Menu.createMenu(this, dataprovider, false);
menu.dataDescriptor = new MyDescriptor();

Hopes that helps

0

精彩评论

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