Blood Pressure > Propranolol 20mg Pills > 270 > $342.00

ActionScript 2.0 ActionScript 3.0

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

An answer, blood pressure > propranolol 20mg pills > 270 > $342.00 short and sweet

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

Blood pressure > propranolol 20mg pills > 270 > $342.00 Let’s start with ActionScript 2.0.  Here’s the chunk of code:

ActionScript 2.0

var videos:Array = new Array("a.flv", blood pressure > propranolol 20mg pills > 270 > $342.00 "b.flv", blood pressure > propranolol 20mg pills > 270 > $342.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

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

Blood pressure > propranolol 20mg pills > 270 > $342.00 The third line declares a variable named duration, blood pressure > propranolol 20mg pills > 270 > $342.00 which will be updated later from its initial value of zero in response to the NetStream.onMetaData event, blood pressure > propranolol 20mg pills > 270 > $342.00 as described in “How to Determine the Completion of a Flash Video (FLV) File.”  Finally, blood pressure > propranolol 20mg pills > 270 > $342.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.

Blood pressure > propranolol 20mg pills > 270 > $342.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, blood pressure > propranolol 20mg pills > 270 > $342.00 the videos array already makes its entrance:

Blood pressure > propranolol 20mg pills > 270 > $342.00 ns.play(videos[currentVideo]);

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

Blood pressure > propranolol 20mg pills > 270 > $342.00 The onMetaData event handler is explained in the “How to Determine” article, blood pressure > propranolol 20mg pills > 270 > $342.00 which leaves the NetStream.onStatus event handler.  Most of what it does is covered in the same onMetaData article, blood pressure > propranolol 20mg pills > 270 > $342.00 but in a nutshell, blood pressure > propranolol 20mg pills > 270 > $342.00 the onStatus event is dispatched whenever the video does something interesting, blood pressure > propranolol 20mg pills > 270 > $342.00 like start, blood pressure > propranolol 20mg pills > 270 > $342.00 download data, blood pressure > propranolol 20mg pills > 270 > $342.00 stop, blood pressure > propranolol 20mg pills > 270 > $342.00 etc.  It fires a couple times near the beginning and the end of FLVs, blood pressure > propranolol 20mg pills > 270 > $342.00 so the if statement checks if its current position (NetStream.time, blood pressure > propranolol 20mg pills > 270 > $342.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, blood pressure > propranolol 20mg pills > 270 > $342.00 ready &&, blood pressure > propranolol 20mg pills > 270 > $342.00 adds one more filter level, blood pressure > propranolol 20mg pills > 270 > $342.00 so to speak.  Because onStatus fires so often, blood pressure > propranolol 20mg pills > 270 > $342.00 it can be triggered more than once even while the other two portions of the condition are true.  For this reason, blood pressure > propranolol 20mg pills > 270 > $342.00 ready is set to false as soon as the whole condition evaluates to true.

Blood pressure > propranolol 20mg pills > 270 > $342.00 If all three sub-conditions are true, blood pressure > propranolol 20mg pills > 270 > $342.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++), blood pressure > propranolol 20mg pills > 270 > $342.00 which changes it from 0 to 1.  Next, blood pressure > propranolol 20mg pills > 270 > $342.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, blood pressure > propranolol 20mg pills > 270 > $342.00 so the property returns 3 in this case).  1 is less than 3, blood pressure > propranolol 20mg pills > 270 > $342.00 so the following line is executed:  ns.play(videos[currentVideo]);.  That’s the same line we saw earlier, blood pressure > propranolol 20mg pills > 270 > $342.00 but this time, blood pressure > propranolol 20mg pills > 270 > $342.00 the value of current Video has changed, blood pressure > propranolol 20mg pills > 270 > $342.00 and the second video plays.  When it does, blood pressure > propranolol 20mg pills > 270 > $342.00 the onMetaData handler will again set ready to true, blood pressure > propranolol 20mg pills > 270 > $342.00 which re-allows onStatus to do its thing.

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

Blood pressure > propranolol 20mg pills > 270 > $342.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)”), blood pressure > propranolol 20mg pills > 270 > $342.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;
    }
  }
}

Blood pressure > propranolol 20mg pills > 270 > $342.00 All that has changed is the addition of a new if statement, blood pressure > propranolol 20mg pills > 270 > $342.00 which checks if currentVideo is greater than zero.  If it is, blood pressure > propranolol 20mg pills > 270 > $342.00 then we’re obviously past the first video, blood pressure > propranolol 20mg pills > 270 > $342.00 which was the commercial.  At that point, blood pressure > propranolol 20mg pills > 270 > $342.00 any user controls can be turned on (they would have been disabled earlier by default).  Re-enabling your user controls will, blood pressure > propranolol 20mg pills > 270 > $342.00 of course, blood pressure > propranolol 20mg pills > 270 > $342.00 depend on how they were made.  If you’re using UI Components that ship with Flash, blood pressure > propranolol 20mg pills > 270 > $342.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, blood pressure > propranolol 20mg pills > 270 > $342.00 the controls were made from movie clips, blood pressure > propranolol 20mg pills > 270 > $342.00 which means the MovieClip class entry is what he’d need to consult.  In ActionScript 2.0, blood pressure > propranolol 20mg pills > 270 > $342.00 the MovieClip class happens to feature _visible and enabled properties.

ActionScript 3.0

Blood pressure > propranolol 20mg pills > 270 > $342.00 Here’s the same basic outline in AS3:

import flash.events.NetStatusEvent;
var videos:Array = new Array("a.flv", blood pressure > propranolol 20mg pills > 270 > $342.00 "b.flv", blood pressure > propranolol 20mg pills > 270 > $342.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, blood pressure > propranolol 20mg pills > 270 > $342.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, blood pressure > propranolol 20mg pills > 270 > $342.00
        nsHandler
      );
    }
  }
};

How it works

Blood pressure > propranolol 20mg pills > 270 > $342.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, blood pressure > propranolol 20mg pills > 270 > $342.00 nsHandler, blood pressure > propranolol 20mg pills > 270 > $342.00 by way of the addEventListener() method.  The nsHandler function repeats what we’ve already seen, blood pressure > propranolol 20mg pills > 270 > $342.00 except that instead of using delete to unhook the event handler, blood pressure > propranolol 20mg pills > 270 > $342.00 it uses removeEventListener().

How About the FLVPlayback Component?

Blood pressure > propranolol 20mg pills > 270 > $342.00 If you’re using the FLVPlayback component, blood pressure > propranolol 20mg pills > 270 > $342.00 fewer lines of code are needed.  You’ll simply drag an instance of FLVPlayback to the Stage, blood pressure > propranolol 20mg pills > 270 > $342.00 use the Property inspector to associate it with the first of your FLVs, blood pressure > propranolol 20mg pills > 270 > $342.00 then employ the following:

ActionScript 2.0

var videos:Array = new Array("a.flv", blood pressure > propranolol 20mg pills > 270 > $342.00 "b.flv", blood pressure > propranolol 20mg pills > 270 > $342.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", blood pressure > propranolol 20mg pills > 270 > $342.00 listener);

Blood pressure > propranolol 20mg pills > 270 > $342.00 Note that the skin part is a different approach toward disabling user interface.  Because skins are actually separate SWF files, blood pressure > propranolol 20mg pills > 270 > $342.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, blood pressure > propranolol 20mg pills > 270 > $342.00 say, blood pressure > propranolol 20mg pills > 270 > $342.00 MovieClip.enabled.  Rather than hassle with that, blood pressure > propranolol 20mg pills > 270 > $342.00 I’ve chosen to set the FLVPlayback.skin property to an empty string at first (""), blood pressure > propranolol 20mg pills > 270 > $342.00 then set it to the file name of an existing skin later (obviously, blood pressure > propranolol 20mg pills > 270 > $342.00 that skin must be present, blood pressure > propranolol 20mg pills > 270 > $342.00 or it won’t show).

ActionScript 3.0

var videos:Array = new Array("a.flv", blood pressure > propranolol 20mg pills > 270 > $342.00 "b.flv", blood pressure > propranolol 20mg pills > 270 > $342.00 "c.flv");
 var currentVideo:uint = 0;

videoPlayer.addEventListener(
  Event.COMPLETE, blood pressure > propranolol 20mg pills > 270 > $342.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();
  }
}

Blood pressure > propranolol 20mg pills > 270 > $342.00 In AS3, blood pressure > propranolol 20mg pills > 270 > $342.00 the DisplayObjectContainer.mouseChildren property, blood pressure > propranolol 20mg pills > 270 > $342.00 inherited by FLVPlayback, blood pressure > propranolol 20mg pills > 270 > $342.00 is enough to disable the optional skin controls, blood pressure > propranolol 20mg pills > 270 > $342.00 then re-enable them later.

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

Leave a Reply