374 Chapter 12: ActionScript Dictionary
Description
Keyword; specifies that objects based on the specified class can add and access dynamic properties
at runtime.
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 to those
defined in the class scope. Class member functions, however, can still be type checked for return
type and parameter types. This behavior is especially useful when you work with MovieClip
objects, because there are many different ways of adding properties and objects to a movie clip
dynamically, such as
MovieClip.createEmptyMovieClip() and
MovieClip.createTextField().
Subclasses of dynamic classes are also dynamic.
For more information, see “Creating dynamic classes” on page 173.
Example
In the following example, class B has been marked as dynamic, so calling an undeclared function
on it will not throw an error at compile time.
// in B.as
dynamic class B extends class_A {
function B() {
/*this is the constructor*/
}
function m():Number {return 25;}
function o(s:String):Void {trace(s);}
}
// in C.as
class C extends class_A {
function C() {
/*this is the constructor*/
}
function m():Number {return 25;}
function o(s:String):Void {trace(s);}
}
// in another script
var var1 = B.n(); // no error
var var2 = C.n() // error, as there is no function n in C.as
See also
class
, extends