acstionscript 3循环对象名称迭代对象名称

时间:2014-10-03 11:07:15

标签: actionscript-3 flash loops

我想在一些Sprite对象上创建一个循环。那些对象不在数组中,但我将它们命名为:fixPT1,fixPT2 ... 我尝试了这个,但它不会工作

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;
    }
}

1 个答案:

答案 0 :(得分: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;
    }
}