Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-26-2005, 05:33 AM   #1
X1Commander
Registered User
 
Join Date: Nov 2005
Posts: 2
Default [AS2] help in Flash

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.

Last edited by X1Commander; 11-26-2005 at 10:35 PM.
X1Commander is offline   Reply With Quote
Old 11-26-2005, 10:34 PM   #2
X1Commander
Registered User
 
Join Date: Nov 2005
Posts: 2
Default

Anything would be helpful.
X1Commander is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Developing a flash site, Part1: Some thoughts Bloom22 Other Flash General Questions 6 09-29-2006 02:10 AM
Flash Number type and c# float and decimal types. Convertion problem within Flash. maglez ActionScript 2.0 2 06-02-2005 05:14 PM
[Q] Do we need those forums??? CyanBlue General Chat 59 07-27-2004 11:13 AM
Macromedia Central CyanBlue ActionScript 1.0 (and below) 13 08-01-2003 09:05 PM


All times are GMT. The time now is 07:44 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.