Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Could use some help with movement of Movie Clips

Guest
Jan 26, 2013 Jan 26, 2013

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

TOPICS
ActionScript
614
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 26, 2013 Jan 26, 2013

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

            stage.addEventListener(Event.ENTER_FRAME, moveKa);

   }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2013 Jan 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);

}

                    }

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 27, 2013 Jan 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 ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2013 Jan 27, 2013
LATEST

don't make them local to a function:

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")

                              xSlope = 1

                              ySlope = ((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);

}

                    }

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines