I was working on a project for class where I have to set cuePoints on an FLVPlayback timeline. The way my project is setup, I am grabbing several stop times from an XML and then I’m using the number that I get out of the XML as cuePoints. Here is my XML:
cuePoints
cuePoint stopTime=”15” id=”firstStop”
cuePoint stopTime=”30” id=”secondStop”
cuePoint stopTime=”45” id=”thirdStop”
cuePoints
There is a lot more cuePoints but I didn’t want to bore you with the extras. Then in my .as file I grabbed my XML and then called the onComplete function. I’m assuming here that you know how to bring in the xml using a URLLoader with an eventListener on it. Now make sure you create your FLVPlayer and put an eventListener for READY and CUEPOINT. These are the events that will set your cuePoints and listen for them. Here is an example of the two functions.
player.addEventListener(VideoEvent.READY, setCuePoints);
player.addEventListener(MetadataEvent.CUE_POINT, onCuePoint);
The top one sets the cuePoints and the second listens too them. This is where I was having some trouble but finally with some help from my mentor I figured it out.
In the setCuePoints function I was setting all the cuePoints like this.
private function setCuePoints(e:VideoEvent):void
{
var list:XMLList = xml.cuePoints.cuePoint.@stopTime;
for each(var x:XML in list)
{
flvPlayer.addASCuePoint(x, 'stop');
}
}
This looked right and if you traced x it would list all the cuePoint times but it would only stop at the last one. The method addASCuePoint ask for an Object for the stop time. I was passing in the number that I was getting from the xml, or was I? I tried everything even the .toString(), and that would not work. I could hard code the times in and that would work fine but for some reason it didn’t like my number (x).
So here is the fix. Replace the line.
flvPlayer.addASCuePoint(x, 'stop');
with
flvPlayer.addASCuePoint(Number(x), 'stop');
We need to cast the xml number we are getting as an actual number. This will work every time and you can set as many cuePoints as you want on the time line.
Hope this helps.
If you didn’t want to use the timeline of the FLVPlayback comp, I wrote a quick post about adding cue points in code: http://ahmednuaman.com/blog/2009/06/18/actionscript-3-cue-points/
Ahmed,
Great post. The options are endless.
Thanks
Thanks, this was driving me nuts. You and your mentor ROCK!!