Posted By

weavermedia on 10/23/09


Tagged

timer as3


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

weavermedia
TrentSkunk


Calling a function after a specified delay and pass arguments - not using Timer()


 / Published in: ActionScript 3
 

  1. // setTimeout allows you to call a function after a specified delay along with arguments, which setTimer does not allow you to do
  2. // You can even make it act like a loop if you call setTimeout within its called function
  3.  
  4. var dd:uint = 2000; // ms delay before function is called
  5. var str:String = "Dog";
  6. var mc:MovieClip = new MovieClip();
  7.  
  8. var timeoutExample:uint = setTimeout(delayedFunction, dd, str, "Cat", "Monkey", 0xFFDF1B, mc);
  9.  
  10. function delayedFunction():void
  11. {
  12. trace("Delayed function ");
  13. if (arguments.length==0) {trace("No argumentys passed")};
  14. for (var i=0; i<arguments.length; i++)
  15. {
  16. trace(arguments[i]);
  17. }
  18. timeoutExample = setTimeout(loopedFunction, dd/2, Math.round(Math.random()*100));
  19. }
  20.  
  21. function loopedFunction():void
  22. {
  23. trace("Random number: "+arguments[0]);
  24. timeoutExample = setTimeout(loopedFunction, dd/2, Math.round(Math.random()*100));
  25. }

Report this snippet  

You need to login to post a comment.