Skip to main content
eliw12510111
Participating Frequently
September 25, 2017
Answered

Action Script Question

  • September 25, 2017
  • 2 replies
  • 543 views

            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)

               

            }

           

            private function Stopd(evt.MouseEvent):void

            {

                this.square_mc.stop;

            }

Getting the error code

1084: Syntax error: expecting rightparen before dot.

for the enlarged line.

This topic has been closed for replies.
Correct answer robdillon

You want to use:

this.square_mc.stop();

2 replies

eliw12510111
Participating Frequently
September 26, 2017

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.

robdillon
Participating Frequently
September 26, 2017

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?

robdillon
robdillonCorrect answer
Participating Frequently
September 25, 2017

You want to use:

this.square_mc.stop();