Hello, I'm working on a side scrolling space shooter and I've run into a problem and I'm not sure why. I'm using Flash MX 2004. It's based on the Robotech TV series and while I can get the Veritech fighter to move around, fire and transform when I start the game directly on the game scene, as soon as I add in a title scene that then changes to the game scene, the functions of any key other than the arrow keys seem to change. The transformation buttons all seem to switch position, firing the gun and missile doesn't work, but the movement is fine.
The code on the veritech is this
Code:
onClipEvent(load)
{
// Initialize some properties
var form = 1
trace (form);
}
// on every frame
onClipEvent (enterFrame)
{
// if the left key is pressed
if (Key.isDown(Key.UP))
{
//this.play();
//_xscale = _xscale;
// if the slug has not hit the left side of the track yet
if (_y > 20)
{
if (form == 1)
{
// move the slug to the left by 10 and rotate it to the right
_y = _y - 15;
}
if (form == 2)
{
// move the slug to the left by 10 and rotate it to the right
_y = _y - 20;
}
if (form == 3)
{
// move the slug to the left by 10 and rotate it to the right
_y = _y - 15;
}
}
}
// if the right key is pressed
if (Key.isDown(Key.DOWN))
{
//this.play();
//this.Elf_Legs_mc.gotoAndPlay(1);
//_xscale = -_xscale;
// if the slug has not hit the left side of the track yet
if (_y < 380)
{
// move the slug to the right by 10 and rotate it to the left
if (form == 1)
{
// move the slug to the left by 10 and rotate it to the right
_y = _y + 15;
}
if (form == 2)
{
// move the slug to the left by 10 and rotate it to the right
_y = _y + 20;
}
if (form == 3)
{
// move the slug to the left by 10 and rotate it to the right
_y = _y + 15;
}
}
}
if (Key.isDown(Key.LEFT))
{
//this.play();
//this.Elf_Legs_mc.gotoAndPlay(1);
//_xscale = -_xscale;
// if the slug has not hit the left side of the track yet
if (_x > 60)
{
// move the slug to the right by 10 and rotate it to the left
if (form == 1)
{
// move the slug to the left by 10 and rotate it to the right
_x = _x - 10;
}
if (form == 2)
{
// move the slug to the left by 10 and rotate it to the right
_x = _x - 15;
}
if (form == 3)
{
// move the slug to the left by 10 and rotate it to the right
_x = _x - 20;
}
}
}
if (Key.isDown(Key.RIGHT))
{
//this.play();
//this.Elf_Legs_mc.gotoAndPlay(1);
//_xscale = -_xscale;
// if the slug has not hit the left side of the track yet
if (_x < 200)
{
// move the slug to the right by 10 and rotate it to the left
if (form == 1)
{
// move the slug to the left by 10 and rotate it to the right
_x = _x + 25;
}
if (form == 2)
{
// move the slug to the left by 10 and rotate it to the right
_x = _x + 15;
}
if (form == 3)
{
// move the slug to the left by 10 and rotate it to the right
_x = _x + 20;
}
}
}
if (Key.isDown(Key.SPACE))
{
if (form < 4)
{
_root.beam.status = "fired!";
if (_root.beam._x > 200)
{
_root.beam2.status = "fired!";
}
if (_root.beam2._x > 200)
{
_root.beam3.status = "fired!";
}
}
else if (form == 4)
{
_root.beam.status = "passive";
_root.beam2.status = "passive";
_root.beam3.status = "passive";
}
}
if (Key.isDown(Key.CONTROL))
{
_root.missile.status = "fired!";
}
//fighter key Q
if (Key.isDown(81))
{
if (form == 2)
{
gotoAndPlay(1);
form = 1
_root.xv = 3;
}
else if (form == 3)
{
gotoAndPlay(1);
form = 1
_root.xv = 3;
}
trace (form);
}
//Guardian key W
if (Key.isDown(87))
{
if (form == 1)
{
gotoAndPlay(7);
form = 2
_root.xv = 2;
}
else if (form == 3)
{
gotoAndPlay(3);
form = 2
_root.xv = 2;
}
trace (form);
}
//Battloid key E
if (Key.isDown(69))
{
if (form == 1)
{
gotoAndPlay(5);
form = 3
_root.xv = 1;
}
else if (form == 2)
{
gotoAndPlay(38);
form = 3
_root.xv = 1;
}
trace (form);
}
/*
if (_root.life == 0)
{
gotoAndPlay(120);
form = 4;
_root.xv = 3;
_root.life = 2;
}
*/
}
I've used similar code on a previous game I made, but there was never any trouble with it switching from scene to scene.
And the code on the stage is
Code:
stop();
onLoad = function ()
{
attachMovie("ammo", "beam", 3);
beam.x = 0;
beam.y = 0;
beam.status = "passive";
beam._visible = false;
attachMovie("ammo", "beam2", 4);
beam2.x = 0;
beam2.y = 0;
beam2.status = "passive";
beam2._visible = false;
attachMovie("ammo", "beam3", 5);
beam3.x = 0;
beam3.y = 0;
beam3.status = "passive";
beam3._visible = false;
attachMovie("Missile_mc", "missile", 6);
missile.x = 0;
missile.y = 0;
missile.status = "passive";
missile._visible = false;
xv = 3;
}
onEnterFrame = function ()
{
Score_txt.text = score;
Damage_txt.text = life;
// Compute the ammo
if (beam.status == "passive")
{
if (VT1D_mc.form == 1)
{
beam.x = VT1D_mc._x;
beam.y = VT1D_mc._y-15;
}
if (VT1D_mc.form == 2)
{
beam.x = VT1D_mc._x;
beam.y = VT1D_mc._y-10;
}
if (VT1D_mc.form == 3)
{
beam.x = VT1D_mc._x;
beam.y = VT1D_mc._y-22;
}
beam._visible = false;
}
if (beam.status == "fired!")
{
beam.x += beam._width;
beam._visible = true;
//Gunpod.start(0, 1);
if (beam.x > 550)
{
beam.status = "passive";
}
}
// Compute the ammo
if (beam2.status == "passive")
{
if (VT1D_mc.form == 1)
{
beam2.x = VT1D_mc._x;
beam2.y = VT1D_mc._y-15;
}
if (VT1D_mc.form == 2)
{
beam2.x = VT1D_mc._x;
beam2.y = VT1D_mc._y-10;
}
if (VT1D_mc.form == 3)
{
beam2.x = VT1D_mc._x;
beam2.y = VT1D_mc._y-22;
}
beam2._visible = false;
}
if (beam2.status == "fired!")
{
beam2.x += beam2._width;
beam2._visible = true;
if (beam2.x > 550)
{
beam2.status = "passive";
}
}
// Compute the ammo
if (beam3.status == "passive")
{
if (VT1D_mc.form == 1)
{
beam3.x = VT1D_mc._x;
beam3.y = VT1D_mc._y-15;
}
if (VT1D_mc.form == 2)
{
beam3.x = VT1D_mc._x;
beam3.y = VT1D_mc._y-10;
}
if (VT1D_mc.form == 3)
{
beam3.x = VT1D_mc._x;
beam3.y = VT1D_mc._y-22;
}
beam3._visible = false;
}
if (beam3.status == "fired!")
{
beam3.x += beam3._width;
beam3._visible = true;
if (beam3.x > 550)
{
beam3.status = "passive";
}
}
beam._x = beam.x;
beam._y = beam.y;
beam2._x = beam2.x;
beam2._y = beam2.y;
beam3._x = beam3.x;
beam3._y = beam3.y;
// Compute the ammo
if (missile.status == "passive")
{
if (VT1D_mc.form == 1)
{
missile.x = VT1D_mc._x;
missile.y = VT1D_mc._y-10;
}
if (VT1D_mc.form == 2)
{
missile.x = VT1D_mc._x-20;
missile.y = VT1D_mc._y-25;
}
if (VT1D_mc.form == 3)
{
missile.x = VT1D_mc._x-20;
missile.y = VT1D_mc._y-20;
}
missile._visible = false;
}
if (missile.status == "fired!")
{
missile.x += 20;
missile._visible = true;
if (missile.x > 550)
{
missile.status = "passive";
}
}
missile._x = missile.x;
missile._y = missile.y;
}
The source file is
http://3dmecha.com/Games/Exodus02.fla
If someone could point out what I'm missing here, I'd be very grateful.