-1

我正在尝试使用 hitTestObject 和 enter_frame 创建一个“测试”页面,用户将“答案框”拖到另一个框,如果答案正确,它会显示“正确”一词,如果不是“错误”,但我有四个问题(q1)和4个答案(a1),并且在输入第一个答案后,它不会做任何其他事情,除非我将方块移出正确答案。

如何让它工作并忽略以前的响应?我也在使用拖放命令。

-

finalTest.addEventListener(Event.ENTER_FRAME, detectCollision);

function detectCollision (evt: Event) : void {
    if(a1.hitTestObject(q1)) {
        finalTest.checkText.text = "Correct answer";
    }
    else if(a1.hitTestObject(q2)) {
        finalTest.checkText.text = "wrong";
    }
    else if(a1.hitTestObject(q3)) {
        finalTest.checkText.text = "wrong";
    }
    else if(a1.hitTestObject(q4)) {
        finalTest.checkText.text = "wrong";
    }

    else if(a2.hitTestObject(q2)) {
        finalTest.checkText.text = "Correct answer";
    }
    else if(a2.hitTestObject(q1)) {
        finalTest.checkText.text = "wrong";
    }
    else if(a2.hitTestObject(q3)) {
        finalTest.checkText.text = "wrong";
    }
    else if(a2.hitTestObject(q4)) {
        finalTest.checkText.text = "wrong";
    }

    else if(a3.hitTestObject(q3)) {
        finalTest.checkText.text = "Correct answer";
    }
    else if(a3.hitTestObject(q1)) {
        finalTest.checkText.text = "wrong";
    }
    else if(a3.hitTestObject(q2)) {
        finalTest.checkText.text = "wrong";
    }
    else if(a3.hitTestObject(q4)) {
        finalTest.checkText.text = "wrong";
    }

    else if(a4.hitTestObject(q4)) {
        finalTest.checkText.text = "Correct answer";
    }
    else if(a4.hitTestObject(q1)) {
        finalTest.checkText.text = "wrong";
    }
    else if(a4.hitTestObject(q2)) {
        finalTest.checkText.text = "wrong";
    }
    else if(a4.hitTestObject(q3)) {
        finalTest.checkText.text = "wrong";
    }
    else {
        finalTest.checkText.text = " ";
    }
}
4

1 回答 1

0

也许这应该有所帮助:

var questionArray:Array = new Array(q1,q2,q3,q4);
var answerArray:Array = new Array(a1,a2,a3,a4);

var checkId:int = 0;

for(var i:int = 0; i<answerArray.length; i++) {
     answerArray[i].ids = i;
     answerArray[i].addEventListener(MouseEvent.MOUSE_DOWN, onDragHandler);
     answerArray[i].addEventListener(MouseEvent.MOUSE_UP, onReleaseHandler);
}

function onDragHandler(e:MouseEvent) {
     e.currentTarget.startDrag();
     checkId = e.currentTarget.ids;
}

function onReleaseHandler(e:MouseEvent) {
    e.currentTarget.stopDrag();
    if(e.currentTarget.hitTestObject(questionArray[checkId])) {
        finalTest.checkText.text = "Correct Answer";
    } else {
        finalTest.checkText.text = "Wrong";
    }
}

我将问题和答案整理成数组。而且我没用ENTER_FRAME..

于 2012-12-19T05:05:01.727 回答