我们需要将ViewStack的selectedIndex属性绑定到一个可以在组件的其他地方改变的整数
变量。
申明一个可绑定的变量,然后将ViewStack 控件的选中索引属性绑定到它上。
在LinkBar 控件的情形下,ViewStack 的选中项目会自动绑定到LinkBar 的选中项目上。当
使用其它控件时,ViewStack 或其他拥有多个同时显示的子组件的控件的选中索引或者项
目,需要绑定到一个可绑定的变量或者对其设置事件。要使用其他方法来控制ViewStack,
将ViewStack 的selectedIndex 属性绑定到变量上,然后在程序运行时改变其值。
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" click="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 Item" y="40"/> </mx:Canvas> </mx:ViewStack> </mx:Canvas>