Archive for April, 2006

Event Handlers versus Event Listeners

Sunday, April 30th, 2006
ActionScript 2.0 Flash

A number of ActionScript classes feature something called events.  An event is raised by an object when a certain occurrence happens.  For example, when someone hovers over a button symbol in a SWF, the Button.onRollOver event is raised for that particular Button instance.  When the mouse is moved elsewhere, the Button.onRollOut event is raised for that same instance.  These events take place whether or not anyone takes notice.  If you want to actually do something in response to an event, you must manage it with an event handler or an event listener.  The choice between these two is determined by the object — some objects expect handlers, some listeners — so hit the ol’ ActionScript Language Reference when in doubt.  Handlers are relatively easy, but for some reason, listeners seem to perplex people at first.  Let’s take a look at both.  Keep reading »

Be in Charge of Browser Cacheing!

Thursday, April 27th, 2006
ActionScript 2.0 Flash

Browsers are supposed to obey.  When you tell them not to cache content, they’re supposed to not cache content.  Right?  But sometimes they have a will of their own, especially when your content includes files that are external to the HTML document, such as SWFs.  For example, you might have built a nifty Flash intro that your client simply adores.  Everyone’s happy — but don’t pour the champagne just yet!  The client’s logo has changed, so would you revise the intro?  Why yes, you would.  And you do, because you provide good service.  You upload the new SWF, but (sigh …) your client doesn’t see the update.

Now, you can advise your client to “clear your cache,” but one person’s “sure, no problem” is another person’s “huh?”  So, where does that leave you?  You can walk through a How To, which might be painless, but might not.  Or you can head this issue off at the pass.  Let’s look at a quick solution.  Keep reading »

setTimeout():  An “Undocumented” Documented Function

Monday, April 24th, 2006
ActionScript 2.0

In an earlier article, we looked at How to Pause a Timeline, which made use of the global setInterval() function to get the timeline rolling again after a specified length of time.  setInterval() has been available since Flash MX (aka Flash 6) and from its inception, has often caused developers to furrow their brows and wonder:  if this function is just like the setInterval() function in JavaScript — and it basically is — why doesn’t ActionScript also feature a setTimeout() function, like JavaScript does?  Keep reading »

The Oma on the Bus Goes …

Saturday, April 22nd, 2006

Meridian loves the song “The Wheels on the Bus,” and we happen to have a board book edition of Raffi’s version of it.  The book is wonderful, because the illustrations are detailed, including little “side plots” that allow me to ask her questions above and beyond the actual story line.  Separate from this, Dawn has added at least a dozen new verses, because Meridian keeps asking for “more, more” when the song ends.  Keep reading »

How to Fix Wrong-sized SWFs in Firefox

Thursday, April 20th, 2006
Flash Web Development

Under certain circumstances, SWFs in Firefox display at the wrong size (usually too small) when their width and height attributes are set to a percent in HTML.  There’s nothing wrong with using percents for width and height — as you’ve likely seen, “full screen” SWFs are a popular practice — but there is a wrong way to code for it.  If you’ve run into this scenario, you’ll be happy to hear the solution is simple.  This is neither a bug in Flash nor Firefox, as a matter of fact, and is resolved with a better understanding of HTML.  Keep reading »

How to Jump to a Random Frame Label

Tuesday, April 18th, 2006
ActionScript 2.0 Flash

This question comes up from time to time in the forums.  Typically, someone has built a Flash banner ad with a handful of entry points.  The ad is supposed to start at any one of these, but the choice should be random.  For example, a fruit stand ad is supposed to play the bit about the bananas first, then the apples, then the bananas again, then the oranges.  How can this be accomplished?  Well, this one’s pretty easy.  Keep reading »

How to Tell When an External SWF has Fully Loaded

Sunday, April 16th, 2006
ActionScript 2.0 Flash

It’s easy to load an external SWF or image at runtime.  The MovieClip.loadMovie() method is all you need.  Simply reference a given movie clip as your container — even if that’s _root or this — and supply the path to an external SWF or image as the method parameter.  Just one line of code.


But how do you know when that file has finished loading?  You may, for example, wish to provide a caption beneath a loaded JPG, or you may wish to center a loaded SWF, which would require knowing its MovieClip._width property — information that isn’t available until loading is complete.  Keep reading »

Macaroni in My Pocket

Thursday, April 13th, 2006

Earlier today, I reached into the left front pocket of my jeans and found a single piece of elbow macaroni.  At first, I was taken aback, “What on earth?”  But then I remembered.  Ah, and it gave me a smile, too.

My daughter, Meridian, will be two years old in a month.  She’s a bright kid.  (Yeah, I know, that’s the expected assessment of a loving father, but hey, it’s true!)  She speaks German with me and English with my wife, Dawn.  She loves all animals, but especially dogs, and the rabbits and squirrels in our back yard.  She loves to read.  She loves to cook.  Keep reading »

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

Thursday, April 13th, 2006
ActionScript 2.0 Flash

Note:  This article has a companion piece, “How to Control Video (FLV) without a Component.”  An ActionScript 3.0 version of this article is located in a more recent entry of this blog.

It has been possible to load external video into a movie since Flash MX (aka Flash 6).  Loading FLV files, however, isn’t nearly as intuitive as loading other external media, such as SWFs, JPGs, MP3s, and the like.  The MovieClip.loadMovie() method, for example, loads an external SWF with a single line of code.  Not so for FLV.  So how is it done?  Keep reading »

Getting the Most Out of Array.sort()

Tuesday, April 11th, 2006
ActionScript 2.0

Have you ever been surprised by the result of invoking Array.sort() on an array of numbers?  Curiously, numbers seem to be sorted in alphabetical order, which doesn’t seem intuitive.  A list of 4, 10, 2006, for example, sorts into 10, 2006, 4, rather than remaining unchanged, since the original is already sorted numerically.  From an alphabetical point of view, the “words” “4,” “10,” and “2006” would be arranged by their first “letters,” in which case it follows that “1” comes before “2,” and “2” comes before “4.”  But this is ridiculous, right?  What do you do if you want to sort numerically?  Keep reading »