Flex中如何利用timer控制改变ViewStack当前选中Index
2009-06-08 23:15
375 查看
Download: main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="init();">
<mx:Script>
<![CDATA[
private var timer:Timer;
private function init():void {
timer = new Timer(1000); /* 1000ms == 1second */
timer.addEventListener(TimerEvent.TIMER, onTimer);
}
private function onTimer(evt:TimerEvent):void {
var idx:uint = viewStack.selectedIndex;
var max:uint = viewStack.numChildren;
var newIdx:uint = ++idx % max;
viewStack.selectedIndex = newIdx;
}
private function startTimer():void {
if (!timer.running) {
timer.start();
}
}
private function stopTimer():void {
if (timer.running) {
timer.stop();
}
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button label="Start timer" click="startTimer();" />
<mx:Button label="Stop timer" click="stopTimer();" />
<mx:Spacer width="100%" />
<mx:Label text="selectedIndex:" />
<mx:HSlider id="slider"
minimum="0"
maximum="3"
liveDragging="true"
snapInterval="1"
tickInterval="1"
change="viewStack.selectedIndex = event.value;" />
</mx:ApplicationControlBar>
<mx:ViewStack id="viewStack" width="100%" height="100%">
<mx:VBox backgroundColor="haloBlue"
width="100%"
height="100%">
<mx:Label text="VBox 1" />
</mx:VBox>
<mx:VBox backgroundColor="haloGreen"
width="100%"
height="100%">
<mx:Label text="VBox 2" />
</mx:VBox>
<mx:VBox backgroundColor="haloOrange"
width="100%"
height="100%">
<mx:Label text="VBox 3" />
</mx:VBox>
<mx:VBox backgroundColor="haloSilver"
width="100%"
height="100%">
<mx:Label text="VBox 4" />
</mx:VBox>
</mx:ViewStack>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="init();">
<mx:Script>
<![CDATA[
private var timer:Timer;
private function init():void {
timer = new Timer(1000); /* 1000ms == 1second */
timer.addEventListener(TimerEvent.TIMER, onTimer);
}
private function onTimer(evt:TimerEvent):void {
var idx:uint = viewStack.selectedIndex;
var max:uint = viewStack.numChildren;
var newIdx:uint = ++idx % max;
viewStack.selectedIndex = newIdx;
}
private function startTimer():void {
if (!timer.running) {
timer.start();
}
}
private function stopTimer():void {
if (timer.running) {
timer.stop();
}
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button label="Start timer" click="startTimer();" />
<mx:Button label="Stop timer" click="stopTimer();" />
<mx:Spacer width="100%" />
<mx:Label text="selectedIndex:" />
<mx:HSlider id="slider"
minimum="0"
maximum="3"
liveDragging="true"
snapInterval="1"
tickInterval="1"
change="viewStack.selectedIndex = event.value;" />
</mx:ApplicationControlBar>
<mx:ViewStack id="viewStack" width="100%" height="100%">
<mx:VBox backgroundColor="haloBlue"
width="100%"
height="100%">
<mx:Label text="VBox 1" />
</mx:VBox>
<mx:VBox backgroundColor="haloGreen"
width="100%"
height="100%">
<mx:Label text="VBox 2" />
</mx:VBox>
<mx:VBox backgroundColor="haloOrange"
width="100%"
height="100%">
<mx:Label text="VBox 3" />
</mx:VBox>
<mx:VBox backgroundColor="haloSilver"
width="100%"
height="100%">
<mx:Label text="VBox 4" />
</mx:VBox>
</mx:ViewStack>
</mx:Application>
相关文章推荐
- Flex中如何利用timer控制改变ViewStack当前选中Index的例子
- 获取当前Tableview选中行的index
- Flex中如何通过监听scroll事件检测用户改变DateChooser控件选中月份的例子
- 在利用ContextMenu处理长按事件时如何找到当前View的问题
- Flex中如何利用openItems属性,检测当前Tree的哪一个节点被展开
- Flex中如何利用closeButtonSkin或closeButtonUpSkin, closeButtonOverSkin, closeButtonDownSkin, closeButtonDisabledSkin样式,改变TitleWindow容器的
- Flex中如何利用folderOpenIcon, folderClosedIcon和defaultLeafIcon样式改变默认文件夹和子项目图标的例子
- 切换导航标签实现当前标签颜色改变以及利用js如何准确获取当前页面url网址信息
- [Flex] ButtonBar系列——如何给ButtonBar添加一个ViewStack
- flex中ViewStack利用按钮做导航
- Flex的TextArea控件中如何利用setSelection事件设定文本选中范围的例子
- UIPickerView控件中自定义 及 改变当前选中的Item的字体颜色
- Android 中如何才能让 StackView 的 OnItemSelectedListener 侦听器响应选中事件
- DataGirdView如何改变选中的CheckBox行的背景颜色:
- Flex中如何利用PopUpManager类在TitleWindow的弹出窗口中播放一段影像(VideoDisplay)的例子
- [WCF权限控制]利用WCF自定义授权模式提供当前Principal[实例篇]
- flex如何获取到当前月份的最后一天
- 当时遇到的主要难点在于TextView的内容不会刷新改变值,今天终于通过Timer和Handler实现了,分享给大家
- ViewPager 如何得到当前的Fragment (使用FragmentPagerAdapter)
- 利用 SpannableStringBuilder 改变textview中字体的颜色