dynamic

Availability

Flash Player 6.

Usage

dynamic class className  [ extends superClass ] 
              [ implements interfaceName [, interfaceName... ] ]
{
  // class definition here
}

Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later 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

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.

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