我有四个类:文档, 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 函数可以正常工作。感谢阅读,希望你能帮忙!
答案 0 :(得分:0)
标记为static的函数只能访问自身静态的属性。我相信'date'不是一个静态成员变量,这就是为什么编译器说它无法找到具有必要'静态'限定符''的''日期'