6 Replies Latest reply on Jan 4, 2010 11:25 AM by Bjlawrence11

    Timed Event Navigate to URL at end of FLV

    Snarky7D

      Greetings,

       

      Long time flash "dabbler" who has avoided using scripts as long as possible. But now finds himself having to use CS4 and AS3.

       

      However, I have a situation that would have been easy to handle in older version of Flash or Swish. Previousely if I had an imported FLV or SWF that was 7 seconds long at 20 FPS I would have gone to frame 140 and set a getURL action to redirect to a webpage at the end of the movie.

       

      But with CS4 & AS3, this is not so simple anymore.

       

      I have a button that when pressed successfully invokes the navigateToURL parameter when pressed. But at the same time I am playing an FLV in the background that is 7 seconds long.

       

      What I need to do is have a timed event that at the end of 7 seconds (7000 milliseconds) then invokes the navigateToURL function.

       

      Anyone have any ideas on how to accomplish this? I have looked all over and have not seen anything that accomplishes this.

       

      Here is what i have as my script on frame 1 in my actions layer including some timed event scripting I found via Google search ...

       

      stop();

       

      // We need to import the utils package
      import flash.utils.*;

       

      // Create a new Timer object with a delay of 7000 ms
      var introTimer:Timer = new Timer(7000);
      introTimer.addEventListener(”timer”, timedFunction);

       

      // Start the timer
      introTimer.start();

       

      // Function will be called every 7000 milliseconds
      function timedFunction(eventArgs:TimerEvent)
      {
      trace(”Timer fired ” + introTimer.currentCount + ” times.”);
      var request:URLRequest = new URLRequest("http://www.welcomesmile.ca/test.php");
      navigateToURL(request, "_self");
      }

       

      I of course get a pile of errors with this script. I would appreciate if anyone could help me or suggest maybe a better way to accomplish my goal?

       

      Best regards & thanks,

       

      Martin

        • 1. Re: Timed Event Navigate to URL at end of FLV
          Dustin Sparks Level 1

          Are you getting Syntax errors by chance?

           

          I copied your code and am getting a syntax error because it is using the wrong type of quotes. This could be due to formatting issues form the place you copied it from in your google search.

           

          Try copying from here and use the following script. It's the same thing, but replaced those crazy quotes and I added a stop to the timer so the link is only called after the first 7 seconds and not repeatedly every 7 seconds.

           

          stop();

           

          // We need to import the utils package
          import flash.utils.*;

           

          // Create a new Timer object with a delay of 7000 ms
          var introTimer:Timer = new Timer(7000);
          introTimer.addEventListener("timer", timedFunction);

           

          // Start the timer
          introTimer.start();

           

          // Function will be called every 7000 milliseconds
          function timedFunction(eventArgs:TimerEvent)
          {
               trace("Timer fired " + introTimer.currentCount + " times.");
               var request:URLRequest = new URLRequest("http://www.welcomesmile.ca/test.php");
               navigateToURL(request, "_self");

               // Stop the timer from calling repeatedly.
               introTimer.stop();
          }

          • 2. Re: Timed Event Navigate to URL at end of FLV
            RossRitchey Level 4

            Rather than use the Timer, the Video class fires a Complete event when it reaches the end.  This is where you will want the navigateToUrl to go:

             

            Note: "myVideoPlayer" is the instance name of the FLVPlayback component on the stage

            import fl.video.VideoEvent;
            
            function timedFunction(e:VideoEvent):void
            {
                 var request:URLRequest = new URLRequest("http://www.welcomesmile.ca/test.php");
                 navigateToURL(request, "_self");
            }
            
            myVideoPlayer.addEventListener(VideoEvent.COMPLETE,timedFunction);
            
            

            1 person found this helpful
            • 3. Re: Timed Event Navigate to URL at end of FLV
              Snarky7D Level 1

              Hi Dustin,

               

              Thanks for your awesomly quick answer! That worked just perfectly and your answer was exactly what I had asked about.

               

              I tested it and tried it out and it worked great. However, I did notice that i had to tweak the milliseconds somewhat as at 7000 it was cutting the end of the movie off.

               

              But I am not complaining, this will be a usefull technique for timing events in future.

               

              However, I see the benefits of Ross's answer as that is timing independent...

               

              Thanks again!

               

              Martin

              • 4. Re: Timed Event Navigate to URL at end of FLV
                Snarky7D Level 1

                Hi Ross,

                 

                I really appreciate your quickness in replying to my question and your information about the Video class.

                 

                I tried your method as well and I defintely think I like it better than the timed event method.

                 

                Your help is very much appreciated.

                 

                Best regards,

                 

                Martin

                • 5. Re: Timed Event Navigate to URL at end of FLV
                  Dustin Sparks Level 1

                  Glad to have helped. Doing this kind of thing is actually easier in AS3 than older versions. Like Ross mentioned, it is best to use the FLV events if you're dealing with an FLV. However, that really doesn't work if you're importing it and embedding to the timeline or doing your own animation in the timeline.

                   

                  Also, I probably should have mentioned this, but you can still do it the old way. If you find the need to bump up the number of frames you're using (usually a tweened animation or embedded video), then you can add a keyframe at the end with stop() on it. When you do this you can still use navigateToURL() just like you would use getURL() on the last frame in older versions. This, as well as the timer, wont work for FLV's in either case though, since they're usually progressively downloaded or streamed on a server. Since everyone plays back the video at different rates depending on their connection, setting a timer of 7 seconds will just give you problems. In almost all cases aside from embedded video or timeline animation, it's absolutely best to go with the COMPLETE event.

                  • 6. Re: Timed Event Navigate to URL at end of FLV
                    Bjlawrence11
                    I'm trying to attempt a similar result as Snarky7D, but I'm even less familiar with Action script than he is... any help is appreciated.
                    I have a flash movie for my website's splash page, and I want to create a script to automatically go to a second URL from the site as soon as the splash video has completed. I just can't figure out whether this is best introduced as an action script event within Flash, or if there is a simpler way within Dreamweaver?

                    I gather there is a need to create a video cue point or "VideoEvent.COMPLETE", which I have done within flash, timing it at 9.90 of my 10 second video. I don't know how to reference the end of the video's playback itself. And currently I have served the video and a separate action script file to my server with this coding:

                     

                    import fl.video.VideoEvent;

                     

                    function timedFunction(e:VideoEvent):void

                     

                    {

                     

                         var request:URLRequest = new URLRequest("http://www.benlawrence.ca/Demo2010.html");

                     

                         navigateToURL(request, "_self");

                     

                    }

                     

                    myVideoPlayer.addEventListener(VideoEvent.COMPLETE,timedFunction);

                     

                     

                     

                    Within the html page in dreamweaver I have this FLV object coding (with the script reference at the end):

                     

                     

                    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="720" height="480">
                      <param name="movie" value="Assets/film/Flash/MotionIntro_03.flv" />
                      <param name="quality" value="high" />
                      <param name="SCALE" value="exactfit" />
                      <embed src="Assets/film/Flash/MotionIntro_03.flv" width="720" height="480" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" scale="exactfit"></embed>
                    </object>
                    <script type="application/javascript" src="Scripts/MotionIntro_03.fla.as"></script>

                     

                     

                    Am I getting closer? In the meantime I'm going to read up more on Javascript, because that may be easier to implement...