引用類A的實例我有四類:文件,topPanel,listPanel和detailsPanel。在此特定示例中,topPanel檢查何時advanceDay(文檔中的功能)。當advanceDay被激活文件告訴topPanel到calculateDate,listPanel到sortlist中和detailsPanel到refreshDetails。 calculateDate然後計算出日期並嘗試更新動態文本字段,但找不到它的實例。類似的問題發生在sortList和refreshDetails。如何從B類
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.
日期是名topPanel中的一個實例(動態文本字段)。 calculateDate函數在advanceDay函數處於topPanel類中並且「公共靜態」位被刪除時,函數可以很好地工作。感謝閱讀,我希望你能幫助!
從另一個類訪問一個類是一個餿主意。你通常希望在你的主類(在這種情況下爲'document')。 – David