The Video Component in as3

The Video Component in as3

A previous post, Making the Move to ActionScript 3, discussed the obstacles of making the change from ActionScript 2 to ActionScript 3. This was such a big change due to the move towards object-oriented programming, which does not require small functional changes, but significant structural changes.

But as with most things, it does get easier the more it is used. In most cases it is a win for having code more organised, but in some cases it seems like a lot more work to do what was previously a simple task.

We’ve been working on a site that incorporates several videos, so it is only appropriate that we share the love on how it went with ActionScript 3.

First import the video component

import fl.video.*;

Define the string to read in the video source (this is being defined in the HTML). It will need to have a default file.

var strSource:String = “Bequest and Donations 2_1.flv”;

if(root.loaderInfo.parameters.video1 != null){

strSource = root.loaderInfo.parameters.video1;

}

Define the video and add it

var myVideo:Video = new Video();

addChild(myVideo);

Define the network connection

var nc:NetConnection = new NetConnection();

nc.connect(null);

Define the netstream

var ns:NetStream = new NetStream(nc);

myVideo.attachNetStream(ns);

Define the width and the height for the video

myVideo.width = 640;

myVideo.height = 360

Play the video!

ns.play(strSource);

Now you have a working video with as3!

About Erin

I like to think about exercising in the hope of achieving the same results as actually exercising

Speak Your Mind

*