Link to home
Start Free TrialLog in
Avatar of Cutthroat_Trout
Cutthroat_Trout

asked on

Event Listener for end of a FLV

I am trying to use Actionscript  3.0 to listen for the end of a video, and then go to a label created on the timeline. Can anyone provide an example of this?  
Avatar of blue-genie
blue-genie
Flag of South Africa image

how are you embedding the flv? are you using the flvPlayback component?

i found this online at kirupa.

import mx.video.*;
var listenerObject:Object = new Object();
listenerObject.complete = function():Void {
_root.gotoAndPlay("yourframelabel");
trace(this);
};
my_FLVPlybk.addEventListener("complete", listenerObject);

try it and see.

blu
blue-genie, that code is for the AS2 component.

If you are using the AS3 FLVPlayback component the event syntax is slightly different:
(assuming your playback component has the variable name flvPlaybackComponent)

import fl.video.VideoEvent;

flvPlaybackComponent.addEventListener(VideoEvent.COMPLETE, listenerFunction);

function listenerFunction(e:VideoEvent):void
{
//what ever code you wanted to do onComplete
trace(e.target) // FLVPlayback object
}

If you are using the AS3 flash.media.Video class and calling the Video.attachNetStream() method, (which I recommend, its more efficient) Let me know and I'll post the solution for that.
ahh sorry, shoud read carefully, thanks for putting me right.
Avatar of Cutthroat_Trout
Cutthroat_Trout

ASKER

Can you please post the solution for streaming video?
sure, (sorry for the delay over the long weekend)

Assumptions:
You have a NetStream named stream and a NetConnection named connection

Other notes:
Notice the MovieClip(stage).gotoAndPlay / gotoAndStop, assuming you want to access a frame label on your main timeline this may or may not be necessary depending on where you are putting the code. (i.e in a document class vs. inline on a layer).  There is no _root in AS3 and the stage is a DisplayObjectContainer, thus does not have the property gotoAndPlay unless you cast it as a MovieClip

var stream:NetStream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
 
private function netStatusHandler(e:Event):void
{
   switch( event.info.code )
   {
      //you can track other events here as well from the stream such as
      //case "NetStream.Play.StreamNotFound"
      //or case "NetStream.Play.Switch"
 
      //the property fired on complete is NetStream.Play.Complete so:
      case "NetStream.Play.Complete:
         //on complete code here 
         MovieClip(stage).gotoAndStop(frame);
         //or MovieClip(stage).gotoAndPlay(frame)
   }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of flyingcarstudios
flyingcarstudios
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial