Whenever I try to extend the Object prototype, I get an error:
Error #1056: Cannot create property my_extension on mx.core.UIComponentDescriptor.
I searched around, and found these:
Flash AS3: ReferenceError: Error #1056: Cannot create property
ReferenceError: Error #1056 – instance name Error
I’m not using a visual IDE for designing a stage, but MXML and AS3 files, so I’m not sure what to make of this error.
My code:
Object.prototype.keys = function(): Array {
var keys: Array = [];
for (var key: * in this) {
keys.push(key);
}
return keys;
}
Object.prototype.values = function(): Array {
var values: Array = [];
for each (var value: * in this) {
values.push(value);
}
return values;
}
Using
prototypeto extend a class seems very ActionScript 1 or 2.In AS3, you may be able to prototype if the class is dynamic.
There are downsides to prototype:
Since all classes extend object, it is not necessary to explicitly declare
Objectas a base; however, you could define an AbstractObject class to be extended:Subtype
AbstractObjectfor your classes.