What are Dynamic classes in Actionscript?
- Basically same idea as in perl where an object is a hash, where keys are the names of properties, and the values are the field values, or function pointers.
- More memory overhead than sealed classes.
- More info:
- http://flexblog.faratasystems.com/2006/10/02/actionscript-3-dynamic-classes - you can dynamically add only public properties and methods. Of course, nothing comes for free and sealed classes are a bit more efficient in terms of memory consumption, because they do not need to create a hash table to store the properties and methods that are unknown during compilation. Another obvious restriction is that dynamically added functions can’t access private members of the dynamic class.
- Examples:

dynamic class Person { var name:String; }Now let’s add dynamically two variables name and age and the function printme() to the object of type Person:
Person p= new Person(); p.name=”Joe”; p.age=25; p.printMe = function () { trace (p.name, p.age); } p.printMe(); // Joe 25In AS3, any function can be attached to a dynamically created property of a dynamic object, for example
function calcTax():Number {…} var myObject:SomeObject = new SomeObject(); myObject.tax=calcTax; //add the tax property and attach the function calcTax() var myTax=myObject.tax();The delete operator destroys the property of an object and makes it eligible for garbage collection:
delete calcTax(); myTax=myObject.tax() // generates an error
- Examples:
- Adobe Help for AS 3.0 - Dynamic Classes

Example of adding function to a dynamic class myProtean.traceProtean = function () { trace(myProtean.privateGreeting); // undefined trace(myProtean.publicGreeting); // hello }; myProtean.traceProtean();
- http://flexblog.faratasystems.com/2006/10/02/actionscript-3-dynamic-classes - you can dynamically add only public properties and methods. Of course, nothing comes for free and sealed classes are a bit more efficient in terms of memory consumption, because they do not need to create a hash table to store the properties and methods that are unknown during compilation. Another obvious restriction is that dynamically added functions can’t access private members of the dynamic class.
- More info:
Labels:
None
Add Comment