Full Browser Flash Video Background in ActionScript 3.0 - Step 2: Loading And Playing A Video
Posted by : FireCode on Sep 06, 2010
Now let's create our variables:
var _netCon :NetConnection = null;
var _netStr :NetStream = null;
var _video :Video = null;
The NetConnection object is like a pipe between the client and the server.
The NetStream class opens a one-way streaming connection between a Flash and the local file system.
The Video class displays recorded video in an application without embedding the video in your SWF file.
Next, let's create our connection function.
function SetupNetConnection()
{
_netCon = new NetConnection();
_netCon.addEventListener(NetStatusEvent.NET_STATUS, NetStatus, false, 0, true);
_netCon.connect(null);
}
We've created a new connection and added an event listener to monitorize the status of the connection. The null argument on the connect method specifies that we are not connecting to a Flash Media Server.
Now we are going to create the stream that can be used for playing video files through the NetConnection object and monitorize its status through the same event listener.
Also, we are going to create our video that will dislay the stream weâ??ve just created.
function SetupNetStream()
{
var $customClient:Object = new Object();
$customClient.onMetaData = onMetaData;
_netStr = new NetStream(_netCon);
_netStr.client = $customClient;
_netStr.addEventListener(NetStatusEvent.NET_STATUS, NetStatus, false, 0, true);
_video = new Video();
_video.attachNetStream(_netStr);
_video.smoothing = false;
addChild(_video);
_netStr.play("video.flv");
}
The onMetaData function will be called as soon as the NetStream object gets the meta data from the flv file. The data is stored in an object.
function onMetaData($info:Object):void {}
The NetStatus function will monitorize our connection and stream. Once the net connection has been establised it's going to create the net stream. When the flv reaches the end, it will fire an event that we can use to play our movie again, in a loop.
function NetStatus($e:NetStatusEvent)
{
switch ($e.info.code)
{
case "NetConnection.Connect.Success":
SetupNetStream();
break;
case "NetStream.Play.Stop":
_netStr.seek(0);
}
}

1 comment
Add comment
Agos85
Hi, is it possible to add content over the video? because I´ve tried with the z-index property but it´s not working..
#  /  PM  /  posted on Nov 17, 2011