[flexcoders] Re: Delay / Pause between script executions

2009-10-23 Thread seanmcmonahan
You definitely want to use Timer here.  When you create a timer you can set the 
interval for the timer and you can set the number of times you want the timer 
to execute.  Using your example you'd get something like:

myTimer = new Timer(5000, 3); 

This will create a timer that executes every 5 seconds and it will do this 
three times.  Now you need two event handlers to handle the actual code 
execution.  Timer has two events of interest timer and timerComplete.  
TimerComplete is dispatched on the final execution of the timer (based on how 
many iterations you set).  Timer is dispatched on every other execution.  So 
wire up some event listeners for these two events and you're pretty much in 
business.  The only other thing you might need to know is what iteration the 
Timer is on.

Fortunately Timer has a property, currentCount, that tells you the current 
iteration.  You can access this in your event handler by reading event.target 
as this will be pointing to your Timer object.

Check out the livedocs page for any details I missed: 
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/Timer.html

--- In flexcoders@yahoogroups.com, Angelo Anolin angelo_ano...@... wrote:

 Hi Flexcoders,
  
 I know this may sound very elementary but I cannot figure the hell out of me 
 how to achieve this.
  
 I have a label control.  I want to display different messages after every 5 
 seconds, such as:
  
 myLabel.text = This is my first message
 // Need to delay for about 5 seconds here
  
 myLabel.text = This is my second message
 // Need to delay for about 5 seconds here
  
 myLabel.text = This is my last message
 
 I cannot figure out how to properly use the pause or timer utilities in 
 achieving this.
  
 Any idea would be appreciated.
  
 Thanks.
 Regards,
 Angelo





[flexcoders] Re: Delay / Pause between script executions

2009-10-23 Thread valdhor
Here is a simple example:

?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
layout=vertical
 creationComplete=onCreationComplete()
 mx:Script
 ![CDATA[
 private var labelTimer:Timer;
 private var messages:Array = [This is my first
message,
 This is my second message,
 This is my last message];

 private function onCreationComplete():void
 {
 labelTimer = new Timer(5000); // 5 Seconds
 labelTimer.addEventListener(TimerEvent.TIMER,
labelTimerTriggered);
 labelTimer.start();
 }

 private function labelTimerTriggered(event:TimerEvent):void
 {
 timerLabel.text = messages[labelTimer.currentCount %
messages.length];
 }
 ]]
 /mx:Script
 mx:Label id=timerLabel text=This is my first message/
/mx:Application

HTH


Steve


--- In flexcoders@yahoogroups.com, Angelo Anolin angelo_ano...@...
wrote:

 Hi Flexcoders,

 I know this may sound very elementary but I cannot figure the hell out
of me how to achieve this.

 I have a label control.  I want to display different messages after
every 5 seconds, such as:

 myLabel.text = This is my first message
 // Need to delay for about 5 seconds here

 myLabel.text = This is my second message
 // Need to delay for about 5 seconds here

 myLabel.text = This is my last message

 I cannot figure out how to properly use the pause or timer utilities
in achieving this.

 Any idea would be appreciated.

 Thanks.
 Regards,
 Angelo




Re: [flexcoders] Re: Delay / Pause between script executions

2009-10-23 Thread Angelo Anolin
Hi Steve,

Thanks for the sample code.  I was able to come up with something quite similar 
to what you have posted.

One question still remains, though.  I tried to issue a timer.stop() command 
when for example, all the text values have been displayed in the label control, 
but the timer event does not seem to stop.

How to specifically stop the timer once all the messages have been displayed?

Thanks.

Angelo





From: valdhor valdhorli...@embarqmail.com
To: flexcoders@yahoogroups.com
Sent: Saturday, 24 October, 2009 2:07:16
Subject: [flexcoders] Re: Delay / Pause between script executions

  
Here is a simple example:

?xml version=1.0 encoding=utf- 8?
mx:Application xmlns:mx=http: //www.adobe. com/2006/ mxml layout=vertical
creationComplete= onCreationCompl ete()
mx:Script
![CDATA[
private var labelTimer:Timer;
private var messages:Array = [This is my first message, 
This is my second message, 
This is my last message];

private function onCreationComplete( ):void
{
labelTimer = new Timer(5000); // 5 Seconds
labelTimer.addEvent Listener( TimerEvent. TIMER, 
labelTimerTriggered );
labelTimer.start( );
}

private function labelTimerTriggered (event:TimerEven t):void
{
timerLabel.text = messages[labelTimer .currentCount % 
messages.length] ;
}
]]
/mx:Script
mx:Label id=timerLabel text=This is my first message/
/mx:Application

HTH


Steve


--- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... wrote:

 Hi Flexcoders,
  
 I know this may sound very elementary but I cannot figure the hell out of me 
 how to achieve this.
  
 I have a label control.  I want to display different messages after every 5 
 seconds, such as:
  
 myLabel.text = This is my first message
 // Need to delay for about 5 seconds here
  
 myLabel.text = This is my second message
 // Need to delay for about 5 seconds here
  
 myLabel.text = This is my last message
 
 I cannot figure out how to properly use the pause or timer utilities in 
 achieving this.
  
 Any idea would be appreciated.
  
 Thanks.
 Regards,
 Angelo


   


  

Re: [flexcoders] Re: Delay / Pause between script executions

2009-10-23 Thread Rick Winscot
Angelo,

The source code on this post provides a means to setup recurring timed
events. In fact, the sample does exactly what you describe (updating a label
every 5 seconds). 

Timers in your app... there can be only one.
http://www.quilix.com/node/65

Cheers,

Rick Winscot
www.quilix.com



On 10/23/09 3:23 PM, Angelo Anolin angelo_ano...@yahoo.com wrote:

  
  
  
 
 Hi Steve,
 
 Thanks for the sample code.  I was able to come up with something quite
 similar to what you have posted.
 
 One question still remains, though.  I tried to issue a timer.stop() command
 when for example, all the text values have been displayed in the label
 control, but the timer event does not seem to stop.
 
 How to specifically stop the timer once all the messages have been displayed?
 
 Thanks.
 
 Angelo
 
 
 From: valdhor valdhorli...@embarqmail.com
 To: flexcoders@yahoogroups.com
 Sent: Saturday, 24 October, 2009 2:07:16
 Subject: [flexcoders] Re: Delay / Pause between script executions
 
   
  
 
 Here is a simple example:
 
 ?xml version=1.0 encoding=utf- 8?
 mx:Application xmlns:mx=http: //www.adobe. com/2006/ mxml layout=vertical
 creationComplete= onCreationCompl ete()
 mx:Script
 ![CDATA[
 private var labelTimer:Timer;
 private var messages:Array = [This is my first message,
 This is my second message,
 This is my last message];
 
 private function onCreationComplete( ):void
 {
 labelTimer = new Timer(5000); // 5 Seconds
 labelTimer.addEvent Listener( TimerEvent. TIMER,
 labelTimerTriggered );
 labelTimer.start( );
 }
 
 private function labelTimerTriggered (event:TimerEven t):void
 {
 timerLabel.text = messages[labelTimer .currentCount %
 messages.length] ;
 }
 ]]
 /mx:Script
 mx:Label id=timerLabel text=This is my first message/
 /mx:Application
 
 HTH
 
 
 Steve
 
 
 --- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... wrote:
 
  Hi Flexcoders,
   
  I know this may sound very elementary but I cannot figure the hell out of
 me how to achieve this.
   
  I have a label control.  I want to display different messages after every 5
 seconds, such as:
   
  myLabel.text = This is my first message
  // Need to delay for about 5 seconds here
   
  myLabel.text = This is my second message
  // Need to delay for about 5 seconds here
   
  myLabel.text = This is my last message
  
  I cannot figure out how to properly use the pause or timer utilities in
 achieving this.
   
  Any idea would be appreciated.
   
  Thanks.
  Regards,
  Angelo
 
   
   
 
  
   
 
 
 



[flexcoders] Re: Delay / Pause between script executions

2009-10-23 Thread valdhor
Two ways

1.  Add the repeat count parameter to the constructor:

labelTimer = new Timer(5000, messages.length);

2.  A little math is required (Arrays are zero based and the first event
triggered will have a count of 1. We need to take that into account):

?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
layout=vertical
 creationComplete=onCreationComplete()
 mx:Script
 ![CDATA[
 private var labelTimer:Timer;
 private var messages:Array = [This is my first
message,
 This is my second message,
 This is my last message];

 private function onCreationComplete():void
 {
 labelTimer = new Timer(1500);
 labelTimer.addEventListener(TimerEvent.TIMER,
labelTimerTriggered);
 labelTimer.start();
 }

 private function labelTimerTriggered(event:TimerEvent):void
 {
 if(labelTimer.currentCount  messages.length - 1)
 {
 labelTimer.stop();
 }
 timerLabel.text = messages[(labelTimer.currentCount - 1)
% messages.length];
 }
 ]]
 /mx:Script
 mx:Label id=timerLabel/
/mx:Application

--- In flexcoders@yahoogroups.com, Angelo Anolin angelo_ano...@...
wrote:

 Hi Steve,

 Thanks for the sample code.  I was able to come up with something
quite similar to what you have posted.

 One question still remains, though.  I tried to issue a timer.stop()
command when for example, all the text values have been displayed in the
label control, but the timer event does not seem to stop.

 How to specifically stop the timer once all the messages have been
displayed?

 Thanks.

 Angelo




 
 From: valdhor valdhorli...@...
 To: flexcoders@yahoogroups.com
 Sent: Saturday, 24 October, 2009 2:07:16
 Subject: [flexcoders] Re: Delay / Pause between script executions


 Here is a simple example:

 ?xml version=1.0 encoding=utf- 8?
 mx:Application xmlns:mx=http: //www.adobe. com/2006/ mxml
layout=vertical
 creationComplete= onCreationCompl ete()
 mx:Script
 ![CDATA[
 private var labelTimer:Timer;
 private var messages:Array = [This is my first
message,
 This is my second
message,
 This is my last
message];

 private function onCreationComplete( ):void
 {
 labelTimer = new Timer(5000); // 5 Seconds
 labelTimer.addEvent Listener( TimerEvent. TIMER,
labelTimerTriggered );
 labelTimer.start( );
 }

 private function labelTimerTriggered (event:TimerEven
t):void
 {
 timerLabel.text = messages[labelTimer .currentCount %
messages.length] ;
 }
 ]]
 /mx:Script
 mx:Label id=timerLabel text=This is my first message/
 /mx:Application

 HTH


 Steve


 --- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ...
wrote:
 
  Hi Flexcoders,
 
  I know this may sound very elementary but I cannot figure the hell
out of me how to achieve this.
 
  I have a label control.  I want to display different messages after
every 5 seconds, such as:
 
  myLabel.text = This is my first message
  // Need to delay for about 5 seconds here
 
  myLabel.text = This is my second message
  // Need to delay for about 5 seconds here
 
  myLabel.text = This is my last message
 
  I cannot figure out how to properly use the pause or timer utilities
in achieving this.
 
  Any idea would be appreciated.
 
  Thanks.
  Regards,
  Angelo
 




[SOLVED] - [flexcoders] Re: Delay / Pause between script executions

2009-10-23 Thread Angelo Anolin


Hi Steve,

That got it quick and easy.  Thanks a lot. Marking as solved.

Regards,

Angelo



From: valdhor valdhorli...@embarqmail.com
To: flexcoders@yahoogroups.com
Sent: Saturday, 24 October, 2009 4:11:35
Subject: [flexcoders] Re: Delay / Pause between script executions

  
Two ways

1.  Add the repeat count parameter to the constructor:

labelTimer = new Timer(5000, messages.length) ;

2.  A little math is required (Arrays are zero based and the first event 
triggered will have a count of 1. We need to take that into account):

?xml version=1.0 encoding=utf- 8?
mx:Application xmlns:mx=http: //www.adobe. com/2006/ mxml layout=vertical
creationComplete= onCreationCompl ete()
mx:Script
![CDATA[
private var labelTimer:Timer;
private var messages:Array = [This is my first message, 
This is my second message, 
This is my last message];

private function onCreationComplete( ):void
{
labelTimer = new Timer(1500);
labelTimer.addEvent Listener( TimerEvent. TIMER, 
labelTimerTriggered );
labelTimer.start( );
}

private function labelTimerTriggered (event:TimerEven t):void
{
if(labelTimer. currentCount  messages.length - 1)
{
labelTimer.stop( );
}
timerLabel.text = messages[(labelTime r.currentCount - 1) % 
messages.length] ;
}
]]
/mx:Script
mx:Label id=timerLabel /
/mx:Application

--- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... wrote:

 Hi Steve,
 
 Thanks for the sample code.  I was able to come up with something quite 
 similar to what you have posted.
 
 One question still remains, though.  I tried to issue a timer.stop() command 
 when for example, all the text values have been displayed in the label 
 control, but the timer event does not seem to stop.
 
 How to specifically stop the timer once all the messages have been displayed?
 
 Thanks.
 
 Angelo
 
 
 
 
  _ _ __
 From: valdhor valdhorlists@ ...
 To: flexcod...@yahoogro ups.com
 Sent: Saturday, 24 October, 2009 2:07:16
 Subject: [flexcoders] Re: Delay / Pause between script executions
 
 
 Here is a simple example:
 
 ?xml version=1.0 encoding=utf- 8?
 mx:Application xmlns:mx=http: //www.adobe. com/2006/ mxml layout=vertical
 creationComplete= onCreationCompl ete()
 mx:Script
 ![CDATA[
 private var labelTimer:Timer;
 private var messages:Array = [This is my first message, 
 This is my second message, 
 This is my last message];
 
 private function onCreationComplete( ):void
 {
 labelTimer = new Timer(5000); // 5 Seconds
 labelTimer.addEvent Listener( TimerEvent. TIMER, 
 labelTimerTriggered );
 labelTimer.start( );
 }
 
 private function labelTimerTriggered (event:TimerEven t):void
 {
 timerLabel.text = messages[labelTimer .currentCount % 
 messages.length] ;
 }
 ]]
 /mx:Script
 mx:Label id=timerLabel text=This is my first message/
 /mx:Application
 
 HTH
 
 
 Steve
 
 
 --- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... wrote:
 
  Hi Flexcoders,
  
  I know this may sound very elementary but I cannot figure the hell out of 
  me how to achieve this.
  
  I have a label control.  I want to display different messages after every 5 
  seconds, such as:
  
  myLabel.text = This is my first message
  // Need to delay for about 5 seconds here
  
  myLabel.text = This is my second message
  // Need to delay for about 5 seconds here
  
  myLabel.text = This is my last message
  
  I cannot figure out how to properly use the pause or timer utilities in 
  achieving this.
  
  Any idea would be appreciated.
  
  Thanks.
  Regards,
  Angelo