dynamic

Availability

Flash Player 6.

Usage

dynamic class className [ extends className] {} 

Note: To use this keyword, you must specify ActionScript 2 and Flash Player 6 or Flash Player 7 in the Flash tab of your FLA file's Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.

Description

Apply the dynamic keyword to class definitions to indicate that instances of the class can add and access dynamic properties at runtime. Typechecking on these classes is more lenient, as members accessed inside the class definition and on class instances are not compared to those defined in the class scope. Class member functions, however, may still be typechecked for return type and parameter types. This behavior is especially useful when working with MovieClip objects, where there are many different ways of adding properties and objects to a movie clip dynamically, such as MovieClip.createEmptyMovieClip() and MovieClip.createTextField().

Example

In the example below, class B has been marked as dynamic, so calling some undeclared function on it will not throw an error at compile-time.

dynamic class B extends A
{
  function B() {/*this is the constructor*/}
  function m():Number {return 25;}
  function o(s:String):Void {trace(s);}
} 

See also

class