我對AS很新,正在玩我發現的掃雷遊戲。對於遊戲板上的每個單元格,我都有一個內嵌動態文本框(number_txt)的影片剪輯(cell_mc),一個純色方塊影片剪輯(block_mc)和一個用於標記轟炸框的小旗子(flag_mc )。我還有一個單獨的動態文本框來計算板上留下的地雷數量(minecounter_txt)。Actionscript 3錯誤代碼1119處理this.parent?
我的問題是當我嘗試運行遊戲時,每一個我有一個「this.parent.flag_mc」或「this.parent」與任何提到的元素,Flash返回一個錯誤代碼 - 「1119 :通過帶有靜態類型單元的引用訪問可能未定義的屬性flag_mc(或其他元素)。「並與minecounter_mc它返回「1119:訪問可能未定義的屬性flag_mc(或其他元素)通過引用與靜態類型flash.display:DisplayObjectContainer」
我認爲,因爲它說,它不能引用元素與靜態類型,它無法將它們識別爲動態。我搜索了一個解決方案,並閱讀它幫助父母,即「影片剪輯(this.parent.flag_mc)之前聲明動態元素,但它並沒有幫助。
誰能幫助?謝謝。
package {
import flash.display.MovieClip;
import flash.display.DisplayObjectContainer;
import flash.events.MouseEvent;
public class cell extends MovieClip {
public var state:Boolean;
public var revealed:Boolean;
public var xcor:uint;
public var ycor:uint;
public var marked:Boolean;
public var cellValue:int;
public function cell(corx:uint, cory:uint) {
// constructor code
this.state = false;
this.revealed = false;
this.marked = false;
this.cellValue = 0;
this.xcor = corx;
this.ycor = cory;
this.flag_mc.visible = false;
this.addEventListener(MouseEvent.CLICK, cellClicked);
}//end of constructor
private function cellClicked(event:MouseEvent):void{
if(event.shiftKey){
if(this.marked){
this.flag_mc.visible = false;
this.marked = false;
this.parent.minecounter_txt.text = String(int(this.parent.parent.minecounter_txt.text) + 1);
} else{
this.flag_mc.visible = true;
this.marked = true;
this.parent.minecounter_txt.text = String(int(this.parent.parent.minecounter_txt.text) - 1);
}
} else{
if(!state){
openCell();
} else{
if(!this.marked){
this.parent.play_btn.visible = true;
}
}
}
}
private function openCell(){
if(!this.marked && !this.revealed){
this.block_mc.visible = false;
this.revealed = true;
this.removeEventListener(MouseEvent.CLICK, cellClicked);
}
}
}//end of class
}//end of package