03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The name of the class must match the name of the external file that contains the class. The<br />

name of the external file must be the name of the class with the file extension .as appended.<br />

For example, if you name a class Student, the file that defines the class must be named<br />

Student.as.<br />

If a class is within a package, the class declaration must use the fully qualified class name of<br />

the form base.sub1.sub2.MyClass. Also, the class's AS file must be stored within the path in a<br />

directory structure that reflects the package structure, such as base/sub1/sub2/MyClass.as. If a<br />

class definition is of the form "class MyClass," it is in the default package <strong>and</strong> the MyClass.as<br />

file should be in the top level of some directory in the path.<br />

For this reason, it's good practice to plan your directory structure before you begin creating<br />

classes. Otherwise, if you decide to move class files after you create them, you have to modify<br />

the class declaration statements to reflect their new location.<br />

You cannot nest class definitions; that is, you cannot define additional classes within a class<br />

definition.<br />

To indicate that objects can add <strong>and</strong> access dynamic properties at runtime, precede the class<br />

statement with the dynamic keyword. To declare that a class implements an interface, use the<br />

implements keyword. To create subclasses of a class, use the extends keyword. (A class can<br />

extend only one class, but can implement several interfaces.) You can use implements <strong>and</strong><br />

extends in a single statement. The following examples show typical uses of the implements<br />

<strong>and</strong> extends keywords:<br />

class C implements Interface_i, Interface_j // OK<br />

class C extends Class_d implements Interface_i, Interface_j // OK<br />

class C extends Class_d, Class_e // not OK<br />

Parameters<br />

className:String - The fully qualified name of the class.<br />

Example<br />

The following example creates a class called Plant. The Plant constructor takes two<br />

parameters.<br />

// Filename Plant.as<br />

class Plant {<br />

// Define property names <strong>and</strong> types<br />

var leafType:String;<br />

var bloomSeason:String;<br />

// Following line is constructor<br />

// because it has the same name as the class<br />

function Plant(param_leafType:String, param_bloomSeason:String) {<br />

// Assign passed values to properties when new Plant object is created<br />

this.leafType = param_leafType;<br />

170 ActionScript language elements

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!