Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 07-07-2009
Member
 
Join Date: Apr 2009
Posts: 78
How to write pause, sleep, wait function

Is there such a thing as sleep command via actionscript? I have an arrow in the first frame of my movie and I want that the arrow moves about 50 pixels. And that same arrow should be moving, 5 seconds after the movie entered frame 1. The only results I get on a search for "actionscript sleep" or "actionscript pause" are in regards to the timeline. Is there any Flash function that will prevent code execution of current script from a predefined time (i.e. 500msec) without consuming CPU usage?
Reply With Quote
  #2  
Old 07-07-2009
Member
 
Join Date: Apr 2008
Posts: 193
Re: How to write pause, sleep, wait function

You need use from inerval and call function whit (setInterval) and when you want to stop function use (clearInerval). I tried a big for loop for a while, but that seems to also freeze ALL the flash on a page while its counting, and that is unacceptable.

Code:
  function callback() {
      clearInterval(callback_int);
      _root.pijl.posy = -50;
      };
      var callback_int = setInterval(this, "callback", 5000);
Reply With Quote
  #3  
Old 07-07-2009
Member
 
Join Date: Apr 2008
Posts: 193
Re: How to write pause, sleep, wait function

But the actionscript you showed to me showed that it is not much different from the Javascript delay timer scripts... I haven't thought about that at first so I think it would work.If you want the setInterval to constantly call the function every X seconds then remove the clearInterval(callback_int); line of code from the function. Hope that makes sense. One of the beautiful things about setInterval was (and is) that you can pass arguments to the activated function when the timer expired:

Code:
public function setInterval(closure:Function, delay:Number, ... arguments):uint
Reply With Quote
  #4  
Old 07-07-2009
Member
 
Join Date: Mar 2008
Posts: 192
Re: How to write pause, sleep, wait function

But with the interval function you have to break your code to 2 functions: One of your main function, one on the interval function (to be executed after the flag change). First, the Tween class is not available in AS 2.0, that is something specific to AS 3.0, so please verify the version of actionscript you are using. Your code has a mixture of AS2.0 and AS 3.0 which won't work. Get that straight and things will work out.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to write pause, sleep, wait function"
Thread Thread Starter Forum Replies Last Post
sleep() function in C Gunner 1 Software Development 5 03-03-2010 06:53 PM
How to write code for pause or stop method in HTML TechPredator Software Development 3 10-08-2009 02:39 PM
JavaScript Sleep Function DARIELLE Software Development 3 29-06-2009 09:30 AM
System pause function for linux - Empty Shell - Operating Systems 2 16-05-2009 06:30 PM
Disabling Pause and sleep Key Ramchandra Operating Systems 1 05-01-2009 01:38 PM


All times are GMT +5.5. The time now is 06:21 AM.