|
|
|
|
| Tutorial |
When you know what you want, you can use the ActionScript that you need to accomplish the tasks.
Getting scripts to work the way you want takes time—often more than one cycle of writing, testing,
and debugging. The best approach is to start simple and test your work frequently. When you get
one section of a script working, choose Save As to save a version of the file (for example,
myDoc01.fla) and start writing the next section. This approach will help you identify trouble spots
efficiently and ensure that your ActionScript is solid as you begin to write more complex scripts.
For more information, see “Testing a movie” under Help > Using Flash.
About object-oriented scripting
In object-oriented scripting, information is organized into groups called classes. You can create
multiple instances of a class, called objects, to use in your scripts. You can create your own classes
and use the built-in ActionScript classes; the built-in classes are located in the Objects folder of
the Actions panel.
When you create a class, you define all the properties (characteristics) and methods (behaviors) of
each object it creates, just as real-world objects are defined. For example, a person could be said to
have properties such as gender, height, and hair color and methods such as talk, walk, and throw.
In this example, Person would be a class, and each individual person would be an object, or an
instance of that class.
Objects in ActionScript can be pure containers for data, or they can be graphically represented on
the Stage as movie clips, buttons, or text fields. All movie clips are instances of the built-in class
MovieClip, and all buttons are instances of the built-in class Button. Each movie clip instance
contains all the properties (for example, _height, _rotation, _totalframes) and all the
methods (for example, gotoAndPlay, loadMovie, startDrag) of the MovieClip class.
To define a class, you create a special function called a constructor function. (Built-in classes have
built-in constructor functions.) For example, if you want information about a bicycle rider in
your movie, you could create a constructor function, Biker, with the properties time and
distance and the method getSpeed, which tells you how fast the biker is traveling:
function Biker(t, d) {
this.time = t;
this.distance = d;
this.getSpeed = function() {return this.time / this.distance;};
}
In this example, you create a function that needs two pieces of information, or parameters, to do
its job: t and d. When you call the function to create new instances of the object, you pass it the
parameters. The following code creates instances of the object Biker called emma and hamish.
emma = new Biker(30, 5);
hamish = new Biker(40, 5);
In object-oriented scripting, classes can receive properties and methods from each other according
to a specific order; this is called inheritance. You can use inheritance to extend or redefine the
properties and methods of a class. A class that inherits from another class is called a subclass. A
class that passes properties and methods to another class is called a superclass. A class can be both a
subclass and a superclass.
For more information, see “Using a built-in object” on page 236 and “Creating inheritance” on
page 241.
|
|
|
|
|
|
| Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist |
|