我有一个 Flex 应用程序,需要以编程方式生成一个菜单,它将非常复杂和动态。这样做的最佳技术是什么?
更新:我已经使用 RIAstar 建议的菜单项和子属性的对象测试了下面的代码。这是有效的,除了我没有看到“输入”菜单,它似乎被绕过了。我看到的是:
我期待“添加->输入->设备{0..8}”。
感谢您的任何想法,弗雷德。
<?xml version="1.0" encoding="utf-8"?>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Menu;
protected function button1_clickHandler(event:MouseEvent):void
{
var toplevelMenu:Object = new Object();
toplevelMenu.label = "Top Level";
var addMenu:Object = new Object();
addMenu.label = "Add";
toplevelMenu.children = addMenu;
var inputMenu:Object = new Object();
inputMenu.label = "Input";
var inputDevicesMenu:ArrayCollection = new ArrayCollection();
for (var i:int = 0;i < 10;i++) {
if ((i % 2) == 0) {
var inputDeviceMenu:Object = new Object();
inputDeviceMenu.label = "Device " + i;
inputDevicesMenu.addItem(inputDeviceMenu);
}
}
if (inputDevicesMenu.length > 0) {
inputMenu.children = inputDevicesMenu;
}
addMenu.children = [inputMenu];
var menu:Menu = Menu.createMenu(this, toplevelMenu, false);
menu.show(event.stageX, event.stageY);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button x="56" y="28" label="Show Menu" click="button1_clickHandler(event)"/>