PDA

View Full Version : [AS3] Game-breaking problem.


mmankt
07-09-2009, 06:07 PM
Hello dear friends. You've helped me once and so i turn to you again :)
I have a problem that is basically letting the player to cheat. I have a weapon with 3 firing modes, each mode is for different enemy. I want the player only be able to use one mode at once, and now u can press all arrows at once and destroy everything. I've been trying with many solutions but i either get errors(ArgumentError: Error #2025:) or funny stuff on the screen(like one of the graphics freezing in space).
Here's my code, maybe u'll see something.

//(...)
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyD ownFunction);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpF unction);
//(...)
// key pressed
function keyDownFunction(event:KeyboardEvent) {
if (event.keyCode == 37) {
shoot_black = true;
fireTimerB.start();
fireB(null);
}
else if (event.keyCode == 39) {
shoot_white = true;
fireTimerW.start();
fireW(null);
}
else if (event.keyCode == 40 ){
shoot_grey = true;
fireTimerG.start();
fireG(null);
}
else if (event.keyCode == 32 ){
shoot_bonus = true;
use_bonus();
}
}
// key lifted
function keyUpFunction(event:KeyboardEvent) {
if (event.keyCode == 37) {
shoot_black = false;
removeChild(Blackshot);
fireTimerB.stop();
}
else if (event.keyCode == 39) {
shoot_white = false;
removeChild(Whiteshot);
fireTimerW.stop();
}
else if (event.keyCode == 40) {
shoot_grey = false;
removeChild(Greyshot);
fireTimerG.stop();
}
// firing:
function fireB(event:TimerEvent) {
if (shoot_black == true ) {
//(...)
}
function fireW(event:TimerEvent){
if (shoot_white == true) {
//(...)
}
function fireG(event:TimerEvent){
if (shoot_grey == true) {
//(...)
}

I just don't have any idea how to do this right, please help!

rrh
07-09-2009, 07:38 PM
I had to google error 2025, it's "The supplied DisplayObject must be a child of the caller."
Which would be triggered by one of your removeChild() calls because you are trying to remove something that has already been removed or was never added.

You've got the three different fireTimers. My first thought would be if you start one timer, you stop the other two.