2014-10-03 126 views
0

我想在一些Sprite對象上創建一個循環。這些對象不是一個數組,但是我將它們命名爲這樣的:fixPT1,fixPT2 ... 我試過,但它不會工作acstionscript 3循環對象名稱迭代對象名稱

function stopAll(e:MouseEvent):void { 
    var num:Number = 1; 
    if (dragPT1.x == destPt1.x && dragPT1.y == destPt1.y) { 
     stage.removeEventListener(MouseEvent.MOUSE_MOVE, pointMove); 
    } else { 
     dragPT1.x = fixPt1.x; 
     dragPT1.y = fixPt1.y; 
    } 
} 
+3

如果.NAME屬性設置喲應該能夠使用數組訪問表示法:this [「fixPt」+ num]'或使用[getChildByName()](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html #getChildByName()) – 2014-10-03 11:19:08

回答

0
totalNumberOfSpriteObjects = 3; // or however many there are 
for(var i:int = 0; i < totalNumberOfSpriteObjects; i++) 
{ 
    var fixPoint = this[ 'fixPt' + (i+1) ]; 
    var dragPoint = this[ 'dragPT' + (i+1) ]; 
    var destPoint = this[ 'destPt' + (i+1) ]; 

    if (dragPoint.x == destPt.x && dragPoint.y == destPt.y) 
    { 
     stage.removeEventListener(MouseEvent.MOUSE_MOVE, pointMove); 
    } 
    else 
    { 
     dragPoint.x = fixPoint.x; 
     dragPoint.y = fixPoint.y; 
    } 
}