December 19, 2006 Actionscript function on FLV finish without quepoints

At work, a colleague and I were converting a huge Director MX2004 CD lesson to a Flash 8 lesson for web delivery.

Within the Director mx 2004 lesson, there were a TON of Quicktime movies that played within the lesson. We batch changed all these into FLVs when we ran into a problem. We needed the flash time-line to advance when the video was finished.

With Flash MX2004 and Flash 8, you can script play() and stop() functions with just the instance name of the FLV container, however, since an FLV is streaming video, and not a swf file, a method like:


  1. if (myVideo._currentframe == myVideo._totalframes){
  2. //function()
  3. }

will not work.

With Flash 8, cue points were introduced, allowing you to set points within the FLV that you can set listeners for and do functions on the event of those cue points. This is mostly what we needed, except that would require reimporting 80 videos and adding a cue point at the end of each video. We really didn’t have time to do that.

With a little help from the built in flash help, we discovered that if you import the mx.video class, there is already an event built in called “complete”.

So with this, we were able to come up with a generic listener that would run a function upon the completion of a video loaded into the component FLV player.


  1. import mx.video.*;
  2. function the_end(eventObject:Object):Void {
  3. //end of video functions
  4. }
  5. myVideo.addEventListener("complete", the_end);

Enjoy!

AddThis Social Bookmark Button Posted by Greg Ferrell at 04:45 PM. Filed under: Flash-ActionScript • (6) CommentsPermalink