EasyManua.ls Logo

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

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...
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 cant
create or access properties or methods that werent 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 doesnt 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.
NOTE
You cannot use getter and setter method attributes in interface method declarations.

Table of Contents

Related product manuals