Results 1 to 4 of 4

Thread: How to write pause, sleep, wait function

  1. #1
    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?

  2. #2
    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);

  3. #3
    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

  4. #4
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,948,691.41943 seconds with 17 queries