244
Classes
Using a class file in Flash
To create an instance of an ActionScript class, use the
new
operator to invoke the class’s
constructor function. The constructor function always has the same name as the class and
returns an instance of the class, which you typically assign to a variable. For example, if you
were using the User class from
“Writing custom class files” on page 235
, you would write the
following code to create a new User object:
var firstUser:User = new User();
Use the dot (
.
) operator to access the value of a property in an instance. Type the name of the
instance on the left side of the dot, and the name of the property on the right side. For
example, in the following statement,
firstUser
is the instance and
username
is the property:
firstUser.username
You can also use the top-level or built-in classes that make up the ActionScript language in a
Flash document. For example, the following code creates a new Array object and then shows
its
length
property:
var myArray:Array = new Array("apples", "oranges", "bananas");
trace(myArray.length); // 3
For more information on using custom classes in Flash, see
“Example: Using custom class files
in Flash” on page 276
. For information on the constructor function, see
“Writing the
constructor function” on page 268
.
NO
T
E
In some cases, you don’t need to create an instance of a class to use its properties and
methods. For more information on class (static) members, see
“About class (static)
members” on page 298
and
“Static methods and properties” on page 249
.
Содержание 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...