EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Assigning a Class to Symbols in Flash

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Assigning a class to symbols in Flash 279
To create a new instance of the ClassA and ClassB classes:
1. Open the file called package_test.fla.
2. Type the following boldface code into the Script window:
import com.macromedia.utils.*;
var a:ClassA = new ClassA(); // ClassA constructor
a.doSomething(); // call the ClassA's doSomething() method
var b:ClassB = new ClassB(); // ClassB constructor
b.doSomething(); // call the ClassB's doSomething() method
Data typing your objects in this code example enables the compiler to ensure that you
dont try to access properties or methods that arent defined in your custom class. For more
information on strict data typing, see About assigning data types and strict data typing”
on page 81. The exception to data typing your objects is if you declare the class to be
dynamic using the
dynamic keyword. See “Creating dynamic classes” on page 259.
3. Save your changes to the FLA file before you proceed.
You should now have a basic understanding of how to create and use classes in your Flash
documents. Remember that you can also create instances of top-level ActionScript or built-in
classes (see About working with built-in classes” on page 296).
To continue using these class files in a Flash file, see Assigning a class to symbols in Flash
on page 279.
Assigning a class to symbols in Flash
You can also assign a class to symbols that you might use in a Flash file, such as a movie clip
object on the Stage.
To assign a class to a movie clip symbol:
1. Select File > New and then select ActionScript File, and then click OK.
2. Select File > Save As, name the file Animal.as, and save the file on your hard disk.
3. Type the following code into the Script window:
class Animal {
public function Animal() {
trace("Animal::constructor");
}
}
This ActionScript creates a new class called Animal that has a constructor method that
traces a string to the Output panel.
4. Save your changes to the ActionScript file.

Table of Contents

Related product manuals