Guest User

Untitled

a guest
Aug 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. How to wait for 3 seconds in ActionScript 2 or 3?
  2. public function foo(param1, param2, param3) {
  3. //do something here
  4. //wait for 3 seconds
  5. //3 seconds have passed, now do something more
  6. }
  7.  
  8. var timer:Timer = new Timer(3000);
  9. timer.addEventListener(TimerEvent.TIMER, callback); // will call callback()
  10. timer.start();
  11.  
  12. class Test {
  13. private var timer:Timer = new Timer(3000);
  14.  
  15. public function foo(param1:int, param2:int, param3:int):void {
  16. // do something here
  17. timer.addEventListener(TimerEvent.TIMER, fooPartTwo);
  18. timer.start();
  19. }
  20.  
  21. private function fooPartTwo(event:TimerEvent):void {
  22. timer.removeEventListener(TimerEvent.TIMER, fooPartTwo);
  23. timer = null;
  24. // 3 seconds have passed, now do something more
  25. }
  26. }
  27.  
  28. function foo(param1:int, param2:int, param3:int):void {
  29. var x:int = 2; // you can use variables as you would normally
  30.  
  31. // do something here
  32.  
  33. var timer:Timer = new Timer(3000);
  34. var afterWaiting:Function = function(event:TimerEvent):void {
  35. timer.removeEventListener(TimerEvent.TIMER, afterWaiting);
  36. timer = null;
  37.  
  38. // 3 seconds have passed, now do something more
  39.  
  40. // the scope is retained and you can still refer to the variables you
  41. // used earlier
  42. x += 2;
  43. }
  44.  
  45. timer.addEventListener(TimerEvent.TIMER, afterWaiting);
  46. timer.start();
  47. }
  48.  
  49. var timer = setInterval(function, 3000, param1, param2);
  50.  
  51. function (param1, param2) {
  52.  
  53. // your function here
  54. clearInterval(timer);
  55.  
  56. }
  57.  
  58. TweenMax.delayedCall(1, myFunction, ["param1", 2]);
  59.  
  60. function myFunction(param1:String, param2:Number):void
  61. {
  62. trace("called myFunction and passed params: " + param1 + ", " + param2);
  63. }
  64.  
  65. public function foo(param1, param2, param3) {
  66. //do something here
  67. trace("I gonna wait 3 seconds");
  68.  
  69. TweenMax.delayedCall(3, function()
  70. {
  71. trace("3 seconds have passed");
  72. });
  73. }
Add Comment
Please, Sign In to add comment