< Day Day Up > |
We saw earlier that trying to dynamically add a property to the Date class generates a compile-time error in ActionScript 2.0. To allow new properties and methods to be added to a class's instances without generating a compile-time error, we can use a dynamic class . You can define your own dynamic classes, but some built-in classes are dynamic by default. Due partially to the architecture of the Flash Player and partially to the heritage of ActionScript 1.0, the following native ActionScript 2.0 classes are dynamic:
When you attempt to access a nonexistent property or method on an object of one of the preceding dynamic classes, the ActionScript 2.0 compiler does not generate an error. For example, the following code yields no error: var dataSender:LoadVars = new LoadVars( ); dataSender.firstName = "Rebecca"; // No error, even though // the LoadVars class doesn't // define the firstName property. However, type mismatch errors may still occur when using the preceding dynamic classes. For example, the following code creates a variable of type Array and attempts to place a Date instance into it: var list:Array = new Date( ); It yields the following error: Type mismatch in assignment statement: found Date where Array is required.
|
< Day Day Up > |