开发者

AS3 <Key,Value> Collection

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜