ActionScript Uncovered
ActionScript is an Object-Oriented Programming (OOP) language that interacts
with a movie’s objects and controls the movie’s playhead.
ActionScript is ECMA- 262-compliant, which means it conforms to the international
standard for JavaScript.
While we will examine many aspects of ActionScript, it’s beyond the scope of this publication to cover every built-in function and object. The books listed below cover most of the extended functionality of JavaScript and ActionScript, and are invaluable references that should be a part of any Flash developer’s library.
• ActionScript: The Definitive Guide (2nd Edition, O’Reilly)
• Professional JavaScript (2nd Edition, SAMS)
Throughout this book, I’ll explain why we’re using particular pieces of code; where appropriate, I’ll also show how similar functions can be carried out by timeline manipulation, and why it’s best practice to script them in most circumstances.
Here’s a simple example that illustrates the benefits of ActionScripting and indicates how easy it is to manipulate parts of the ActionScript to alter the final outcome.
To animate an object’s movement from point A to point B, you could create a movie clip of the object you want to move, create two key frames on the timeline, and tween between them to produce the movement. While this is a legitimate method for creating animation, you can instead script this process in a few lines of simple code.
Assume we have a movie clip named myMC. Adding the following ActionScript code to the main timeline moves the movie clip to the right if the horizontal position (_x) is less than 500:
myMC.onEnterFrame = function ()
{
if (this._x < 500)
{
this._x++;
}
};
Pretty simple, isn’t it?
The good thing about scripting animation and other effects is that the scripts can be stored within your own script library (or a shared library), ready for inclusion in your Flash applications whenever you need them. Changing the scripts to suit your needs, rather than altering nested timelines, has obvious benefits in terms of your own productivity, and in helping you develop a reference library. To change the range of motion in the above example, we could simply alter the numeric value from 500 to some other value.
Let’s take a quick look at some of the objectives ActionScript can accomplish, bearing in mind that these are just a few of its many uses. In later chapters, we’ll cover many more, including some that may surprise you.
• Simple or complex animation effects
• Transitional effects
• Interactive user interfaces
• Menu systems that cannot be produced in any other medium
• Experimental mathematical effects
• Simple or complex interactive games
• Connection to databases or external files via a middle tier (ASP,
ColdFusion, PHP, or Macromedia Data Connection Components)
| Download
4 sample chapters Order
The Flash Anthology book here |