Artane 2mg Pills $334.00

ActionScript 2.0 ActionScript 3.0

Artane 2mg pills $334.00 Half a year ago, artane 2mg pills $334.00 I wrote a brief article on “How to Play Sound Files Sequentially” (AS2).  Recently, artane 2mg pills $334.00 a reader was asking how to apply the same principle to video.  In his case, artane 2mg pills $334.00 Paul had to play a commercial first, artane 2mg pills $334.00 then follow it with a longer content video — and the user controls (buttons, artane 2mg pills $334.00 scrubber, artane 2mg pills $334.00 etc.) needed to be disabled wile the commercial was playing.  As it turns out, artane 2mg pills $334.00 Paul worked out a solution of his own, artane 2mg pills $334.00 partly based on some of the other articles here, artane 2mg pills $334.00 but I thought it would be fun to do a quick version too.  That way, artane 2mg pills $334.00 he can compare notes and anyone else can look on. 

An answer, artane 2mg pills $334.00 short and sweet

Artane 2mg pills $334.00 To my thinking, artane 2mg pills $334.00 the key is to reuse as much code as possible.  Even though we’re playing two (or any number) of videos, artane 2mg pills $334.00 we only need a single instance of Video, artane 2mg pills $334.00 NetConnection, artane 2mg pills $334.00 and NetStream apiece.  That’s if we’re going with a non-component approach, artane 2mg pills $334.00 like the one described in “How to Load External Video (FLV)” (AS2).  We’ll start with that one, artane 2mg pills $334.00 to get the basic idea across, artane 2mg pills $334.00 then I’ll also show how to accomplish the same thing with the FLVPlayback component.  The operative mechanism, artane 2mg pills $334.00 in all cases, artane 2mg pills $334.00 is to detect when the current video has ended, artane 2mg pills $334.00 then automatically start playing the next one, artane 2mg pills $334.00 until the list of videos is complete.

Artane 2mg pills $334.00 Let’s start with ActionScript 2.0.  Here’s the chunk of code:

ActionScript 2.0

var videos:Array = new Array("a.flv", artane 2mg pills $334.00 "b.flv", artane 2mg pills $334.00 "c.flv");
var currentVideo:Number = 0;
var duration:Number = 0;
var ready:Boolean = true;

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(videos[currentVideo]);

ns.onMetaData = function(evt:Object):Void {
  duration = evt.duration;
  ready = true;
};
ns.onStatus = function(evt:Object):Void {
  if (ready && this.time > 0 && this.time >= (duration - 0.5)) {
    ready = false;
    currentVideo++;
    if (currentVideo < videos.length) {
      ns.play(videos[currentVideo]);
    } else {
      delete this.onStatus;
    }
  }
}

How it works

Artane 2mg pills $334.00 The first line declares an arbitrarily named variable, artane 2mg pills $334.00 videos, artane 2mg pills $334.00 and sets it to an instance of the Array class.  This Array instance is populated with three strings, artane 2mg pills $334.00 “a.flv”, artane 2mg pills $334.00 “b.flv”, artane 2mg pills $334.00 and “c.flv”.  Arrays are just lists, artane 2mg pills $334.00 and this is a list of three FLV files.  The second line declares another variable, artane 2mg pills $334.00 currentVideo, artane 2mg pills $334.00 which is a number, artane 2mg pills $334.00 and sets its value to zero.  Arrays start at zero, artane 2mg pills $334.00 so in a moment, artane 2mg pills $334.00 you’ll see this variable used to pull the first video from the list.

Artane 2mg pills $334.00 The third line declares a variable named duration, artane 2mg pills $334.00 which will be updated later from its initial value of zero in response to the NetStream.onMetaData event, artane 2mg pills $334.00 as described in “How to Determine the Completion of a Flash Video (FLV) File.”  Finally, artane 2mg pills $334.00 a Boolean (true/false) variable named ready is declared and set to true.  This will be used to ensure that the onStatus event handler doesn’t perform its tasks too often in a row.

Artane 2mg pills $334.00 The next few lines — starting with var nc:NetConnection — use the approach suggested in “How to Load External Video (FLV)” to load the first video.  In fact, artane 2mg pills $334.00 the videos array already makes its entrance:

Artane 2mg pills $334.00 ns.play(videos[currentVideo]);

Artane 2mg pills $334.00 Remember, artane 2mg pills $334.00 currentVideo is 0, artane 2mg pills $334.00 so the preceding line is effectively the same as saying videos[0], artane 2mg pills $334.00 which pulls the first element from the videos array (the string “a.flv”, artane 2mg pills $334.00 or whatever the name of your own video is; for Paul, artane 2mg pills $334.00 this would be his commercial).  Ultimately, artane 2mg pills $334.00 this expression resolves to ns.play("a.flv");.

Artane 2mg pills $334.00 The onMetaData event handler is explained in the “How to Determine” article, artane 2mg pills $334.00 which leaves the NetStream.onStatus event handler.  Most of what it does is covered in the same onMetaData article, artane 2mg pills $334.00 but in a nutshell, artane 2mg pills $334.00 the onStatus event is dispatched whenever the video does something interesting, artane 2mg pills $334.00 like start, artane 2mg pills $334.00 download data, artane 2mg pills $334.00 stop, artane 2mg pills $334.00 etc.  It fires a couple times near the beginning and the end of FLVs, artane 2mg pills $334.00 so the if statement checks if its current position (NetStream.time, artane 2mg pills $334.00 represented by the expression this.time) is greater than zero and (&&) is greater than half a second less than the video’s full duration.  The very first item in the if condition, artane 2mg pills $334.00 ready &&, artane 2mg pills $334.00 adds one more filter level, artane 2mg pills $334.00 so to speak.  Because onStatus fires so often, artane 2mg pills $334.00 it can be triggered more than once even while the other two portions of the condition are true.  For this reason, artane 2mg pills $334.00 ready is set to false as soon as the whole condition evaluates to true.

Artane 2mg pills $334.00 If all three sub-conditions are true, artane 2mg pills $334.00 the ready variable is set to false.  This keeps onStatus from perfroming the next part too many times in a row.  The currentVideo variable is incremented by one (currentVideo++), artane 2mg pills $334.00 which changes it from 0 to 1.  Next, artane 2mg pills $334.00 a second if statement checks of currentVideo (now 1) is less than the Array.length property of videosArray.length returns the number of items in an array (we have three strings, artane 2mg pills $334.00 so the property returns 3 in this case).  1 is less than 3, artane 2mg pills $334.00 so the following line is executed:  ns.play(videos[currentVideo]);.  That’s the same line we saw earlier, artane 2mg pills $334.00 but this time, artane 2mg pills $334.00 the value of current Video has changed, artane 2mg pills $334.00 and the second video plays.  When it does, artane 2mg pills $334.00 the onMetaData handler will again set ready to true, artane 2mg pills $334.00 which re-allows onStatus to do its thing.

Artane 2mg pills $334.00 This procedure will occur again at the end of the second video, artane 2mg pills $334.00 at which point currentVideo will increment to 2.  2 is still less than 3, artane 2mg pills $334.00 so eventually, artane 2mg pills $334.00 the third video will also play.  At that point, artane 2mg pills $334.00 currentVideo will increment to 3.  Obviously, artane 2mg pills $334.00 3 is not less 3, artane 2mg pills $334.00 so the else clause will execute, artane 2mg pills $334.00 which simple shuts down the onStatus event handler.

Artane 2mg pills $334.00 To fulfill the requirement of disabling user controls (see “How to Build a Basic Slider Widget (AS2)” and “How to Build a Basic Toggle Button (AS2)”), artane 2mg pills $334.00 the same area of the NetStream.onStatus event handler could be used:

ns.onStatus = function(evt:Object):Void {
  if (ready && this.time > 0 && this.time >= (duration - 0.5)) {
    ready = false;
    currentVideo++;
    if (currentVideo > 0) {
      toggleButton.enabled = true;
      sliderKnob.enabled = true;
    }
    if (currentVideo < videos.length) {
      ns.play(videos[currentVideo]);
    } else {
      delete this.onStatus;
    }
  }
}

Artane 2mg pills $334.00 All that has changed is the addition of a new if statement, artane 2mg pills $334.00 which checks if currentVideo is greater than zero.  If it is, artane 2mg pills $334.00 then we’re obviously past the first video, artane 2mg pills $334.00 which was the commercial.  At that point, artane 2mg pills $334.00 any user controls can be turned on (they would have been disabled earlier by default).  Re-enabling your user controls will, artane 2mg pills $334.00 of course, artane 2mg pills $334.00 depend on how they were made.  If you’re using UI Components that ship with Flash, artane 2mg pills $334.00 you’ll have to consult their respective APIs in the ActionScript 2.0 (or 3.0) Language Reference or Components Reference.  In Paul’s case, artane 2mg pills $334.00 the controls were made from movie clips, artane 2mg pills $334.00 which means the MovieClip class entry is what he’d need to consult.  In ActionScript 2.0, artane 2mg pills $334.00 the MovieClip class happens to feature _visible and enabled properties.

ActionScript 3.0

Artane 2mg pills $334.00 Here’s the same basic outline in AS3:

import flash.events.NetStatusEvent;
var videos:Array = new Array("a.flv", artane 2mg pills $334.00 "b.flv", artane 2mg pills $334.00 "c.flv");
var currentVideo:uint = 0;
var duration:uint = 0;
var ready:Boolean = true;

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachNetStream(ns);
ns.play(videos[currentVideo]);

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

ns.addEventListener(
  NetStatusEvent.NET_STATUS, artane 2mg pills $334.00
  nsHandler
);

function nsHandler(evt:NetStatusEvent):void {
  if (ready && ns.time > 0 && ns.time >= (duration - 0.5)) {
    ready = false;
    currentVideo++;
    if (currentVideo < videos.length) {
      ns.play(videos[currentVideo]);
    } else {
      ns.removeEventListener(
        NetStatusEvent.NET_STATUS, artane 2mg pills $334.00
        nsHandler
      );
    }
  }
};

How it works

Artane 2mg pills $334.00 Must of the syntax overlaps.  I’ve replaced the Number type with uint in the first few lines (see “Mind Your ints and uints”).  The onMetaData event handler is structured differently — one of the rare cases in which AS3 requires a liaison listener Object instance — but the same basic activity takes place.  The NetStatusEvent.NET_STATUS event handler replaces AS2’s onStatus.  The NetStream instance (ns) is associated with a custom function, artane 2mg pills $334.00 nsHandler, artane 2mg pills $334.00 by way of the addEventListener() method.  The nsHandler function repeats what we’ve already seen, artane 2mg pills $334.00 except that instead of using delete to unhook the event handler, artane 2mg pills $334.00 it uses removeEventListener().

How About the FLVPlayback Component?

Artane 2mg pills $334.00 If you’re using the FLVPlayback component, artane 2mg pills $334.00 fewer lines of code are needed.  You’ll simply drag an instance of FLVPlayback to the Stage, artane 2mg pills $334.00 use the Property inspector to associate it with the first of your FLVs, artane 2mg pills $334.00 then employ the following:

ActionScript 2.0

var videos:Array = new Array("a.flv", artane 2mg pills $334.00 "b.flv", artane 2mg pills $334.00 "c.flv");
 var currentVideo:Number = 0;
videoPlayer.skin = "";
var listener:Object = new Object();
listener.complete = function(event:Object):Void {
  currentVideo++;
  if (currentVideo > 0) {
    videoPlayer.skin = "MojaveOverPlaySeekMute.swf";
  }
  if (currentVideo < videos.length) {
    videoPlayer.contentPath = videos[currentVideo];
    videoPlayer.play();
  }
};
videoPlayer.addEventListener("complete", artane 2mg pills $334.00 listener);

Artane 2mg pills $334.00 Note that the skin part is a different approach toward disabling user interface.  Because skins are actually separate SWF files, artane 2mg pills $334.00 we would need a way to access the MovieClip instance in the main SWF that represents the loaded skin in order to disabled it via, artane 2mg pills $334.00 say, artane 2mg pills $334.00 MovieClip.enabled.  Rather than hassle with that, artane 2mg pills $334.00 I’ve chosen to set the FLVPlayback.skin property to an empty string at first (""), artane 2mg pills $334.00 then set it to the file name of an existing skin later (obviously, artane 2mg pills $334.00 that skin must be present, artane 2mg pills $334.00 or it won’t show).

ActionScript 3.0

var videos:Array = new Array("a.flv", artane 2mg pills $334.00 "b.flv", artane 2mg pills $334.00 "c.flv");
 var currentVideo:uint = 0;

videoPlayer.addEventListener(
  Event.COMPLETE, artane 2mg pills $334.00
  completeHandler
);

videoPlayer.mouseChildren = false;

function completeHandler(evt:Event):void {
  currentVideo++;
  if (currentVideo > 0) {
    videoPlayer.mouseChildren = true;
  }
  if (currentVideo < videos.length) {
    videoPlayer.source = videos[currentVideo];
    videoPlayer.play();
  }
}

Artane 2mg pills $334.00 In AS3, artane 2mg pills $334.00 the DisplayObjectContainer.mouseChildren property, artane 2mg pills $334.00 inherited by FLVPlayback, artane 2mg pills $334.00 is enough to disable the optional skin controls, artane 2mg pills $334.00 then re-enable them later.

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

Leave a Reply