回答了我自己的問題:我無法在類中打開任何變量。它們必須在函數中聲明,在這種情況下,初始化(); 。實際定義屬性時出現「未定義屬性訪問」錯誤
我有一個名爲 「壽司」
package {
public class Sushi {
private var cName: String; // This is the name of the sushi.
private var cBio: String; // This is the description of the sushi.
private var cWeight: Number; // This is the weight modifier of the sushi (please keep it between 0.1 and 2.0).
//public var cSprite: MovieClip; // This is the sushi's graphic.
private var cResist: Number; // This is the sushi's resistance modifier.
public function setName(n:String): void {
cName = n;
}
public function setBio(b:String): void {
cBio = b;
}
public function setWeight(w:Number): void {
cWeight = w;
}
public function setResist(r:Number): void {
cResist = r;
}
public function getName(): String {
return cName;
}
public function setCurrentChar(): void {
MainClass.curChar = this;
}
}
}
類......和主類。我的主類創建兩個Sushi對象:test1和test2。
private var test1 = new Sushi();
test1.setName("Test1");
private var test2 = new Sushi();
test2.setName("Test2");
每當我運行它,我得到的錯誤「訪問未定義的屬性test1」和test2相同。我做錯了什麼,我如何從錯誤中學習?