746
Best Practices and Coding Conventions for ActionScript 2.0
One of the most difficult parts of debugging a FLA file is finding all the code. After you find
all the code, you must figure out how it interacts with other pieces of code along with the FLA
file. If you put all your code in a single frame, it is much easier to debug because it is
centralized, and these problems occur less frequently. For information on attaching code to
objects (and decentralizing your code), see
“Attaching code to objects” on page 746
. For
information on behaviors and decentralized code, see
Chapter 3, “Best practices for using
behaviors”
in
Using Flash
.
Attaching code to objects
You must avoid attaching ActionScript code to objects (such as button or movie clip
instances) in a FLA file, even in simple or prototype applications. Attaching code to an object
means that you select a movie clip, component, or button instance, open the ActionScript
editor (the Actions panel or Script window), and add ActionScript code by using the
on()
or
onClipEvent()
handler functions.
This practice is strongly discouraged for the following reasons:
■
ActionScript code that is attached to objects is difficult to locate, and the FLA files are
difficult to edit.
■
ActionScript code that is attached to objects is difficult to debug.
■
ActionScript code that is written on a timeline or in classes is more elegant and easier to
build upon.
■
ActionScript code that is attached to objects encourages poor coding style.
■
ActionScript code that is attached to objects forces students and readers to learn additional
syntax as well as different coding styles that are often poor and limited.
■
Users typically have to relearn how to write functions and so on, on a timeline at a later
date.
Some Flash users might say it is easier to learn ActionScript by attaching code to an object.
Some also say it might be easier to add simple code, or write about or teach ActionScript this
way. However, the contrast between two styles of coding (code placed on objects, and frame
scripts) can be confusing to developers who are learning ActionScript and should be avoided.
Also, users who learn how to write code attached to objects often have to relearn how to place
the equivalent code as a frame script at a later date. This is why consistency throughout the
learning process, by learning how to write frame scripts, has advantages.
Attaching ActionScript code to a button called
myBtn
appears as follows. Avoid this method:
on (release) {
// Do something.
}
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...