The following example shows how you can load external FLV files using ActionScript 2.0 and ActionScript 3.0.
Full code after the jump.
The following example shows how you can load an .FLV file in ActionScript 2.0 using the NetConnection and NetStream classes and attach the video stream to the Video object on the Stage.
// ActionScript 2.0 /** * Requires: * - Video object on the Stage with an instance name of "video". */ var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); ns.onMetaData = function (item:Object):Void { trace("metaData"); // Resize video instance. video._width = item.width; video._height = item.height; // Center video instance on Stage. video._x = (Stage.width - video._width) / 2; video._y = (Stage.height - video._height) / 2; }; ns.onCuePoint = function (item:Object):Void { trace("cuePoint"); trace(item.name + "\t" + item.time); }; ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv"); video.attachVideo(ns);
In ActionScript 3.0, the code is a little different. Instead of creating a new Video object in the Flash document’s Library panel, you can create a new Video instance using the Video class’s constructor. Also, note that instead of going <NetStream>.onMetaData = function(...);, you attach the onMetaData and onCuePoint event handlers to a client object.
// ActionScript 3.0 var video:Video = new Video(); addChild(video); var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); ns.client = {}; ns.client.onMetaData = ns_onMetaData; ns.client.onCuePoint = ns_onCuePoint; ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv"); video.attachNetStream(ns); function ns_onMetaData(item:Object):void { trace("metaData"); // Resize video instance. video.width = item.width; video.height = item.height; // Center video instance on Stage. video.x = (stage.stageWidth - video.width) / 2; video.y = (stage.stageHeight - video.height) / 2; } function ns_onCuePoint(item:Object):void { trace("cuePoint"); trace(item.name + "\t" + item.time); }
{ 8 comments… read them below or add one }
perfect. thanks! just what i was looking 4.
gr8 ! thanks
Thank you! it seems that the live docs aren’t too clear as for the onMetaData event regards
Hi,
This way to trace the cuePoints works perfect. Now I am trying to play another video after the cuePoint on the first video is reached.
Any ideas?
can u tell me how will give a specified width and height?
thanks in advance
I’ve been looking for this the entire morning. Thnx so much!
I also found this for anti-aliasing the video: http://julian.empiregn.com/2006/1/30/Flash-Video-FLV-AntiAliasing
is there a way of inserting the video in a specific layer below the graphics i have?
thanks!