1

我有六个可拖动的影片剪辑,其中一个实例名称存储在此数组中:

var dragArray1:Array = [drag1, drag2, drag3, drag4, drag5, drag6];

我有一些 5 电影剪辑是上面六个电影剪辑的 hitTestObject 并将该实例名称也存储在此数组中:

var mArray1:Array = [mat1, mat2, mat3, mat4, mat5];

这里有一些变量:

var currentClip1:MovieClip;
var startX1:Number;
var startY1:Number;

这是我为 dragArray1 进行循环拖放的代码:

for(var ia:int = 0; ia < dragArray1.length; ia++) {
    dragArray1[ia].buttonMode = true;
    dragArray1[ia].addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown1);

}

function item_onMouseDown1(event:MouseEvent):void {
    currentClip1 = MovieClip(event.target);
    startX1 = currentClip1.x;
    startY1 = currentClip1.y;
    currentClip1.startDrag()
    addChild(currentClip1)
    stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp1);

}

这是我的“无效代码”。我希望这段代码使dragArray1 hitTestObject mArray1,当dragArray1 hitTestObject mArray1时,dragArray1的x和y等于mArray1,对不起,如果我的英语太糟糕了

这是代码:

function stage_onMouseUp1(event:MouseEvent):void {

    stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp1);
    currentClip1.stopDrag();

    for(var ma:int = 0; ma < mArray1.length; ma++){

        if(currentClip1.hitTestObject(mArray[ma])){
            return;
            trace("hit")
            currentClip1.x=mArray1[ma].x;
            currentClip1.y=mArray1[ma].y;
        }else{
            currentClip1.x=startX1;
            currentClip1.y=startY1;
        }
    }

}

我只希望 dragArray1 中的每个影片剪辑都可以随机地在 mArray1 中的任何影片剪辑中命中测试对象。

4

1 回答 1

0

The issue is the position of your return; statement. Calling it prior the other 3 lines causes them to not execute.

Hence, the fix is simply placing return; to the end:

trace("hit")
currentClip1.x=mArray1[ma].x;
currentClip1.y=mArray1[ma].y;
return;
于 2013-08-15T14:25:06.180 回答