ActionScript Prototyping and Inheritance
Before the addition of ActionScript, Flash authors were fairly limited in the interactivity that they could provide. Simple button and frame actions allowed for the creation of nonlinear, mouse-driven movies, but that was about it.
The version of ActionScript included with Flash 5, however, is based on the ECMAScript standard and, therefore, brings with it all the power of a modern scripting language. Now developers can couple the flexibility of Flash's graphics and animation engine with the efficiency of object-oriented programming.
An object-oriented language is unique in that it allows data and programming instructions to be bundled up into functional units called objects. In the course of running an ActionScript-enhanced movie, objects of different types can be created and then made to interact with each other, to produce the desired result.
For the purposes of this article, here are some key terms: A class is a template or recipe for creating new objects. An object is an instance of a class. The process of passing the characteristics of a class onto object instances created in its image is known as inheritance.
The beauty of Flash is that it comes equipped with so many multimedia capabilities built in. Animation, audio, graphics, and text rendering are provided and can be easily set up by hand. ActionScript can then be used to arrange, transform, and otherwise control all those elements to create interactivity. This is much like what JavaScript brings to HTML pages, only better.
To understand how ActionScript works to control Flash movies, it's important to know about the Flash document object model (DOM). In simple terms, Flash's DOM determines what ActionScript can "see" and "touch."
The Flash DOM
Flash's DOM revolves around timelines. In its simplest form, a timeline comprises one or more frames, with each frame capable of playing a sound, executing a set of programming instructions, or just displaying some shapes or symbols.
Each individual movie begins with a single root timeline, and more can be added with the use of movie clips. Movie clips and the root timeline are functionally identical: Both can store data (variables and properties), programming instructions (functions and methods), and combinations of both (objects).
As more timelines are added, the object tree of a movie starts to grow, as shown in Figure 1.
Figure 1 As timelines are added to a movie, the number of places where data and objects can be stored increases.
So why is any of this useful? Well, because the root timeline and any movie clips nested in it are all objects accessible with ActionScript, and they can be manipulated through programming. Because the timelines can each hold other objects, data, and functions, it becomes easy to build multimedia applications within Flash.