In actionscript object class can act as a collection that stores key,value combinations:
var o:Object = new Object(开发者_如何学C);
o["a"] = 1;
But when I'm trying to extend it and add some custom functionality:
var mo:MyObject = new MyObject();
mo["a"] = 1;
I get this:
ReferenceError: Error #1056: Cannot create property a on MyObject.
How would I solve this? Thanks.
You need to make the MyObject
class a dynamic class.
package foo.bar {
public dynamic class MyObject {
}
}
A dynamic class supports the Object
behavior of <String,Object>
-- to get the arbitrary <Object,Object>
map, you need to extend Dictionary
instead (again, making the class dynamic).
精彩评论