EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 278

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...
278 Classes
To import a class or package:
1. Open the file called package_test.fla.
2. Type the following code into the Script window:
import com.macromedia.utils.*;
var a = new ClassA(); // ClassA constructor
var b = new ClassB(); // ClassB constructor
The previous block of code begins by importing each of the classes within the
com.macromedia.utils package by using the wildcard (*) character. Next, you create a
new instance of the ClassA class, which causes the constructor method to trace a message
to the Output panel. An instance of the ClassB class is also created, which sends
debugging messages to the Output panel.
3. Save your changes to the Flash document before you proceed.
To continue using these class files in a Flash file, see “Creating instances of classes in an
example” on page 278.
Creating instances of classes in an example
Instances are objects that contain all the properties and methods of a particular class. For
example, arrays are instances of the Array class, so you can use any of the methods or
properties of the Array class with any array instance. Or you can create you own class, such as
UserSettings, and then create an instance of the UserSettings class.
Continuing the example you started in “Example: Using custom class files in Flash
on page 276, you modified FLA file to import the classes you wrote so that you dont have to
always refer to them by their fully qualified names.
The next step in this example (“Example: Using custom class files in Flash” on page 276) is to
create an instance of the ClassA and ClassB classes in a script, such as a frame script in a
package_test.fla Flash document, and assign it to a variable. To create an instance of a custom
class, you use the
new operator in the same way you would when creating an instance of a top-
level ActionScript class (such as the Date or Array class). You refer to the class using its fully
qualified class name, or import the class (as demonstrated in “Importing classes and packages
on page 276.)
NOTE
The following exercise is part of “Example: Using custom class files in Flash”
on page 276 which continues the examples “Example: Writing custom classes”.

Table of Contents

Related product manuals