actionscript 2到3 mouseX在时间轴上移动

时间:2014-05-08 08:04:20

标签: actionscript-3 flash actionscript actionscript-2

我在Flash中有一个Actionscript 2。我已经用了一些时间来移动鼠标移动的时间轴,我想把它转换成Actionscript 3,试过但是很难挣扎:

var x_mouse = _root._xmouse;
var y_mouse = _root._ymouse;
if ( ( y_mouse >= 0 ) and ( y_mouse <= 400 ) ) {
  if ( ( x_mouse >= 0 ) and ( x_mouse <= 900 ) ) {
    this._parent.gotoAndStop ( Math.round ( x_mouse ) );
  }
  else if ( x_mouse < 0 ) {
    this._parent.gotoAndStop ( 1 );
  }
  else if ( x_mouse > 900 ) {
    this._parent.gotoAndStop ( 900 );
  }
}

也许这对你来说真的很容易? : - )

3 个答案:

答案 0 :(得分:0)

尝试:

在属性面板中,设置实例名称:“instance”。

instance.addEventListener(MouseEvent.CLICK, mouse_handler);
function mouse_handler(event:MouseEvent):void {
   if (instance.mouseX < 0 || instance.mouseX > 900) {
      return;
   }

   instance.gotoAndStop(instance.mouseX);
}

我建议您使用类文件而不是时间轴脚本。

答案 1 :(得分:0)

一些注意事项:

as2是 _parent 。 as3只是

as3中的

_root 不再是文档根目录,它只是代码所在的swf的时间轴或文档类。例如,如果你将swf加载到另一个swf并从中调用_root加载swf,它只引用加载的swf的时间轴或文档类,而不是包含swf的。

as3 stage 中的

通过属性mouseX和MouseY包含鼠标指针位置。

以下是您正在寻找的内容:

var x_mouse = stage.mouseX;
var y_mouse = stage.mouseY;

if( y_mouse >= 0 && y_mouse <= 400 )
{
    if ( x_mouse >= 0 && x_mouse <= 900 )
    {
        this.parent.gotoAndStop( Math.round ( x_mouse ) );
    }
    else if ( x_mouse < 0 )
    {
        this.parent.gotoAndStop( 1 );
    }
    else if ( x_mouse > 900 )
    {
        this.parent.gotoAndStop ( 900 );
    }
}

答案 2 :(得分:0)

这就是我最终的结果,它完美无缺:

stop();
function findFrame(event:Event):void{
var frame:int = Math.floor((stage.mouseX/stage.stageWidth) * 900) + 1;
gotoAndStop(frame);
};
addEventListener("enterFrame",findFrame);