What Is ActionScript?


ActionScript takes Flash beyond vector graphics and simple animations. With ActionScript you can create user interfaces for rich applications, program multiuser Internet games, or even explore creative possibilities with computational art. One of the great things about ActionScript is that people with different skill levels can use it. You can start with some simple code right away and progress to more advanced coding approaches, such as class-based programming.

Up until now, everything we have discussed about Flash has concerned author-time development. For example, you can use a timeline motion tween to animate the movement of a circle across the stage. With ActionScript, you can program the same animation by writing code that will be executed during runtime while a published SWF file is running. In this chapter, you will learn the basics of coding with ActionScript in Flash.

Code Preparation

One of the biggest questions people have when they begin working in Flash is where to place their code. With Flash, you have a lot of options on where you can place the code. Although technically you can attach ActionScript to the timeline of any frame or to the outside of any button or movie clip symbol instance in your project, it's a good idea to keep your code centralized. All code should be on the main timeline, preferably in the first or second frame. When placing code on the main timeline in the Flash authoring environment, most professional Flash developers place it on its own layer in a blank keyframe. Why? Because it's easy to find. I use the top layer and name it "actions," which is a common practice.

Another step that you can take to make your ActionScripting more easily read and organized is to use comments in your code. Comments are used to explain the code clearly and briefly. They are helpful to you when you return to a project months later. In addition, they are helpful to other people who need to work with your code.

There are two ways to write comments in ActionScript. One option is to place two forward slashes at the beginning of a line of text. This signals to the compiler that the rest of the line is to be ignored and not compiled, and to skip to the next line.

// double slashes indicate that this line is a comment


The second method enables you to mark a multiline block of text as a comment, with /* and */ characters framing the commented text. Anything between the slash-astrix bookends is skipped over by the compiler. This can be used to quickly "comment out" multiline portions of your code and help you pin down the source of a bug in your project.

/* Anything between these slash-astrix bookends is ignored by the compiler, no matter how many lines you type in. */




Special Edition Using Macromedia Studio 8
Special Edition Using Macromedia Studio 8
ISBN: 0789733854
EAN: 2147483647
Year: 2003
Pages: 337

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net