如何从B类引用A类中的实例

时间:2013-02-02 16:23:55

标签: actionscript-3 flash class instance

我有四个类:文档 topPanel listPanel detailsPanel 。在此特定示例中, topPanel 检查何时 advanceDay 文档中的函数)。当 advanceDay 被激活文档告诉 topPanel calculateDate listPanel sortList detailsPanel refreshDetails calculateDate 然后计算出日期并尝试更新动态文本字段但无法找到它的实例。关于 sortList refreshDetails ,会出现类似的问题。

topPanel:

function advanceLoop(a:Event)
{
    loopCounter +=  simSpeed;
    if ((loopCounter >= 24))
    {
        loopCounter = 0;
        document.advanceDay();
    }
}

public static function calculateDate()
{
    ... // sets moonCounter and yearCounter using day
    date.text = document.prettyNumbers[moonCounter] + " moon of the year " + yearCounter + " B.C.";
}

文件:

public static var prettyNumbers:Array = ["Zeroth","First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth","Eleventh","Twelfth","Thirteenth","Fourteenth"];

...

public static function advanceDay()
{
    topPanel.day++;
    topPanel.calculateDate();           
    listPanel.sortList();
    detailsPanel.refreshDetails();
}

返回错误:

Line 278 1120: Access of undefined property date.

date 是topPanel中实例(动态文本字段)的名称。当 advanceDay 函数位于 topPanel 类中并且“public static”位被删除时, calculateDate 函数可以正常工作。感谢阅读,希望你能帮忙!

1 个答案:

答案 0 :(得分:0)

标记为static的函数只能访问自身静态的属性。我相信'date'不是一个静态成员变量,这就是为什么编译器说它无法找到具有必要'静态'限定符''的''日期'