startDrag()闪存移动所有父对象而不仅仅是它分配给它的内容

时间:2013-04-14 15:33:25

标签: flash actionscript

所以我对Actionscript相当新,但是我在功能和事件监听器方面做得很好,所以我想知道是否有人可以告诉我修复我的项目发生了什么。

所以我有一个基本的拖放功能,但是当我运行这个代码时它会移动舞台上的所有内容,从所有不同的层和帧中移动,我不希望这种情况发生,我只想要各种对象拖动

answer1_word.addEventListener(MouseEvent.MOUSE_DOWN, answer1_drag)
function answer1_drag(event:MouseEvent):void {
startDrag();
}

answer1_word.addEventListener(MouseEvent.MOUSE_UP, answer1_drop)
function answer1_drop(event:MouseEvent):void {
stopDrag();
}

我想不出代码有什么问题,但我很感激帮助,谢谢你们!

编辑:动作建议

if(answer1_word.hitTestObject(word_select_box)){
trace("Hello");
}

这是我的热门测试对象代码。

1 个答案:

答案 0 :(得分:0)

您正在“根”级容器上调用startDrag()和stopDrag()。那是“舞台”。您需要从要移动的实例中调用startDrag()和stopDrag()。

answer1_word.addEventListener(MouseEvent.MOUSE_DOWN, answer1_drag)
function answer1_drag(event:MouseEvent):void {
 answer1_word.startDrag();
}

answer1_word.addEventListener(MouseEvent.MOUSE_UP, answer1_drop)
function answer1_drop(event:MouseEvent):void {
 answer1_word.stopDrag();
}

老实说,如果你打算拥有多个Draggle对象,我会抽象使用event.target

answer1_word.addEventListener(MouseEvent.MOUSE_DOWN, onDrag)
answer1_word.addEventListener(MouseEvent.MOUSE_UP, onDrop)

function onDrag(event:MouseEvent):void {
 event.target.startDrag();
}


function onDrop(event:MouseEvent):void {
 event.target.stopDrag();
}