Adobe Dreamweaver Forums



Last 10 THreads :         Creating a boundry in the stage... (Last Post : Rob Dillon - Replies : 1 - Views : 2 )           »          Re: Mouse capture won't activate (Last Post : robertnagle - Replies : 0 - Views : 1 )           »          help! my FB3 has gone insane! (Last Post : peteandrus - Replies : 0 - Views : 1 )           »          help! my FB3 has gone insane! (Last Post : peteandrus - Replies : 0 - Views : 1 )           »          How come the html is being displayed, and not the link (Last Post : Skaterstu - Replies : 0 - Views : 1 )           »          Another way to accomplish this (Last Post : Andy-K - Replies : 2 - Views : 3 )           »          HELP! Cannot upload files in DW CS4 (Last Post : dan@hoppernet.org - Replies : 6 - Views : 7 )           »          Adobe Flash 10 kills Wimpy (Last Post : m77ty8uu - Replies : 32 - Views : 208 )           »          How do I unlock all files in site at once (Last Post : Alan - Replies : 1 - Views : 2 )           »          Load library clip into target on stage (Last Post : NedWebs - Replies : 5 - Views : 8 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags: , ,



Reply
  #1 (permalink)  
Old 09-05-2008, 07:14 PM
pasta Primavera
 
Posts: n/a
Diggs:
Default Creating a timer function

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);
}
}
}








Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-05-2008, 09:40 PM
Greg Lafrance
 
Posts: n/a
Diggs:
Default Re: Creating a timer function

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>

Reply With Quote
  #3 (permalink)  
Old 09-06-2008, 01:26 AM
pasta Primavera
 
Posts: n/a
Diggs:
Default Re: Creating a timer function

Thanks Greg, worked like a charm!
Reply With Quote


Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 02:20 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk