Skip to main content
January 26, 2013
Question

Could use some help with movement of Movie Clips

  • January 26, 2013
  • 2 replies
  • 632 views

package  {

          import flash.display.MovieClip

          import lameGame

          import flash.events.MouseEvent

          import flash.events.Event

          import flash.display.Graphics

          public class heroOne extends lameGame {

                    var kamehamehaGfx:redCircle = new redCircle

                    var lameCircle:redCircle = new redCircle

                    var xSlope:Number

                    var ySlope:Number

                    public function heroOne() {

                              var _heroStrength = 20

                              var _heroSpeed = 2

                              var _heroHealth = 140

                              kamehamehaGfx.x = 30

                              kamehamehaGfx.y = 30

                              stage.addEventListener(MouseEvent.MOUSE_DOWN, kamehameha);

                              if(kamehamehaGfx) {

                                        stage.addEventListener(Event.ENTER_FRAME, moveKa);

                              }

                    }

                    public function kamehameha(evt:MouseEvent) {

                              addChild(kamehamehaGfx)

                              trace("gay")

                              var xSlope:Number = 1

                              var ySlope:Number = ((mouseY - kamehamehaGfx.y)/(mouseX - kamehamehaGfx.x)) ;

                    }

                    public function moveKa(evt:Event) {

                              trace("SuperGay")

                              kamehamehaGfx.x += xSlope;

                              kamehamehaGfx.y += ySlope;

                              trace(kamehamehaGfx.x)

                    }

          }

}

When I click the mouse on the stage, the object spawns but there is no movement

when i trace (kamehamehaGfx.x) I get the value 0 every time

This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
January 26, 2013

use:

TurkeyGuy wrote:

package  {

          import flash.display.MovieClip

          import lameGame

          import flash.events.MouseEvent

          import flash.events.Event

          import flash.display.Graphics

          public class heroOne extends lameGame {

                    var kamehamehaGfx:redCircle = new redCircle

                    var lameCircle:redCircle = new redCircle

                    var xSlope:Number

                    var ySlope:Number

                    public function heroOne() {

                              var _heroStrength = 20

                              var _heroSpeed = 2

                              var _heroHealth = 140

                

                              stage.addEventListener(MouseEvent.MOUSE_DOWN, kamehameha);

                         

                    }

                    public function kamehameha(evt:MouseEvent) {

                                        stage.addEventListener(Event.ENTER_FRAME, moveKa);

        

             kamehamehaGfx.x = 30

                              kamehamehaGfx.y = 30

                              addChild(kamehamehaGfx)

                              trace("gay")

                              var xSlope:Number = 1

                              var ySlope:Number = ((mouseY - kamehamehaGfx.y)/(mouseX - kamehamehaGfx.x)) ;

                    }

                    public function moveKa(evt:Event) {

                              trace("SuperGay")

                              kamehamehaGfx.x += xSlope;

                              kamehamehaGfx.y += ySlope;

                              trace(kamehamehaGfx.x)

if(  kamehamehaGfx.x>stage.stageWidth||  kamehamehaGfx.y>stage.stageHeight){  // adjust this per   kamehamehaGfx's reg point

    stage.removeEventListener(Event.ENTER_FRAME, moveKa);

}

                    }

          }

}

January 27, 2013

Hey guys ! thanks for the feedback so far ! It's been really helpful for a noob like me !

I found the problem the moveKa function won't recognize the xSlope and Yslope Variables... How can i change this ?
Is it because the variables are defined in another function ?

esdebon
Inspiring
January 26, 2013

   if(kamehamehaGfx) {             //<-----------You need a boolean, may be change to  kamehamehaGfx!=null

            stage.addEventListener(Event.ENTER_FRAME, moveKa);

   }