开发者

AS3 <Key,Value> Collection

开发者 https://www.devze.com 2023-01-17 19:10 出处:网络
In actionscript object class can act as a collection that stores key,value combinations: var o:Object = new Object(开发者_如何学C);

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

精彩评论

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

关注公众号