10 Replies Latest reply on Jun 4, 2007 6:39 AM by kglad

    A possible 'SetTimeOut' disaster

    Non-nelson Level 1
      Hi everyone,

      I need some help here with the undocumented feature "setTimeout' function in AS2. that I suspect is causing me a critical error in my flash presentation. The error is a reset of my animation when the up & down buttons controlling an animation where setTimeOut is applied are toggled.
      What I like to find out from you guys is whether I can reuse the setTimeout function or is it STRICTLY JUST A ONE TIME function?

      [a sample of the code controlling that animation is attached]
      Appreciate any help given,
      Thanks
        • 1. Re: A possible 'SetTimeOut' disaster
          kglad Adobe Community Professional & MVP
          setTimeout() is a one time function. setInterval() repeatedly calls the target function.

          • 2. Re: A possible 'SetTimeOut' disaster
            Level 7
            Non-nelson,

            > I need some help here with the undocumented feature
            > "setTimeout' function in AS2. that I suspect is causing
            > me a critical error in my flash presentation.

            It's undocumented in Flash 8, but the lack of documentation was
            unintentional. See notes at the bottom of this LiveDocs page ...

            http://livedocs.macromedia.com/flash/8/main/00001717.html

            > The error is a reset of my animation when the up & down
            > buttons controlling an animation where setTimeOut is
            > applied are toggled.

            Let's see your code; that might bring something to light.

            > What I like to find out from you guys is whether I can
            > reuse the setTimeout function or is it STRICTLY JUST
            > A ONE TIME function?

            It's practically identical to the setTimeout() function in JavaScript.
            Perfectly legal. Call it as often as you like.


            David Stiller
            Adobe Community Expert
            Dev blog, http://www.quip.net/blog/
            "Luck is the residue of good design."


            • 3. A possible 'SetTimeOut' disaster
              Non-nelson Level 1
              quote:

              Originally posted by: kglad
              setTimeout() is a one time function. setInterval() repeatedly calls the target function.




              Hmm...thanks guys but does it mean if I use script to replay the animation on the timeline, it will mess things up? as I still need to perform that pause as it continues to play again.
              • 4. Re: A possible 'SetTimeOut' disaster
                kglad Adobe Community Professional & MVP
                it won't mess things up unless the frame that contains that code plays repeatedly. and there's no need to clear your timeout in the function that's called by setTimeout.

                however, using a clear(hold) in a line above your hold=setTimeout() is a good idea and would prevent that possible mess that's caused by repeatedly playing that frame.
                • 5. Re: A possible 'SetTimeOut' disaster
                  Non-nelson Level 1
                  Sounds awesome! Do u mean... and may i know how is it different or how does it help?

                  • 6. Re: A possible 'SetTimeOut' disaster
                    kglad Adobe Community Professional & MVP
                    yes, that prevents significant problems especially with setInterval().

                    to see the benefit put your code in a swf with a few frames on the main timeline, place your code in frame 1, remove your stop() and clear(hold) and replace your play() with trace("HI"). then test.

                    if you replace your setTimeout with setInterval, place a clearInterval() in stopawhile() and do the same thing, be sure to shut down the test as soon as things start going crazy or you'll crash flash.
                    • 7. Re: A possible 'SetTimeOut' disaster
                      Non-nelson Level 1
                      Shucks guys...it still works the same with the problem of my animation restarting.
                      I used simple gotoAndPlay(framelabel) to toggle the up & down buttons, don't know whats going wrong...
                      • 8. Re: A possible 'SetTimeOut' disaster
                        kglad Adobe Community Professional & MVP
                        you've not given enough information to help with your issue.

                        i answered your specific question about setTimeout() and gave some extra info about setTimeout() and setInterval().
                        • 9. Re: A possible 'SetTimeOut' disaster
                          Non-nelson Level 1
                          Ok, i will try to troubleshoot it as I am kinda a designer dumped with the duty of a developer now & I can' t upload my project & i think u experts here will surely understand.

                          Can i just ask whether there is any Limitation when it comes to giving a frame label. like I am naming a frame now "navigation section starts here." Will it be a problem when it comes to calling it?

                          Cheers,
                          Really ppreciate all the help provided so far
                          • 10. Re: A possible 'SetTimeOut' disaster
                            kglad Adobe Community Professional & MVP
                            no, you can use any string for a frame label. (though there's probably a limit on the number of characters in that string and that limit is usually something like 2**14 so you need not worry about it.)