![]() |
![]() |
||||||
|
|||||||
| Tags: creating, function, timer |
![]() |
|
|||
|
I need an event to fire at a periodic 1 second rate as long as the app is
running. I looked at the examples and found this (see Below): I am pretty new to flex, so what got me puzzled is the "package". all I am looking for is to use this timer function and create use the event listener function to do my bidding. my code looks like this, but its a no go. <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="TimerExample()" color="#060606" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#4B679F, #4B679F]"> <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.controls.Alert; import flash.utils.Timer; import flash.events.TimerEvent; import flash.events.Event; public function TimerExample():void { var delay:uint = 1000; var repeat:uint = 300; var myTimer:Timer = new Timer(delay, repeat); myTimer.addEventListener(TimerEvent.TIMER, timerHandler); myTimer.start(); } publicprivate function timerHandler(e:TimerEvent):void { trace("We got here"); } ]]> </mx:Script> </mx:Application> package { import flash.utils.Timer; import flash.events.TimerEvent; import flash.display.Sprite; public class TimerExample extends Sprite { public function TimerExample() { var myTimer:Timer = new Timer(1000, 2); myTimer.addEventListener("timer", timerHandler); myTimer.start(); } public function timerHandler(event:TimerEvent):void { trace("timerHandler: " + event); } } } |
| Sponsored Links |
|
|||
|
Here tis...
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="TimerExample()"> <mx:Script> <![CDATA[ import flash.utils.Timer; import flash.events.TimerEvent; private function TimerExample():void { var myTimer:Timer = new Timer(1000, 0); myTimer.addEventListener(TimerEvent.TIMER, timerHandler); myTimer.start(); } private var cnt:uint = 1; private function timerHandler(e:TimerEvent):void{ if(cnt++ % 2){ vb.setStyle("backgroundColor","red"); }else{ vb.setStyle("backgroundColor","blue"); } } ]]> </mx:Script> <mx:VBox width="100" height="100" backgroundColor="blue" id="vb"/> </mx:Application> |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise