Archive for the 'ActionScript 3.0' Category

MP3 Cue Points Article Updated on Adobe Developer Connection

Tuesday, December 4th, 2007
ActionScript 2.0 ActionScript 3.0

I wrote a cue points article last year (October, 2006) for what was then called the Adobe Dev Center.  One of the editors recently asked me to update that article for Flash CS3, which I was happy to do.  It’s now available on the Adobe Developer Connection at the following URL.

http://www.adobe.com/devnet/actionscript/articles/cue_points_audio.html

If you’re looking for a way to assign cue points to audio files (especially MP3 files loaded at runtime), I hope you find this article useful.  It steps through a custom SoundSync class in ActionScript 2.0 and 3.0.

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 »

Chance to Win a Free Copy of Moock’s Essential ActionScript 3.0

Thursday, October 25th, 2007
ActionScript 3.0 General

Note:  This contest has now ended, with results posted here.  Thanks for the post cards, everybody!

I’m an admirer of the clarity, thoroughness, and encouraging tone of Colin Moock’s books.  To that end, I pre-ordered his Essential ActionScript 3.0 (O’Reilly) long before it was available and was delighted when it arrived on my doorstep several months later.  Flash forward (pun) from that moment to just over a month ago, when I arrived in Boston for a terrific Flashforward conference.  Kevin Lynch, Adobe Chief Software Architect and keynote speaker, arranged to have a copy of Essential ActionScript 3.0 for every attendee, which was a fantastic and generous gift.  What that means is that I have a mint condition extra copy of Moock’s latest, and I’m happy to give it away.  I’ll pay shipping to anywhere in the world.

If you send me a post card and it gets here between now and November 15, 2007, I’ll have my three-year-old daughter, Meridian, choose randomly from the pile on that date.  I’m hoping three weeks gives everyone a fair chance, whether or not you’re in the US.  I’d love to hear about how this blog has helped you, if it has, but most importantly, I will of course need your return address, email address, or some other handy way to get your shipping address.

Send post cards to:

David Stiller
1700 Gray Slate Court
Virginia Beach, VA  23456

How to Play Flash Video Files (FLV) Sequentially

Friday, October 19th, 2007
ActionScript 2.0 ActionScript 3.0

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

How to Use Flash Video (FLV) Cue Points

Tuesday, October 9th, 2007
ActionScript 2.0 ActionScript 3.0 Flash

Video cue points can be used for all sorts of things in Flash.  Typical uses involve triggering other activity, such as peripheral movie clips whose animations enhance the video content, or triggering text, such as closed captions.  I’ve seen some developers in the Adobe forums even use a cue point to signal that a video clip has reached its end.  Strictly speaking, cue points aren’t needed for that last goal (see “How to Determine the Completion of a Flash Video (FLV) File”), but it’s certainly a possible way to go.

If you’re interested in cue points yourself, but don’t know where to begin, let’s dive in.  Keep reading »

How to Retrieve FlashVars Data in ActionScript 3.0

Tuesday, September 25th, 2007
ActionScript 3.0 Flash

Last year around this time, I described how to pass variables into a SWF by way of something called FlashVars.  This was discussed in “How to Tell a SWF What File(s) to Load — From the Outside” which works for pretty much any sort of simple data you may want to pass in, as long as you’re talking about relatively small groups of name/value pairs.  Complex data is more likely to be suited to XML.  In that earlier blog entry, the purpose was to re-use a single SWF numerous times to load a variety of MP3 files, by specifying which audio in the HTML.  Pretty flexible solution!  You could use the same technique for loading JPGs or FLVs, to populate dynamic text fields, or whatever you like.  The article has been fairly popular and continues to be useful — as long as your SWF is published for ActionScript 2.0 (or even 1.0 if you drop the post colon suffixes — :String, :Number, and the like).  In ActionScript 3.0, things are different.  Keep reading »

How to Pause a Timeline (AS3)

Monday, August 27th, 2007
ActionScript 3.0 Flash

If the title of this blog entry sounds familiar, it may be because you saw the ActionScript 2.0 equivalent on this site over a year ago.  In the comments to that article, a reader named Eric asked how to pause a timeline in ActionScript 3.0 (very different from AS2, as it turns out).  There’s a significant benefit to using ActionScript (whatever version) to temporarily halt the timeline, then resume after a few seconds:  it’s all about saving yourself the hassle of horizontal scrolling.  Consider pausing for five whole minutes.  At the default 12fps, that would require 3,600 frames of timeline real estate.  With code, you can pull it off in a single frame.  Let’s take a look.  Keep reading »