Flash_and_Flex_03_2009

ActionScript Development

Animating with ActionScript

by Lee McColl Sylvester

This article is targeted at all levels. Whether you’ve been using Flash for years, or have only just started getting to grips with ActionScript, there’s something here for you.

Flash applications; at least where it’s beneficial to do so. Let’s look at this from a subjective point- of-view. Back in the days of ActionScript 2, when presented with an FLA file containing some nice and messy timelines and complex animations, one would normally first start to consider how such content could map to objects in their ActionScript framework. Following this, some careful unpicking would ensue, and new Library assets would be created containing elements of the animations that the ActionScript would later need to manage. At worse, much of the timelines would remain as they are, but small scripts would be added directly to frames throughout the application. It’s enough to make even the most burley developer buckle at the knees.

What you will learn… • How to control MovieClip timelines in Action- Script 3.0 • How to raise events using frame labels • How to create an animation stack, making MovieClip timelines play at different times.

What you should know… • ActionScript at a competent level • The frustration of working with messy design- er FLA’s

realising it, meaning you’re now free to relieve yourself of cleanup duty. You only have to realise it yourself in order to take advantage. ActionScript 3.0 Hidden Secrets Okay, so I’mnot going to tell you about anything in particular that you couldn’t discover with some successful Googling, but I do hope to at least open your mind to a new way of thinking about how one might go about coding up their

Level of difficulty

I n all my years as a Flash developer, there’s one thing that stands paramount in my mind; designers never produce Flash content in a way that’s right for the way I develop. It’s not just me. Every developer I know or have spoken to has this problem. For years, I worked alongside an incredibly gifted Flash designer, who produced content to make the eyes bulge, but his use of the Flash timeline always left me with hours of cleanup and refactoring. He’s not the only designer to express this trait, though. Many designers do. Why? It could be that designers think in some abstract way that requires them to simply regurgitate their cerebral creations onto the stage like some mental projection, or it could be that many designers lack the ability to keep a clean and logical frame of mind. Either way, there’s little that can be done about it. I should know, as I’ve certainly tried hard enough. And, as I’m preparing to do while I open myself up to the inevitable stream of designer originating abuse, all you can do is grin and bear it. The good news, though, is that you don’t have to suffer too much when you code against these atrocities. Thanks to the ActionScript Virtual Machine 2 (AVM2) being profoundly object oriented, many designers now work in such a way as to be object oriented without

Listing 1. The TimelineManager class

package { import flash.display.MovieClip; import flash.display.FrameLabel; public class TimelineManager extends MovieClip { public static function initClip( mc : MovieClip, handler : Function ) : void {

var labels : Array = mc.currentLabels; for each ( var i : FrameLabel in labels ) mc.addFrameScript( i.frame – 1, handler ); } } }

Figure 1. Timeline animation example

03/2009 (5)

20

Made with FlippingBook HTML5