Like ActionScript 2, ActionScript 3 allows you to create dynamic classes using the dynamic keyword (dynamic keyword). Dynamic classes are classes you can add properties to dynamically without needing to declare or define them within the class definition. An example of a dynamic class would be Array. When you create an Array instance, you can assign to it any variariable you want despite it not being within the Array class definiton.
In AS2, when you extended a class that was dyanmic, that subclass too became dynamic.
ActionScript Code:
// superclass.as
dynamic class superclass {
}
// subclass.as
class subclass extends superclass {
}
// main movie
var instance:subclass = new subclass();
trace(instance.anything); // ok since subclass inherited dynamic
This is no longer the case with AS3. Subclasses of dynamic classes are no longer dynamic unless specified as being dynamic themselves
ActionScript Code:
// superclass.as
package {
dynamic class superclass {
}
}
// subclass.as
package {
class subclass extends superclass {
}
}
// main movie
var instance:subclass = new subclass();
trace(instance.anything); // error, property not defined (not dynamic)
0 评论:
发表评论