-1

我已经使用 Actionscipt2.0 完成了拖动和匹配 Flash 的内容,但现在我需要将其更改为 3.0。改了之后,flash就不能再拖东西了,有没有人看一下代码,看我是哪部分转换错了。谢谢。

动作脚本 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();
}
}

动作脚本 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();
}
);
}
4

2 回答 2

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);
于 2013-01-17T09:46:34.820 回答
0

这行不通

    this["content_mc.matching_term_"+i]

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

    this.content_mc["matching_term_"+i]

可能有点帮助。

于 2013-01-17T21:04:50.820 回答