Americas

  • United States

Complex Flash programming well worth the effort

Opinion
Feb 02, 20044 mins
Enterprise Applications

You’ll find that creating rich media Flash movies is much easier than creating similar effects in, say, Java, Dynamic HTML or Visual Basic, so there is an immediate, upfront cost advantage.

Last week we broached the topic of Macromedia’s Flash system and discussed the basics of creating animations. If that were all you could do with Flash, the results would be pretty cool, but add programmability to that and the results can be fantabulous!

Programming in Flash is the province of ActionScript, Macromedia’s homegrown language that owes much of its design to JavaScript (more accurately, it is based on ECMAscript). But it differs from JavaScript in five main areas.

First, its document object model is very different from that of JavaScript. Instead of the objects you’d find in a browser environment, you have a top-level object named Flash, under which are nine child objects, including: Document, an array of all the open documents; Effect, descriptors of effects such as brightness and tint; Math (need we spell this one out?); and XMLUI, for custom dialog boxes written in a subset of the XML User Interface Language (see www.xulplanet.com).

Second, there are a few JavaScript statements that are not supported in ActionScript, including the switch statement and exception handling (try/catch/throw).

Third, ActionScript supports some statements, such as event handlers and message sending, that don’t exist in JavaScript.

Fourth, under ActionScript the evaluation function evaluates only variable references rather than evaluating strings that represent arithmetic expressions as JavaScript does.

And fifth, ActionScript supports only a subset of some of the built-in JavaScript objects such as Date and String, and their methods and properties.

So there you have it, better and worse. Be that as it may . . . the result is a rich, complex language that any self-respecting JavaScript programmer would take one look at and say, “Groovy, it will cost you double” . . . but would be able to handle immediately.

The first version of the language, ActionScript 1.0, was superseded by ActionScript 2.0, which introduced improvements. And ActionScript 2.0 has been benchmarked to be three to seven times faster than Version 1.0.

As much as we’d like to, we won’t go into the language basics, because it would take far too many columns to make a real dent in the topic. Instead we would refer you to Introducing ActionScript (DocFinder: 9528), an excerpt from Macromedia Flash MX 2004 ActionScript: Training from the Source by Derek Franklin and Jobe Makar, and Macromedia’s online ActionScript Basics  and Introduction to ActionScript 2.0 (DocFinder: 9530).

The ActionScript programming environment is part of the Flash MX development system based on the concepts of a “stage” and a “timeline,” as we discussed last week. This is where you create media elements by assembling them on the stage and arranging them on the timeline to create a movie clip.

The Flash development environment includes a sophisticated script editor. This has two modes: basic, which lets you construct scripts by picking actions from a predefined list that you then customize by dialog choices that provide lots of help in defining the code; and advanced, which provides a free-form text editor with keyword coloring and a lot less interference from the help system. Scripts are tested in the Flash development environment, and there’s a script debugger to watch variables and object properties, set breakpoints and trace statement execution.

Remember that Flash movies consist of a sequence of frames and that frames can be layered with separate graphical elements on each layer? Well, frames also can have scripts attached to layers within them but you have to be careful, as only the uppermost layer’s script will be executed in a given frame. Most developers assign a layer specifically for scripts to avoid confusion and errors.

So now we would like to show you the obligatory “Hello World” example in ActionScript, except it is rather tricky, because the entire ActionScript paradigm is so graphics-based that we’d have to resort to death by screenshots.

The bottom line is that ActionScript is a complex language but the complexity is worth coming to grips with – you’ll find that creating rich media Flash movies is much easier than creating similar effects in, say, Java, Dynamic HTML or Visual Basic, so there is an immediate, upfront cost advantage.

Next week we’ll wrap up Flash. Expose yourself to gearhead@gibbs.com.

mark_gibbs

Mark Gibbs is an author, journalist, and man of mystery. His writing for Network World is widely considered to be vastly underpaid. For more than 30 years, Gibbs has consulted, lectured, and authored numerous articles and books about networking, information technology, and the social and political issues surrounding them. His complete bio can be found at http://gibbs.com/mgbio

More from this author