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.

Type checking on dynamic classes is less strict than type checking on nondynamic classes,<br />

because members accessed inside the class definition <strong>and</strong> on class instances are not compared<br />

with those defined in the class scope. Class member functions, however, can still be type<br />

checked for return type <strong>and</strong> parameter types. This behavior is especially useful when you work<br />

with MovieClip objects, because there are many different ways of adding properties <strong>and</strong><br />

objects to a movie clip dynamically, such as MovieClip.createEmptyMovieClip() <strong>and</strong><br />

MovieClip.createTextField().<br />

Subclasses of dynamic classes are also dynamic.<br />

Example<br />

In the following example, class Person2 has not yet been marked as dynamic, so calling an<br />

undeclared function on it generates an error at compile time:<br />

class Person2 {<br />

var name:String;<br />

var age:Number;<br />

function Person2(param_name:String, param_age:Number) {<br />

trace ("anything");<br />

this.name = param_name;<br />

this.age = param_age;<br />

}<br />

}<br />

In a FLA or AS file that's in the same directory, add the following ActionScript to Frame 1 on<br />

the Timeline:<br />

// Before dynamic is added<br />

var craig:Person2 = new Person2("Craiggers", 32);<br />

for (i in craig) {<br />

trace("craig." + i + " = " + craig[i]);<br />

}<br />

/* output:<br />

craig.age = 32<br />

craig.name = Craiggers */<br />

If you add an undeclared function, dance , an error is generated, as shown in the following<br />

example:<br />

trace("");<br />

craig.dance = true;<br />

for (i in craig) {<br />

trace("craig." + i + " = " + craig[i]);<br />

}<br />

/* output: **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 14: There is<br />

no property with the name 'dance'. craig.dance = true; Total ActionScript<br />

Errors: 1 Reported Errors: 1 */<br />

Add the dynamic keyword to the Person2 class, so that the first line appears as follows:<br />

dynamic class Person2 {<br />

Statements 177

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

Saved successfully!

Ooh no, something went wrong!