Question

I have an Actionscript 2 in Flash. I have used some times for moving in a timeline with mouse movement, I would like to convert it to Actionscript 3, have tried but are struggling:

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 );
  }
}

Maybe it is a real easy task for you? :-)

Was it helpful?

Solution 3

This is what I ended up with, and it works perfect:

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

OTHER TIPS

try:

At property panel, set instance name: "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);
}

I recommend you to use class files than timeline script.

Some considerations:

as2 is _parent. as3 is just parent.

_root in as3 is not the document root anymore, its only the timeline or document class of the swf the code is in. For instance if you load a swf into another swf and call _root from the loaded swf, it only references that loaded swf's timeline or document class, not the containing swf's.

in as3 stage contains the mouse pointer location via the properties mouseX and MouseY.

Below is closer to what you are looking for:

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 );
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top