Lets refresh how it's done in AS2.
[1] The Video Symbol
We need a Video symbol on stage. Create it using the New Video... command in the context menu of Library panel, make sure you choose 'ActionScript' option.
Drag the new symbol from Library to Stage. Give the symbol an instance name (Following code assumes the instance name is 'video').
[2] Playing the FLV
We just need a few lines to play an external FLV file. Enter the following code to the first frame of your movie, and 'test.flv' in the same folder with your SWF will play...
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
video.attachVideo(ns);
ns.play("test.flv");
[3] Receiving Events
Now that we have the FLV playing, we need code to receive the FLV meta events. You can attach event handlers to the NetStream object instance, like below:
ns.onCaption = function(captions,speaker){
trace('onCaption event at '+ns.time);
}
AS3 code is actually very similar to AS2 code. There are a few changes but most of the time all you need to add is variable definitions and imports when necessary...
[1] The Video Symbol
We, again, need a video symbol on stage. You can create it as in AS2 version, or you can create it the AS3 way in ActionScript, like:
import flash.media.Video;
var video:Video;
video = new Video();
addChild(video);
[2] Playing the FLV
Again the following code is very similar to AS2 code. Main difference is that 'attachVideo' is now called 'attachNetStream' which is more correct:
import flash.net.NetConnection;
import flash.net.NetStream;
var nc:NetConnection;
var ns:NetStream;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
video.attachNetStream(ns);
ns.play("test.flv");
[3] Receiving Events
With AS3, event handlers are not attached to NetStream directly, but you will attach them
to the client property of NetStream. You can create a custom class (see Flash help for sample code) or you can simply create an object as below:
ns.client = new Object();
ns.client.onCaption= function(captions:Object,speaker:Number):void{
trace('onCaption event at '+ns.time);
}
Here is sample code that receives and traces the onMetaData event (in AS3). In Flash, you can create a new AS3 file, copy the code to the fist frame, save the FLA. Make sure you have 'test'flv' in the same folder as you save the FLA.
//import flash.net.NetConnection;
//import flash.net.NetStream;
//import flash.media.Video;
var nc:NetConnection;
var ns:NetStream;
var video:Video;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client = new Object();
video=new Video();
addChild(video);
video.attachNetStream(ns);
ns.play("test.flv");
function traceObject(info:Object):void{
var level;
var s;
function levelStr(level){
s='';
for (var n=0;n<level;n++){s=s+' '};
return(s);
}
function traceThis(x){
level++;
for (var y in x){
var s=typeof(x[y]);
switch (typeof(x[y])){
case 'object':
trace(levelStr(level)+y+'('+s+') : '+x[y]);
traceThis(x[y]);
break;
default:
trace(levelStr(level)+y+'('+s+') = '+x[y]);
break;
}
}
level--;
}
level=0;
traceThis(info);
}
ns.client.onMetaData=function(info:Object):void {
trace('onMetaData event at '+ns.time);
traceObject(info);
}