OK, here's the script I wrote very quickly.
Let's start with the XML - "cuepoints.xml":
Code:
<?xml version="1.0"?>
<cuepoints>
<cuepoint>
<time>1</time>
<name>cue1</name>
</cuepoint>
<cuepoint>
<time>2</time>
<name>cue2</name>
</cuepoint>
<cuepoint>
<time>3.5</time>
<name>cue3</name>
</cuepoint>
</cuepoints>
This XML describes 3 cuepoints. "cue1" is at 1 second, "cue2" is at 2 seconds, and "cue3" is at 3-and-a-half seconds.
You want to add these cuepoints to the FLV on the fly.
The stratergy would be:
[ol]
[li]Create the FLVPlayBack Component and set the content path to the external FLV[/li]
[li]Set up the listener so that when a cuepoint is reached it outputs the cuepoint info (in the real situation you would set up some function to do something when a cuepoint is reached)[/li]
[li]When FLV is ready, load the XML[/li]
[li]On each cuepoint node in the XML add the cuepoint to the FLV[/li]
[li]When XML is done start the FLV[/li]
[/ol]
What you will need is the FLVPlayBack Component in the Library, the external XML and the FLV ("video.flv" in this example). The following script goes to the first frame of the main timeline. Nothing on Stage.
Code:
import mx.video.*;
var flv:FLVPlayback = this.attachMovie("FLVPlayback", "flv", 1);
var lo:Object = new Object();
lo.ready = function(evt:Object):Void {
loadCuePoints();
};
flv.addEventListener("ready",lo);
lo.cuePoint = function(evt:Object):Void {
for (var s in evt.info) {
trace(s+": "+evt.info[s]);
}
trace("***");
};
flv.addEventListener("cuePoint",lo);
with (flv) {
autoPlay = false;
contentPath = "video.flv";
}
function loadCuePoints():Void {
var xmlObj:XML = new XML();
xmlObj.ignoreWhite = true;
xmlObj.onLoad = function(OK:Boolean):Void {
if (OK) {
addCuePoints(this);
} else {
trace("XML load failed");
}
};
xmlObj.load("cuepoints.xml");
}
function addCuePoints(xmlObj):Void {
var cuepoints:XMLNode = xmlObj.firstChild;
for (var i = 0, n = cuepoints.childNodes.length; i<n; i++) {
var cuepoint:XMLNode = cuepoints.childNodes[i];
var cuepointObj:Object = new Object();
for (var j = 0; j<2; j++) {
var cuepointElement:XMLNode = cuepoint.childNodes[j];
switch (cuepointElement.nodeName) {
case "name" :
cuepointObj["name"] = cuepointElement.firstChild.nodeValue;
break;
case "time" :
cuepointObj["time"] = parseFloat(cuepointElement.firstChild.nodeValue);
break;
}
}
flv.addASCuePoint(cuepointObj);
}
startFLV();
}
function startFLV():Void {
flv.play();
}
It will output at the each cuepoint on specified time:
Code:
name: cue1
time: 1
type: actionscript
***
name: cue2
time: 2
type: actionscript
***
name: cue3
time: 3.5
type: actionscript
***
Kenneth Kawamoto