A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: setting time delay in the script

  1. #1
    Junior Member
    Join Date
    Apr 2006
    Posts
    7

    setting time delay in the script

    I wounder if it is possible to set time delay using script. I wat to run a sequencef functionswith a certain delay. Something similar to setTimeout or TimeInterval in Javascript.

    I know that I can set a time delay using events so it should be possible to run that directly from the script

    Thank you for help

    Malgosia

  2. #2
    Senior Member zoranvedek's Avatar
    Join Date
    Aug 2001
    Location
    Wagoner OK
    Posts
    893
    Never done it, but in theory it should work. Try getting the time(actual time on the users computer) and setting that as a variable, then use that variable to set/get your time in your movie.......

    -J

  3. #3
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590
    Yep, this can be done in scripting, Zoranvedek is on the right lines.

    There are two easy ways I can think of. To delay by a number of frames:

    When you want the delay to start, set a variable to 0. Have a script running once every frame, to increment the variable by 1. Have another part of the script running so that when the variable exceeds 20, to then go on and do something else.
    If you're using 20 frames per second, this would pause the movie for one second.

    ie.
    In the starting script:
    status="BeforeWait"

    In a script running once per frame in the movie:
    if (status=="BeforeWait")
    {
    // All the other stuff you want to do before the wait
    }

    if (status=="StartWait")
    {
    counter=0
    status="NowWaiting"
    }

    if (status=="NowWaiting")
    {
    counter+=1
    if (counter>20)
    {
    status="FinishedWaiting"
    }
    }

    if (status=="FinishedWaiting")
    {
    // All the stuff you want to do after the wait is completed
    }

    On a button when you want the delay to start, add an 'On Button Up' script of:
    status="StartWait"

    For longer delays, change the line : if (counter>20) to be a bigger number. If your movie doesn't run at 20 frames per second, change this accordingly.


    If you need it to be a strict time delay, then the same principle can be used with the time variables, or probably the better one would be the timer() function, which just returns a number rather than having to mess about with hours, minutes, seconds, days, etc.

    ie.
    In the starting script:
    status="BeforeWait"

    In a script running once per frame in the movie:
    if (status=="BeforeWait")
    {
    // All the other stuff you want to do before the wait
    }

    if (status=="StartWait")
    {
    counter=getTimer()
    status="NowWaiting"
    }

    if (status=="NowWaiting")
    {
    if (getTimer()>(counter+1000))
    {
    status="FinishedWaiting"
    }
    }

    if (status=="FinishedWaiting")
    {
    // All the stuff you want to do after the wait is completed
    }

    On a button when you want the delay to start, add an 'On Button Up' script of:
    status="StartWait"

    This would wait 1000 milliseconds. The method you use probably depends on if you want to wait for a number of frames, or for a specific amount of time.

    Morgan.
    Please note that my domain has changed to http://www.morganmultinational.com

  4. #4
    Junior Member
    Join Date
    Nov 2006
    Posts
    17
    edit
    Last edited by steviehype; 11-20-2006 at 10:26 AM. Reason: wrong forum...!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center