`
xiaoer_1982
  • 浏览: 1817737 次
  • 性别: Icon_minigender_2
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Flex中如何利用timer控制改变ViewStack当前选中Index的例子

阅读更多
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"
  3.     layout="vertical"
  4.     verticalAlign="middle"
  5.     backgroundColor="white"
  6.     creationComplete="init();">
  7.   <mx:Script>
  8.     <![CDATA[
  9.       private var timer:Timer;
  10.       private function init():void {
  11.         timer = new Timer(1000); /* 1000ms == 1second */
  12.         timer.addEventListener(TimerEvent.TIMER, onTimer);
  13.       }
  14.       private function onTimer(evt:TimerEvent):void {
  15.         var idx:uint = viewStack.selectedIndex;
  16.         var max:uint = viewStack.numChildren;
  17.         var newIdx:uint = ++idx % max;
  18.         viewStack.selectedIndex = newIdx;
  19.       }
  20.       private function startTimer():void {
  21.         if (!timer.running) {
  22.           timer.start();
  23.         }
  24.       }
  25.       private function stopTimer():void {
  26.         if (timer.running) {
  27.           timer.stop();
  28.         }
  29.       }
  30.     ]]>
  31.   </mx:Script>
  32.   <mx:ApplicationControlBardock="true">
  33.     <mx:Buttonlabel="Start timer" click="startTimer();" />
  34.     <mx:Buttonlabel="Stop timer" click="stopTimer();" />
  35.     <mx:Spacerwidth="100%" />
  36.     <mx:Labeltext="selectedIndex:" />
  37.     <mx:HSliderid="slider"
  38.         minimum="0"
  39.         maximum="3"
  40.         liveDragging="true"
  41.         snapInterval="1"
  42.         tickInterval="1"
  43.         change="viewStack.selectedIndex = event.value;"/>
  44.   </mx:ApplicationControlBar>
  45.   <mx:ViewStackid="viewStack" width="100%" height="100%">
  46.     <mx:VBoxbackgroundColor="haloBlue"
  47.         width="100%"
  48.         height="100%">
  49.       <mx:Labeltext="VBox 1" />
  50.     </mx:VBox>
  51.     <mx:VBoxbackgroundColor="haloGreen"
  52.         width="100%"
  53.         height="100%">
  54.       <mx:Labeltext="VBox 2" />
  55.     </mx:VBox>
  56.     <mx:VBoxbackgroundColor="haloOrange"
  57.         width="100%"
  58.         height="100%">
  59.       <mx:Labeltext="VBox 3" />
  60.     </mx:VBox>
  61.     <mx:VBoxbackgroundColor="haloSilver"
  62.         width="100%"
  63.         height="100%">
  64.       <mx:Labeltext="VBox 4" />
  65.     </mx:VBox>
  66.   </mx:ViewStack>
  67. </mx:Application>
本文转自:http://blog.minidx.com/2009/01/29/2040.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics