2013-02-02 69 views
0

引用類A的實例我有四類:文件topPanellistPaneldetailsPanel。在此特定示例中,topPanel檢查何時advanceDay文檔中的功能)。當advanceDay被激活文件告訴topPanelcalculateDatelistPanelsortlist中detailsPanelrefreshDetailscalculateDate然後計算出日期並嘗試更新動態文本字段,但找不到它的實例。類似的問題發生在sortListrefreshDetails如何從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類中並且「公共靜態」位被刪除時,函數可以很好地工作。感謝閱讀,我希望你能幫助!

+0

從另一個類訪問一個類是一個餿主意。你通常希望在你的主類(在這種情況下爲'document')。 – David

回答

0

標記爲static的函數只能訪問本身爲靜態的屬性。 'date',我相信,不是一個靜態成員變量,這就是爲什麼編譯器說它不能找到一個'日期'必要的'靜態'限定符'

+0

感謝您的支持者 – Ashton

相關問題