Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
if(kamehamehaGfx) { //<-----------You need a boolean, may be change to kamehamehaGfx!=null
stage.addEventListener(Event.ENTER_FRAME, moveKa);
}
Copy link to clipboard
Copied
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); |
}
}
}
}
Copy link to clipboard
Copied
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 ?
Copy link to clipboard
Copied
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); }
}
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now