4 Replies Latest reply on Feb 15, 2010 5:19 PM by Ned Murphy

    Need Help With Processing A Delay

    disposable_zero

      OK I'm working on a Flash intro for a site. After the Flash movie plays I want it to wait three seconds and then send them to the index page. Currently I'm using the action script:

       

      stop();
      getURL("http://mywebsite.com/index.php", "_top", "GET");

       

      I've got that keyed to the last frame. The issue is at the end of the Flash movie it displays the company logo image. Well with that script added to the last frame it just quickly blips up the logo then takes you to the main page so fast you don't even get to really see the logo. I want the viewer to have a couple seconds to take it in, but then move them along to the main site without them having to look for a button to press.I was emailing with a friend and he suggested.

       

      // ActionScript 2

      // Call the setTimeout function.
      // The first argument is the target you want to call the function on (this).
      // The second argument is the name of the function to call.  It could be our own custom written function but in this case we'll use the getURL one.
      // The third argument is the delay in milliseconds, so 1000 milliseconds is 1 second.
      // The fourth and fifth arguments are the arguments to pass into the called function.
      _global["setTimeout"](this, "getURL", 1000, "http://mywebsite.com/index.php", "GET");

      // We call stop because we want to wait on this keyframe until setTimeout fires.
      this.stop();

       

      Now I think he's right, he usually is, but I've only been using flash for about two weeks now so even with that reply I'm not getting it.I don't even see "setTimeout" anywhere in my actions list. I tried just cutting and pasting:

       

      _global["setTimeout"](this, "getURL", 1000, "http://mywebsite.com/index.php", "GET");

       

      All it says is "evaluate: Evaluates an arbitrary expression" in the Script Assist window. I need someone to either walk me through it step by step, or give me exactly what the code should be so I can understand it. It's very humbling when you're the n00b all the sudden, I promise to pay it forward if someone can help me out

        • 1. Re: Need Help With Processing A Delay
          Ned Murphy Adobe Community Professional & MVP

          I have to say I've never seen the setTimeout specified in that way, but there's likely lots I aint seen.  In your last frame you should be able to use...

           

          stop();

           

          setTimeout(waitABit, 3000); // in 3 seconds call the waitABit function

           

          function waitABit(){
               getURL("http://mywebsite.com/index.php", "_top"); // not sure if you want "_top"

          }

          • 2. Re: Need Help With Processing A Delay
            disposable_zero Level 1

            Thanks that got me to the right place, I had to switch it around a little but used:

             

             

            setTimeout(waitABit, 3000);
            //in 3 seconds call the waitABit function
            function waitABit() {
                stop();
                getURL("http://www.mysite.com/index.php", "_self");
            }

             

            And got it to work, thanks so much!

            • 3. Re: Need Help With Processing A Delay
              Rothrock Level 5

              I can't remember exactly, but I think that setTimeout was actually included in the player as early as player 7 (maybe 8?), but the compiler wouldn't recognize it and would generate and error when publishing. So the _global["setTimeout"] was a trick to get around the compiler. But that hasn't been needed since Flash 9.

               

              And the second part is a very clever way of using it the second form of setTimeout. In that case you specify and object, in that case "this" which refers to the main timeline. Then you specify the name of the method to use, normally that would be a user defined function, but the "getURL" method is a perfectly well defined function of the specified object, namely "this." And then the last arguement is the value to pass to the specified function, which is a string in the form of a url. Very clever indeed.

               

              BTW you don't need the stop(); inside of the function you call. As Ned showed in his example the stop rightly belongs outside of the function if you want the main timeline to stop and wait three seconds. Otherwise you will wait three seconds and then stop(), but since you are calling a getURL, that stop() will never do anything at all....