Archive for November, 2007

Trust Me, AS3, It’s a MovieClip

Thursday, November 29th, 2007
ActionScript 3.0 Flash

This topic came up when someone asked me how (if it was possible) to instruct one movie clip to start playing after another has stopped.  For example, the main timeline does its thing, humming along, when it suddenly comes to a keyframe that contains a nested movie clip.  A simple stop() action in that keyframe tells the main timeline to rest where it is, and the nested movie clip starts playing on its own.  When the nested clip hits the last frame of its own timeline … that’s when the main timeline needs to start moving again.  How to do that?

In my reply, I said there were a number of possible ways.  You could set up a loop, for example — MovieClip.onEnterFrame (AS2) or Event.ENTER_FRAME (AS3), maybe setInterval() (AS2) or the Timer class (AS3) — and in that loop, check the current frame of the nested movie clip against the number of its total frames.  In AS2, that would be a comparison of _currentframe to _totalframes; in AS3, currentFrame to totalFrames.  When the former equals the latter, invoke MovieClip.play() on the main timeline and quit the loop.

But much easier than that, and less processor intensive, is simply to put a keyframe script in the last frame of the nested movie clip, telling its parent (the main timeline) to play.  In AS2, that would be this._parent.play();.  In AS3, this.parent.play(); (no underscore on parent).  Ah, but there lies a problem.  The AS3 version, which is technically correct, causes a compiler warning:  1061: Call to a possibly undefined method play through a reference with static type flash.display:DisplayObjectContainer.  What on earth?  Keep reading »

How to Pause and Loop the Timeline in Flash CS3 (AS3)

Monday, November 26th, 2007
ActionScript 3.0 Flash

How to pause the main timeline (or any timeline), and how to loop it, are fairly common questions on the Adobe forums — not super hot topics, but they continue to crop up every few months.  I suggested an AS2 approach to both questions in “How to Pause a Timeline (AS2)” and “How to Loop a Movie Three Times (AS2)” in 2006, but now with Flash CS3’s support for ActionScript 3.0, a couple of updates make good sense.

Check out “Using ActionScript to pause and loop the timeline in Flash,” in the Adobe Design Center, to see how things have changed.  Looping, as it turns out, can be handled in practically the same way.  The recommended approach for pausing now calls for the Timer class, which operates very differently from the setInterval() used in AS2.

And the Winner of Essential ActionScript 3.0 is …

Thursday, November 15th, 2007
ActionScript 3.0 Flash Meridian

First of all, I’d like to give a big thanks to everyone who sent in a post card!  :)   Meridian has shown a great interest in maps lately, so (as it happens) we bought her a windshield-sized world map not long ago and had it mounted on foam board.  She’s been noting places we’ve traveled with stick pins, and as post cards started to arrive, we had fun discussing what places they came from.  I really think it’s neat that people visit this blog from over a dozen different countries!

Post cards were deposited into a pillowcase, and Meridian chose one without looking.  The winner was John in Sweden, whom I’ve contacted via email for shipping information.  Here’s the post card drawing in five photos.  Enjoy Moock’s Essential ActionScript 3.0, John — it’s a winner!

How to Load External Flash Video (FLV) Files (AS3)

Tuesday, November 13th, 2007
ActionScript 3.0 Flash

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, to load an external Flash video (FLV) file at runtime — without using the FLVPlayback component.  To be sure, there’s nothing wrong with FLVPlayback.  Its skins are customizable (all the more so in Flash CS3, which is the first version of Flash to support AS3) and it provides plenty of built-in widgets, such as play/pause, a volume slider, mute button, and the like.  But to get those features, even if you choose a non-skinned component, you pay a 49KB price in an ActionScript 3.0 document.  If you go without the component, it costs you less than 1KB.  That means site visitors can spend their bandwidth on your video content itself, rather than the video player.  Keep reading »