ActionScript 2.0到ActionScript 3.0转换:将1个对象拖放到多个目标?

时间:2014-03-23 17:53:14

标签: actionscript-3 flash if-statement actionscript drag-and-drop

我正在开发一种教育游戏,其中包含多项选择题,玩家必须拖放一个选择器"在3个答案面板中的一个上。

这是使用ActionScript 2.0的游戏以前版本的一些代码

Object(_root).selector.origX = Object(_root).selector._x;
Object(_root).selector.origY = Object(_root).selector._y;
Object(_root).selector.onPress = function ()
{
    Object(_root).selector.startDrag();
};
Object(_root).selector.onRelease = function ()
{
    Object(_root).selector.stopDrag();
    if (eval(Object(_root).selector._droptarget) == Object(_root).target1)
    {
        stopAllSounds ();
        gotoAndPlay(1017); //Go to Game Over Screen
        Object(_root).selector._x = Object(_root).target1._x;
        Object(_root).selector._y = Object(_root).target1._y;
    }
    else if (eval(Object(_root).selector._droptarget) == Object(_root).target2)
    {
        stopAllSounds ();
        gotoAndPlay(1017); //Go to Game Over Screen
        Object(_root).selector._x = Object(_root).target2._x;
        Object(_root).selector._y = Object(_root).target2._y;
    }
    else if (eval(Object(_root).selector._droptarget) == Object(_root).target3)
    {
        play (); //Go to Next Question
        Object(_root).selector._x = Object(_root).target3._x;
        Object(_root).selector._y = Object(_root).target3._y;
    }
    else //Return selector back to original position if dropped anywhere outside of targets
    {
        Object(_root).selector._x = Object(_root).selector.origX;
        Object(_root).selector._y = Object(_root).selector.origY;
    }
};

我想知道转换为ActionScript 3.0时此代码的样子。为了使这个代码块能够使用AS 3.0,我必须做出哪些调整?

1 个答案:

答案 0 :(得分:0)

从此页面:http://www.kirupa.com/flash/easy_drag_drop_flash_as3.htm

import flash.events.MouseEvent;

this.addEventListener(MouseEvent.MOUSE_DOWN, startDragging, true);
this.addEventListener(MouseEvent.MOUSE_UP, stopDragging, true);

function startDragging(e:MouseEvent) {
dragger.startDrag();
}

function stopDragging(e:MouseEvent) {
dragger.stopDrag();
}

两个this.addEventListener将更改为selector.addEventListener,您可以将dragger.start / stopDrag()替换为您将从我在下面链接的页面中学到的内容。

然后,您将添加对dropTarget的检测,如下所述:how to use droptarget in AS3?