ITP DriveBy: Flash Motion

The Flash API

An Overview on Flash (The short, SHORT version)

symbolsSymbols available in Flash.

The Flash application programming interface (API) contains a timeline for visually creating linear animation and a panel for writing ActionScript, the event-based programming language of Flash. The Flash API allows the user to animate different visual symbols that are inherent to the API—MovieClips, Buttons, and Graphics. When unused by the timeline, these three types of symbols are contained within the library panel of the Flash API. MovieClips and Buttons are both inherent Classes in Flash ActionScript; Graphics are not, and are therefore inaccessible to the programming side of the application. Graphics serve strictly for organization within the Flash program.

When to Use Graphics

Because of this limitation, many people create all of their elements as MovieClips; the optimal methodology, though, is to create any elements not required in ActionScript as graphics, as Flash will waste memory by naming anything that’s a MovieClip (even if the author doesn’t). To see this in action, create a Flash file, add a MovieClip but don’t name it in the properties panel, Publish the FLA, and try Debug>List Objects in the testing mode. You’ll see “_level0.instance#” as the name.

What Frame Rate to Use

frame rate

The default frame rate in Flash is 12 frames per second (fps), which leads to choppy animations. Television has a frame rate of 30 fps, and film is 24 fps. CRT monitors have a maximum frame rate of 72 fps, meaning anything above this in Flash is a waste. So what should you use? The industry convention is to use 31 fps when creating Flash movies. This frame rate is on par with other screen-based animation, and has proven to run consistently—and occasionally even higher, on PCs and especially Macs. You can set your movie’s frame rate in the properties panel or by using Modify > Document.

Bitmap Caching

Flash has been notoriously bad at handling several moving objects on-screen. Because of the way Flash Player was built, the computer does not allocate additional memory to it like it does with Java. Macromedia has improved the performance of this in Flash Player 8 by creating bitmap caching. Bitmap caching caches a MovieClip and improves performance when a MovieClip, Button, or several MovieClips and/or Buttons are moving on the Stage (Bitmap caching is counterproductive and shouldn’t be used with objects that scale, rotate, or elements within the MovieClips move, though).

bitmap caching

To apply bitmap caching, you can select a MovieClip or Button on the Stage and click the “use runtime bitmap caching” button in the properties panel. This feature is more powerful through ActionScript, though, as you can toggle this Boolean property.

// sets caching to true
myMovieClip.cacheAsBitmap = true;

// sets caching to false
myMovieClip.cacheAsBitmap = false;

Using the Actions Palette

help

One of the greatest tips I can provide is also one of the easiest, though it is often overlooked. If at anytime you don’t know what a reserved keyword (usually highlighted in blue) in the ActionScript palette means, highlight the word and hit the help button. This will bring up the extensive and well-documented ActionScript reference that provides in-depth descriptions and code examples.

If you wish to explore the structure of the language, you can always hit the plus button in the upper left of the palette. This will show the hierarchy of ActionScript code.

hierarchy

Strict Data Typing and Creating Code Shortcuts

Strict Data Typing is a way to ensure that a variable remains the same type of variable from when it has been created to when it is assigned a new variable. This creates more readable code and as an added benefit generates code hints (You can also create code hints through naming conventions, Example: naming MovieClip instances with “_mc” appended will create hints in the ActionScript).

In the past, you would create a variable in Flash by simply declaring:

// create a number variable
var myNumber = 10;

or

// create a number variable
myNumber = 10;

With ActionScript 2.0’s strict data typing, a variable would be declared as

// create a number variable
var myNumber:Number  = 10;

As a result, assigning the variable anything other than a number at a later time would generate a compiler error.

// assign a String type to myNumber
myNumber = “This is a String”; // this would run an error.

So, now with the conventions out of the way, let’s move on to Timeline-based Animations in Flash.

Presented by