Copy link to clipboard
Copied
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void {
var dx:Number = circle_mc1.x - square_mc.x;
var dy:Number = circle_mc1.y - square_mc.y;
var angle:Number = Math.atan2 (dy,dx);
var xVelocity:Number =Math.cos(angle) * speed;
var yVelocity:Number =Math.sin(angle) * speed;
square_mc.x += xVelocity;
square_mc.y += yVelocity;
circle_mc.addEventListener(MouseEvent.MOUSE_UP, Stopd)
}
{
this.square_mc.stop;
}
Getting the error code
1084: Syntax error: expecting rightparen before dot.
for the enlarged line.
You want to use:
this.square_mc.stop();
Copy link to clipboard
Copied
You want to use:
this.square_mc.stop();
Copy link to clipboard
Copied
Ok awesome, thank you.
Didn't quite have the effect I was looking for though. How do I get square_mc to go towards circle_mc until I let go of the mouse click? Right now it just goes part way every time a click wether I hold it or not.
Copy link to clipboard
Copied
You'll have to give me more information. It sounds like you have an action where you want an object to move on the stage while the mouse button is down and then to stop moving when the button is released. Is that correct? Can you share the code that you are using now to make the object move?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now