About working with custom classes in an application
259
6.
Save the Flash document and select Control > Test Movie to test the file.
Flash displays the following information in the Output panel:
RickyM
EnriqueI
About dynamic classes
Adding the
dynamic
keyword to a class definition specifies that objects based on the specified
class can add and access dynamic properties at runtime. You should create dynamic classes
only if you specifically require this functionality.
Type checking on dynamic classes is less strict than type checking on nondynamic classes,
because members accessed inside the class definition and on class instances are not compared
with those defined in the class scope. Class member functions, however, can still be type
checked for return types and parameter types.
For information on creating dynamic classes, see
“Creating dynamic classes” on page 259
.
Creating dynamic classes
By default, the properties and methods of a class are fixed. That is, an instance of a class can’t
create or access properties or methods that weren’t originally declared or defined by the class.
For example, consider a Person class that defines two properties,
userName
and
age
.
To create a class that is not dynamic:
1.
Select File > New and then select ActionScript File, and then click OK.
2.
Type the following ActionScript into the Script window:
class Person {
public var userName:String;
public var age:Number;
}
If, in another script, you create an instance of the Person class and try to access a property
of the class that doesn’t exist, the compiler generates an error.
3.
Save the file on your hard disk as
Person.as
.
4.
Select File > New and then select Flash Document to create a new FLA file, and then
click OK.
5.
Select File > Save As, name the file
person_test.fla
, and save the file in the same directory
as the Person class you created earlier.
NO
T
E
You cannot use getter and setter method attributes in interface method declarations.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...