3

给定以下代码:

import flash.utils.Dictionary;

import mx.collections.ArrayCollection;
import mx.controls.Alert;

public class CDictionary extends Dictionary
{
    public function CDictionary(weakKeys:Boolean=false)
    {
        super(weakKeys);
    }
}

这会引发错误 #1056:

m_cdictNearIDs = new CDictionary();
m_cdictNearIDs[4] = "f";

但这不是:

m_cdictNearIDs = new Dictionary();
m_cdictNearIDs[4] = "f";

(在每种情况下,它都是一个成员变量,它被声明为与它被实例化的类型相同。)Wth?从字典继承的技巧是什么?谢谢!

4

1 回答 1

6

您必须将您的班级定义为dynamic

package
{
    import flash.utils.Dictionary;

    public dynamic class CDictionary extends Dictionary
    {
        public function CDictionary(weakKeys:Boolean=false)
        {
            super(weakKeys);
        }
    }
}
于 2012-11-13T16:49:48.370 回答