首页 > 设计 > WEB开发 > 正文

3.14.将ViewStack 的选中索引数绑定到一个变量上

2023-08-08 22:33:13
字体:
来源:转载
供稿:网友
3.14.1 问题
我们需要将ViewStack的selectedIndex属性绑定到一个可以在组件的其他地方改变的整数变量。
3.14.2 解决办法
申明一个可绑定的变量,然后将ViewStack 控件的选中索引属性绑定到它上。
3.14.3 讨论
在LinkBar 控件的情形下,ViewStack 的选中项目会自动绑定到LinkBar 的选中项目上。当使用其它控件时,ViewStack 或其他拥有多个同时显示的子组件的控件的选中索引或者项目,需要绑定到一个可绑定的变量或者对其设置事件。要使用其他方法来控制ViewStack,将ViewStack 的selectedIndex 属性绑定到变量上,然后在程序运行时改变其值。
+展开
-XML
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxmlwidth="400"
height="300click="changeViewStack()">

<mx:Script>
<![CDATA[
[Bindable]
private var selectedIndexInt:int = 0;
private function changeViewStack():void
{
if(selectedIndexInt == 2)
{
selectedIndexInt = 0;
}
else
{
selectedIndexInt++;
}
}

]]>
</mx:Script>
<mx:ViewStack selectedIndex="{selectedIndexInt}">
<mx:HBox height="{this.height}width="{this.width}">
<mx:Label text="First View Item"/>
<mx:Label text="First View Item"/>
</mx:HBox>
<mx:VBox height="{this.height}width="{this.width}">
<mx:Label text="Second View Item"/>
<mx:Label text="Second View Item"/>
</mx:VBox>
<mx:Canvas height="{this.height}width="{this.width}">
<mx:Label text="Third View Item"/>
<mx:Label text="Third View Itemy="40"/>
</mx:Canvas>
</mx:ViewStack>
</mx:Canvas>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表