1

我正在尝试使用带有数组的 flex 组合框来更改为视图堆栈中的画布。我可以使用一些自定义操作脚本来做到这一点吗?我正在设计的 UI 真的可以从中受益。

4

3 回答 3

3

这是一个小演示应用程序,演示了您要执行的操作:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

    <mx:Script>
        <![CDATA[
            import mx.core.Container;

            private function onComboBoxChange():void
            {
                stackNav.selectedChild = this[comboNav.selectedItem];
            }            

        ]]>
    </mx:Script>

    <mx:ComboBox id="comboNav" dataProvider="{['canvas1','canvas2']}" change="onComboBoxChange()"/>

    <mx:ViewStack id="stackNav" width="400" height="300">
        <mx:Canvas id="canvas1" width="100%" height="100%">
           <mx:Label text="Hello" horizontalCenter="0" verticalCenter="0"/>
        </mx:Canvas>
        <mx:Canvas id="canvas2" width="100%" height="100%">
           <mx:Label text="World!" horizontalCenter="0" verticalCenter="0"/>
        </mx:Canvas>
    </mx:ViewStack>

</mx:Application>

您也可以更改 onComboBoxChange() 中的逻辑以使用 selectedIndex :

stackNav.selectedIndex = comboNav.selectedIndex;
于 2009-05-22T00:35:10.553 回答
0

您可以使用此解决方案,但请注意,您不能使用空格插入单词(尝试将“canvas1”更改为“canvas 1”),您将看到:

[Bindable] private  var models:Array = ["tasks","users","bugs"];
public function changeViewStackModel():void { 
    //this.modelViewStack.selectedChild=users; //works
//this.modelViewStack.selectedChild="users"; //does not work
//this.modelViewStack.selectedChild=this.modelsCombo.selectedItem; //does not work

    switch(modelsCombo.selectedItem) {
    case "tasks": modelViewStack.selectedChild=tasks; break;
    case "users": modelViewStack.selectedChild=users; break;
    case "bugs": modelViewStack.selectedChild=bugs; break;
    }

}

MXML 代码:

<mx:ComboBox id="modelsCombo" dataProvider="{models}" selectedIndex="0"   
    change="changeViewStackModel()"/>
    <mx:ViewStack x="29.25" y="55" id="modelViewStack" width="90%" height="200">
        <mx:Canvas id="tasks" label="Tasks"><mx:Label text="Tasks stack view!!"/>
        </mx:Canvas>
        <mx:Canvas id="users" label="Users"><mx:Label text="Users stack view!!"/>
        </mx:Canvas>
        <mx:Canvas id="bugs" label="Bugs"><mx:Label text="Bugs stack view!!"/>
        </mx:Canvas>
    </mx:ViewStack>
于 2010-07-28T12:21:58.693 回答
0

或者您可以将 viewStack 的 selectedIndex 绑定到组合的 selectedIndex 属性:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    <mx:ComboBox id="comboNav" dataProvider="{['canvas1','canvas2']}"/>

    <mx:ViewStack id="stackNav" width="400" height="300"
        selectedIndex="{comboNav.selectedIndex}">
        <mx:Canvas id="canvas1" width="100%" height="100%">
           <mx:Label text="Hello" horizontalCenter="0" verticalCenter="0"/>
        </mx:Canvas>
        <mx:Canvas id="canvas2" width="100%" height="100%">
           <mx:Label text="World!" horizontalCenter="0" verticalCenter="0"/>
        </mx:Canvas>
    </mx:ViewStack>

</mx:Application>
于 2009-05-28T14:29:08.223 回答