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?  
Adobe Flash

Avatar of undefined
Last Comment
flyingcarstudios

8/22/2022 - Mon
blue-genie

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
flyingcarstudios

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.
blue-genie

ahh sorry, shoud read carefully, thanks for putting me right.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
Cutthroat_Trout

Can you please post the solution for streaming video?
flyingcarstudios

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
flyingcarstudios

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question