2011-10-15 91 views

回答

1

this.x和this.y從你的跳棋片段對象的範圍起作用;但是,如果您訪問的作品範圍之外,則必須使用作品的實例名稱。雖然不是最佳的,但您可以循環顯示DisplayObject子項。

// create a collection of your checker pieces 
var checkers:Array = []; 

// create a checker piece, whatever your DisplayObject class is. 
var checker:Checker; 
checkers.push(checker); 

// add it to the stage, probably your game board 
addChild(checker);  
checker.x = 100; 
checker.y = 100; 

// loop through the children (from your game board) 
for (var i:uint = 0; i < numChildren; i++) 
{ 
    var checker:DisplayObject = getChildAt(i); 
    trace(checker.x); 
    trace(checker.y); 
} 

使用座標來引用一塊可能不是遊戲的最佳選擇。你可能想考慮一個行/列或從你的遊戲板的工作方式。

如果不清楚,你應該指定一些代碼或者擴展你的問題的更多細節。

+0

所有的跳棋都來自類Checker(從MovieClip擴展而來)和checker.side是可以是「白色」或「黑色」的kind strig的屬性。當它們位於屏幕上時,將創建一個數組來存儲它們的相對位置。因此,跳棋也有_row(從0到7)和_column(從0到7),並且在每次移動之後都會更新數組,以便計算移動是否可行。但是跳棋不在數組中,我應該按照您在示例代碼中所做的操作,通過_row和_column找到它們嗎? – user997213

+0

我遵循你的例子,它的工作原理,我所需要的只是添加數組中的所有檢查器和魔術線「var checker:DisplayObject = getChildAt(0);」一個一個地驗證檢查器是否擁有該屬性並將其刪除。 我修改的例子中,以嘗試的你的拉斯部分: '函數removeChecker(事件:TimerEvent){ 爲(VAR I:UINT = 0; I \t VAR檢查:的DisplayObject = getChildAt(ⅰ);
\t if(checker.x == 200 && checker.y == 200){
\t removeChild(checker);
\t}
}
}'
非常感謝。 – user997213

+0

是的,對不起,我有getChildAt(0) - 你完全正確。謝謝! –

相關問題