Skip to main content
December 14, 2010
Question

NetStream() and CuePoints

  • December 14, 2010
  • 1 reply
  • 699 views

Hi,

Iv recently started using flash again after a few years of neglect (I finally have a job that pushes me!) and I'm finding I'm a little rusty...

Very simply Im having some issues creating reactions to CuePoints when using NetStream();

I can get what I want to work when the video is embedded directly onto the stage by using the following code:

vid.addEventListener(MetadataEvent.CUE_POINT, cp_listener);


function cp_listener(eventObject:MetadataEvent):void {

     obj = eventObject.info.parameters;

     for (key in obj) {

          if (key == "CuePointName1") {

               // then do whatever I want to happen when CuePointName1 is reached in the video

          }

}

But when I translate it over to work with NetStream it doesn't work:

// START NETSTREAM


var nc:NetConnection = new NetConnection();

nc.connect(null);

var ns:NetStream = new NetStream(nc);

ns.client = this;

ns.play("video.flv");

var vid:Video = new Video();

vid.attachNetStream(ns);

addChild(vid);



// CUEPOINT LISTENERS

function onCuePoint(infoObject:Object):void {

     for (key in infoObject) {

          trace(infoObject["name"]);

          if (infoObject["name"] == "CuePointName1") {

               // then do whatever I want to happen when CuePointName1 is reached in the video

          }

     }

}

The trace statement is returning the name of the CuePoint correctly, but 4 times like this:

CuePointName1

CuePointName1

CuePointName1

CuePointName1

Witch I assume is why the if statement isn't picking it up.

Any help will be most appreciated!

Thanks

Ross

This topic has been closed for replies.

1 reply

Inspiring
December 15, 2010

Because info object has four parameters (name, parameters, time, and type) and you loop through them. Also, why do you use "name" as a string when you can just do infoObject.name?

In any case do that and you will see the key name and value:

function onCuePoint(infoObject:Object):void {
     for (var key:String in infoObject){
          trace(key, infoObject[key]);
     }
}

December 15, 2010

Hi Andrei1,

Thanks for your help and for improving my script, but i'm essentially no further forwards...

How do I compare only the name value and ignore the other 3? Because if I understand you correctly (and testing shows):

if (infoObject.name == "CuePoint1") {

     // what to do when CuePoint1 is reached

}

Is the same as:

if (infoObject["name"] == "CuePoint1") {

     // what to do when CuePoint1 is reached

}

Just slightly better coding.

Thanks for your help so far.

December 15, 2010

Excuse my stupidity, I really am rusty!

The reason I was having problems was that I had simply attached the video directly to the stage (ontop of all the other objects) so I simply couldn't see what was happening!

By creating n empty movie clip on the very back layer and loading the video into it like this:

vidholder.addChild(vid);

it sorted it.

Sorry for wasting your time!