拖东西,Actionscript 2.0到3.0

时间:2013-01-17 09:21:52

标签: actionscript-3 actionscript actionscript-2

我使用Actionscipt2.0完成了拖动和匹配Flash的内容,但现在我需要将其更改为3.0。在我更改之后,闪存无法再拖动这些东西,任何人都可以看看代码,看看我错误地转换了哪个部分。感谢。

Actionscript 2.0版本:

stop();
var randomPositionFrame = int(Math.random()*9)+1;
content_mc.gotoAndStop(randomPositionFrame);
for(var i=1; i<=5; i++){
eval("content_mc.matching_term_"+i)._alpha = 0;
eval("content_mc.matching_term_"+i).onPress = function(){
    if(this._currentframe == 1){
        this.startDrag();
    }
}
eval("content_mc.matching_term_"+i).onRelease = onMouseUp = function(){
    this.stopDrag();
}

eval("content_mc.matching_desc_"+i)._alpha = 0;
eval("content_mc.matching_desc_"+i).onPress = function(){
    if(this._currentframe == 1){
        this.startDrag();
    }
}
eval("content_mc.matching_desc_"+i).onRelease = onMouseUp = function(){
    this.stopDrag();
}
}

Actionscript 3.0版本:

stop();
var randomPositionFrame = int(Math.random()*9)+1;
content_mc.gotoAndStop(randomPositionFrame);
for(var i=1; i<=5; i++){
this["content_mc.matching_term_"+i]._alpha = 0;
 this["content_mc.matching_term_"+i].addEventListener(MouseEvent.MOUSE_DOWN,function():void     {
if(this._currentframe == 1){
        this.startDrag();
    }
}
);

    this["content_mc.matching_term_"+i].addEventListener(MouseEvent.MOUSE_UP,function():void {
stage.addEventListener(MouseEvent.MOUSE_UP, doMouseUp, false, 0, true);

function doMouseUp($evt:MouseEvent):void
{
this.stopDrag();
}
}
);


this["content_mc.matching_desc_"+i]._alpha = 0;
    this["content_mc.matching_term_"+i].addEventListener(MouseEvent.MOUSE_DOWN,function():void     {
    if(this._currentframe == 1){
        this.startDrag();
    }
}
);

this["content_mc.matching_desc_"+i].addEventListener(MouseEvent.MOUSE_UP,function():void {
this.stopDrag();
}
);
}

2 个答案:

答案 0 :(得分:0)

在鼠标侦听器中,您必须从事件中获取目标/对象。表示您应用侦听器的目标。

创建两个侦听器函数并将它们应用于addEventListener调用:

function mouseDownHandler(e:MouseEvent):void
{
    var object = e.target;
    object.startDrag();
}

function mouseUpHandler(e:MouseEvent):void
{
    var obj = e.target;
    obj.stopDrag();
}

像这样使用addEventListener:

yourObj.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
yourObj.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

答案 1 :(得分:0)

这不起作用

    this["content_mc.matching_term_"+i]

您需要分别与每个对象交谈。首先this然后content_mc

    this.content_mc["matching_term_"+i]

可能会帮助一点。