Flex 问题:我可以在 Flex 中使用 ComboBox 来更改视图堆栈吗?

发布于 2024-07-21 03:00:57 字数 86 浏览 10 评论 0原文

我正在尝试使用 Flex 中的组合框和数组来更改为视图堆栈中的画布。 我可以使用一些自定义操作脚本来做到这一点吗? 我正在设计的用户界面确实可以从中受益。

I am trying to use a combobox in flex with an array to change to a canvas in a view stack.
Can I do this with some custom action script? The UI I am designing could really benefit form this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

漆黑的白昼 2024-07-28 03:00:57

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

<?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;

Here's a little demo app that demonstrates what you are trying to do:

<?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>

You can change the logic in onComboBoxChange() to use selectedIndex as well:

stackNav.selectedIndex = comboNav.selectedIndex;
夜未央樱花落 2024-07-28 03:00:57

或者您可以将 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>

Or you can bind the selectedIndex of the viewStack to the selectedIndex property of the combo:

<?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>
舞袖。长 2024-07-28 03:00:57

您可以使用此解决方案,但请注意,您不能将单词与空格分开
(尝试将“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>

You can use this solution, but be warned that you can not pike a word with space
(try to change "canvas1" to "canvas 1") and you will see:

[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 code:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文