Bind the Selected Index of a ViewStack to a Variable

<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" click="changeViewStack()">
<mx:Script>
[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:HBox>
<mx:VBox height="{this.height}" width="{this.width}">
<mx:Label text="Second View Item"/>
</mx:VBox>
<mx:Canvas height="{this.height}" width="{this.width}">
<mx:Label text="Third View Item"/>
</mx:Canvas>
</mx:ViewStack>
</mx:Canvas>
</mx:Application>
Related examples in the same category