Flash CS4 using AS2: bullet issues
alright so i have two classes, character (instance name "man") and bullet (instance name "Bullet+_root.getNextHighestDepth") and what happens is if the player turns before his bullet is off the screen, the bullet changes direction as well. I know WHY this happens, i just don't know how i could solve it. My basic idea is to set a variable equal to the scale upon creation of the bullet, but i have no idea how i would do that. Here are my scripts for the character and bullet classes respectively
Code:
class character extends MovieClip
{
var jump
var gun
var shooter
function onLoad()
{
jump = 0
gun = 0
shooter = 0
}
function onEnterFrame()
{
shooter += 1
if(Key.isDown(Key.RIGHT)){_x += 5; _xscale = 100}
if(Key.isDown(Key.LEFT)){_x -= 5; _xscale = -100}
if(Key.isDown(Key.UP) && jump < 10){_y -= 20; jump += 1}
if(this.hitTest(_root.wall0) || this.hitTest(_root.wall1)){_y+= 0; jump = 0} else {_y +=10}
if(this.hitTest(_root.gun1)){gun = 2; _root.gun1._alpha =0}
if(Key.isDown(Key.SPACE) && shooter > 5 && gun > 1)
{
shooter = 0
var shot = _root.attachMovie("Bullet","Bullet"+_root.getNextHighestDepth(),_root.getNextHighestDepth())
shot._x = _x
shot._y = _y
}
}
}
Code:
class bullet extends MovieClip
{
var dir
function onEnterFrame()
{
if(_root.man._xscale > 0){dir = 1}
if(_root.man._xscale < 0){dir = -1}
if(dir > 0){_x += 10}
if(dir < 0){_x -= 10}
if(_x < -50){this.removeMovieClip()}
if(_x > 700){this.removeMovieClip()}
}
}