Duphalac 200ml Bottle $108.00

ActionScript 3.0 Flash

Duphalac 200ml bottle $108.00 This article can be considered a sequel to “How to Load External Flash Video (FLV) Files (AS2).”  The code suggested here is nothing more than the ActionScript 3.0 way to accomplish the same goal achieved earlier; namely, duphalac 200ml bottle $108.00 to load an external Flash video (FLV) file at runtime — without using the FLVPlayback component.  To be sure, duphalac 200ml bottle $108.00 there’s nothing wrong with FLVPlayback.  Its skins are customizable (all the more so in Flash CS3, duphalac 200ml bottle $108.00 which is the first version of Flash to support AS3) and it provides plenty of built-in widgets, duphalac 200ml bottle $108.00 such as play/pause, duphalac 200ml bottle $108.00 a volume slider, duphalac 200ml bottle $108.00 mute button, duphalac 200ml bottle $108.00 and the like.  But to get those features, duphalac 200ml bottle $108.00 even if you choose a non-skinned component, duphalac 200ml bottle $108.00 you pay a 49KB price in an ActionScript 3.0 document.  If you go without the component, duphalac 200ml bottle $108.00 it costs you less than 1KB.  That means site visitors can spend their bandwidth on your video content itself, duphalac 200ml bottle $108.00 rather than the video player. 

An answer, duphalac 200ml bottle $108.00 short and sweet

Duphalac 200ml bottle $108.00 As described in the AS2 version of this article, duphalac 200ml bottle $108.00 you’re going to use an instance each of the NetConnection and NetStream classes in addition to a Video object.  In ActionScript 3.0 — this is really neat — you can even create your Video instance via ActionScript.  This is new.  If you like, duphalac 200ml bottle $108.00 though, duphalac 200ml bottle $108.00 you can also still use the Library panel to create a video asset beforehand and drag it to the Stage.  We’ll look at both approaches.  First, duphalac 200ml bottle $108.00 the completely programmatic way:

var vid:Video = new Video(320, duphalac 200ml bottle $108.00 240);
addChild(vid);

var nc:NetConnection = new NetConnection();
nc.connect(null);

var ns:NetStream = new NetStream(nc);
vid.attachNetStream(ns);

var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;

ns.play("externalVideo.flv");

How it works

Duphalac 200ml bottle $108.00 An arbitrarily named variable, duphalac 200ml bottle $108.00 vid, duphalac 200ml bottle $108.00 is declared and set to an instance of the Video class.  To specify the size of this video, duphalac 200ml bottle $108.00 two parameters are passed into the constructor:  a width and height of 320 and 240 pixels.  As it turns out, duphalac 200ml bottle $108.00 this is the default, duphalac 200ml bottle $108.00 so you can leave those numbers out completely and your video will show as 320×240.  If you want something bigger or smaller, duphalac 200ml bottle $108.00 or if your video’s dimensions are some other aspect ratio, duphalac 200ml bottle $108.00 specify the relevant numbers.  The line immediately following, duphalac 200ml bottle $108.00 addChild(vid), duphalac 200ml bottle $108.00 invokes the DisplayObjectContainer.addChild() method on the timeline in which this code appears.

Duphalac 200ml bottle $108.00 Why the timeline?  Because the method stands alone, duphalac 200ml bottle $108.00 doesn’t have an object reference prefixed to it.  (In contrast, duphalac 200ml bottle $108.00 other methods in the above snippet are preceded by object references.)  What’s a DisplayObjectContainer?  Well, duphalac 200ml bottle $108.00 it’s just another class, duphalac 200ml bottle $108.00 like the others we’re using here.  DisplayObjectContainer is inherited by a number of everyday classes, duphalac 200ml bottle $108.00 such as MovieClip.

Duphalac 200ml bottle $108.00 The timeline in which this code appears (i.e., duphalac 200ml bottle $108.00 the main timeline) actually is a MovieClip instance, duphalac 200ml bottle $108.00 which means it has access to the addChild() method thanks to the fact that DisplayObjectContainer is a grandparent in its family tree.  By “adding the child” vid, duphalac 200ml bottle $108.00 you’re simply making the Video object visible.  You’re adding it to the display list of the main timeline, duphalac 200ml bottle $108.00 which means it’ll show up visually (even though it exists before then and would even if you failed to add it to the list — in which case it just wouldn’t show).

Duphalac 200ml bottle $108.00 So now we have a Video object to display the video.  Now we need to hook it up.  Another arbitrarily named variable, duphalac 200ml bottle $108.00 nc, duphalac 200ml bottle $108.00 is declared and set to an instance of the NetConnection class, duphalac 200ml bottle $108.00 then the NetConnection.connect() method is called on it and passed a null parameter.  Why null?  All that means is that we’re requesting a progressive download FLV file; that is, duphalac 200ml bottle $108.00 one that isn’t streamed via Flash Media Server.

Duphalac 200ml bottle $108.00 With this connection established, duphalac 200ml bottle $108.00 a third arbitrarily named variable, duphalac 200ml bottle $108.00 ns, duphalac 200ml bottle $108.00 is declared and set to an instance of the NetStream class.  This instance is associated with the net connection, duphalac 200ml bottle $108.00 and the Video.attachNetStream() method is invoked on vid to associate it with the net stream.  This may be a bit tedious, duphalac 200ml bottle $108.00 but it’s not too bad, duphalac 200ml bottle $108.00 and certainly pretty straightforward.

Duphalac 200ml bottle $108.00 The next three lines merit a bit of explanation.  Here they are again:

var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;

Duphalac 200ml bottle $108.00 This is one of the very few exceptions to how event handing is done in ActionScript 3.0.  Normally, duphalac 200ml bottle $108.00 the task is done as described in this excellent article by Trevor McCauley, duphalac 200ml bottle $108.00 “Introduction to event handling in ActionScript 3.0.”  Here, duphalac 200ml bottle $108.00 the NetStream.onMetaData event is taken care of by a sort of liaison — a generic Object instance — the way it’s often done in AS2.  Why are we even handling onMetaData?  Strictly speaking, duphalac 200ml bottle $108.00 you don’t have to.  If your FLV doesn’t have metadata embedded in it, duphalac 200ml bottle $108.00 the onMetaData event won’t be dispatched when the video starts playing.  Most FLV encoders, duphalac 200ml bottle $108.00 however (including the native Flash Import Video Wizard), duphalac 200ml bottle $108.00 do embed metadata, duphalac 200ml bottle $108.00 and if you don’t handle the dispatched event, duphalac 200ml bottle $108.00 you’ll see an error message in the Output panel.  The above three lines simply create a dummy stand-in function (that doesn’t do anything) and associate it with an onMetaData property of the Object instance, duphalac 200ml bottle $108.00 arbitrarily named listener.  This object is then connected with the NetStream instance by way of its client property.

Duphalac 200ml bottle $108.00 Finally, duphalac 200ml bottle $108.00 NetStream.play() is invoked on ns and told which FLV to play.

What if I prefer a made-by-hand Video object?

Duphalac 200ml bottle $108.00 If you remember the AS2 version of this article and prefer your older workflow, duphalac 200ml bottle $108.00 drop the first two lines of the above code sample.  Instead, duphalac 200ml bottle $108.00 right-click / Command-click in an open space in your Library panel, duphalac 200ml bottle $108.00 choose New Video… from the context menu, duphalac 200ml bottle $108.00 hit OK to accept the default values — this gives you an ActionScript-controllable Video object with an asset name of Video 1 — then drag that asset to the Stage.  Size it to the dimensions of your video content, duphalac 200ml bottle $108.00 then use the Property inspector to give the object an instance name, duphalac 200ml bottle $108.00 such as videoPlayer.  That instance name will be your key to associating this Video object with the NetStream instance:

var nc:NetConnection = new NetConnection();
nc.connect(null);

var ns:NetStream = new NetStream(nc);
videoPlayer.attachNetStream(ns);

var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;

ns.play("externalVideo.flv");

Duphalac 200ml bottle $108.00 And there you have it.  See how most of that code overlaps?

Average Rating: 4.8 out of 5 based on 241 user reviews.

Leave a Reply