7 Replies Latest reply: Dec 21, 2010 9:03 AM by kglad RSS

    Delay action of button to URL.

    ruthgordy Community Member

      Created button that activates short animation AND ALSO connects to URL.

       

      I want viewer to see full animation (26 frames that lasts about 1.5 seconds - 18 frames per second). Instead the button connects almost instantaneously to URL and viewer does not see animation.

       

      Animation automatically plays (full loop - 26 frames) when viewer first opens swf/html. The same animation plays again when viewer clicks button to go to URL.

       

      Is there some code in AS3 that can delay the connection to the URL until the 26th frame of the animation.

      I am beginner/intermediate to Flash and extreme novice to Action Script (get most of my AS coding from searches online). Need to be led by my hand in Action Script.

       

      Here is my action script 3.0 of my animation (and connection to URL)

      teach_btn is the button.

      ------------------------------------------------------------------------------------------ -------

       

      // This is code that loads and plays above animation when you open swf/html file -  code is on frames 1-25

      stop();

       

      gotoAndPlay(1);

       

      function startMovie(event:MouseEvent):void

      {

      this.play();

      }

      teach_btn.addEventListener(MouseEvent.CLICK, startMovie);

       

       

      // This is code that connects user to URL - this code is only on keyframe 26

      stop();

       

      teach_btn.addEventListener(MouseEvent.CLICK,mouseClick);

      function mouseClick(event:MouseEvent):void

      {

       

        var request = new URLRequest("http://www.webpage.com/")

        navigateToURL(request,"_blank");

      }

       

      Thanks

       

        • 1. Re: Delay action of button to URL.
          kglad CommunityMVP

          use:

           


          // This is code that loads and plays above animation when you open swf/html file -  code is on frames 1-25

          stop();

           

          gotoAndPlay(1);

           

          function startMovie(event:MouseEvent):void

          {

          this.play();

          }

          teach_btn.addEventListener(MouseEvent.CLICK, startMovie);

           

           

          // This is code that connects user to URL - this code is only on keyframe 26

          stop();

          mouseClick(null);

          function mouseClick(event:MouseEvent):void

          {

           

            var request = new URLRequest("http://www.webpage.com/")

            navigateToURL(request,"_blank");

          }

           

          Thanks

           

          • 2. Re: Delay action of button to URL.
            ruthgordy Community Member

            Thanks kglad,

             

            The coding does work now when viewer clicks on button, animation runs then goes to URL. That's just what I want.

            Unfortunately when the swf/html OPENS initially and the above animation runs - it also goes to the URL - I don't want viewer to automatically go to URL unless they actively click on the button to activate the animation/go to URL.

             

            Can we send swf/html files to forum participants? This may help you see what I'm trying to accomplish.

            Here's where I'm at with your edits to my coding.

             

            // This is code that loads and plays above animation when you open swf/html file -  code is on frames 1-25

            stop();

             

            gotoAndPlay(1);

             

            function startMovie(event:MouseEvent):void

            {

            this.play();

            }

            teach_btn.addEventListener(MouseEvent.CLICK, startMovie);

             

             

            // This is code that connects user to URL - this code is only on keyframe 26

            stop();

            mouseClick(null);function mouseClick(event:MouseEvent):void

            {

             

              var request = new URLRequest("http://www.webpage.com/")

              navigateToURL(request,"_blank");

            }

             

            • 3. Re: Delay action of button to URL.
              kglad CommunityMVP

              are those two code snippets on different timelines?  i know they're in different frames but the question is, are they on different timelines?

              • 4. Re: Delay action of button to URL.
                ruthgordy Community Member

                I put the two separate snippets on different AS timelines and it is still going automatically to the URL?

                • 5. Re: Delay action of button to URL.
                  kglad CommunityMVP

                  the quickest (but not best) way to help you do this:

                   


                   

                   

                  // This is code that loads and plays above animation when you open swf/html file -  code is on frames 1-25

                  stop();

                   

                  gotoAndPlay(1);

                   

                  function clickF(event:MouseEvent):void

                  {

                  if(MovieClip(root).played){

                    var request = new URLRequest("http://www.webpage.com/")

                    navigateToURL(request,"_blank");

                  } else {

                  MovieClip(root).clicked=true;

                  }

                  }

                  teach_btn.addEventListener(MouseEvent.CLICK, clickF);

                   

                   

                  // This is code that connects user to URL - this code is only on keyframe 26

                  stop();

                  navToF();

                   

                  function navToF():void

                  {

                  if(MovieClip(root).clicked){

                    var request = new URLRequest("http://www.webpage.com/")

                    navigateToURL(request,"_blank");

                  } else {

                  MovieClip(root).played=true;

                  }

                  }

                   

                  • 6. Re: Delay action of button to URL.
                    ruthgordy Community Member

                    thanks kglad,

                     

                    this works great!! You're awesome!

                    • 7. Re: Delay action of button to URL.
                      kglad CommunityMVP

                      you're welcome.