Dynamically adding cue points to an FLV using the FLVPlayback control in ActionScript 3.0

by Peter deHaan on March 13, 2008

in FLVPlayback

The following example shows how you can dynamically create an instance of the FLVPlayback control, dynamically add an ActionScript cue point, listen for the ready and cuePoint events, and add the FLVPlayback control to the display list, all in delicious ActionScript 3.0.

Full code after the jump.

/**
 * Requires:
 *   - FLVPlayback control in Library.
 */
import fl.video.*;
 
var flvPlayback:FLVPlayback = new FLVPlayback();
flvPlayback.x = 10;
flvPlayback.y = 10;
flvPlayback.addEventListener(VideoEvent.READY, flvPlayback_ready);
flvPlayback.addEventListener(MetadataEvent.CUE_POINT, flvPlayback_cuePoint);
flvPlayback.source = "http://www.helpexamples.com/flash/video/clouds.flv";
addChild(flvPlayback);
 
function flvPlayback_ready(evt:VideoEvent):void {
    flvPlayback.addASCuePoint(1, "cuePoint1");
}
 
function flvPlayback_cuePoint(evt:MetadataEvent):void {
    trace("CUE POINT!!!");
    trace("\t", "name:", evt.info.name); // name: cuePoint1
    trace("\t", "time:", evt.info.time); // time: 1
    trace("\t", "type:", evt.info.type); // type: actionscript
}

{ 5 comments… read them below or add one }

1 Richard 01.22.09 at 2:02 am

Hi Peter,

I’m trying to implement a movie with cue points using your flvPlayback code above. The code works great, but how do i action events to happen when the cuepoints happen?

I want to play a caption mc when cuePoint1 happens over the top of the playing movie

regards

Richard

2 Peter deHaan 01.22.09 at 8:14 am

Richard,

I’d probably add the code to the flvPlayback_cuePoint() method and put a switch statement for the cue point name (using evt.info.name). Once you know which cue point you’re looking at you can add whatever code you need to attach and position the movie clip asset from the library, or whatever.

Something like this:

function flvPlayback_cuePoint(evt:MetadataEvent):void {
    switch (evt.info.name) {
        case "cuePoint1":
            // logic to display caption movie clip here...
            break;
        case "cuePoint2":
            // logic to remove existing caption movie clip and display new 
            // clip here...
            break;
        default:
            // we don't know which cue point we're looking at, so remove 
            // all caption movie clips...
            break;
}

Peter

3 Erik 04.03.09 at 6:42 am

ik gebruik onderstaande code om cuepoint toetevoegen aan mijn flv en hiermee actionscript te triggeren.(as 2) wellicht kunnen jullie hier wat mee:

flvmovie.addASCuePoint(2, "cue1");
flvmovie.addASCuePoint(4, "cue2");
flvmovie.addASCuePoint(6, "cue3");
 
var listenerObject:Object = new Object();
listenerObject.cuePoint = function(eventObject:Object):Void  {
    if (eventObject.info.name == "cue1") {
        _level0.vierkant._x= 50;// zet hier neer wat je wilt
    }
    if (eventObject.info.name == "cue2") {
        _level0.vierkant._x= 100;// zet hier neer wat je wilt
    }
    trace("Elapsed time in seconds: "+flvmovie.playheadTime);
    trace("Cue point name is: "+eventObject.info.name);
};
 
 
flvmovie.addEventListener("cuePoint", listenerObject);
4 SLiDEnl 04.21.09 at 2:05 am

I’ve been trying to add a prevScene(); event when my script has found it’s AS generated cue point. This doesn’t seem to work however, I’ve been playing around with variables as well but to no avail.

I understand this stems from the fact that code embedded in a MC won’t respond to goto or scene commands?

Oh, all this in AS3.0.

5 SLiDEnl 05.06.09 at 5:07 am

Never mind, I’m an idiot.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: