# Trouble passing function parameters: Shooting Game 85% done

**URL:** <https://forum.kirupa.com/t/trouble-passing-function-parameters-shooting-game-85-done/301041>\
**Category:** flash\
**Created:** [December 2, 2009, 7:36pm UTC](https://forum.kirupa.com/t/trouble-passing-function-parameters-shooting-game-85-done/301041 "2009-12-02T19:36:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![karkaim](https://avatars.discourse-cdn.com/v4/letter/k/f17d59/32.png) [@karkaim](https://forum.kirupa.com/u/karkaim)\
**Post date:** [December 2, 2009, 7:36pm UTC](https://forum.kirupa.com/t/trouble-passing-function-parameters-shooting-game-85-done/301041/1 "2009-12-02T19:36:39Z")

</div>

Hi everyone. I have benn programming in AS2 for a while, but **I’m moving to AS3** , and I’m having some trouble with syntax and mostly with **management of parameters and variables** (actually I tried to work with functions in packages without good results T.T).

The game has four different types of shooters, and all of them use the same bullet (shoot function). I have succeeded on disappearing the target (a coin in this case) when it is hit by the bullet, but the problem is that I can’t quite find the way to **dissapear the bullet**  **properly**. I keep receiving this message:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.  
at flash.display::DisplayObjectContainer/removeChild()  
at eco\_adm9\_fla::MainTimeline/moveBullet()

Here’s the code, I hope you find it useful in a way.  
PS Help would rrrreallly be appreciated! Thank you 😉

var second\_u:int=0;  
var second\_d:int=0;  
var i:int=0;  
var car:int=0;  
var shootAllow:Boolean=true;  
var timer1:Timer=new Timer(1000);  
var timer\_gun:Timer=new Timer(800);  
var Bullet= new shoot\_ball\_mc();  
var Shooter= new shooter1\_mc();//First time Shooter  
Shooter.x=mouseX;  
Shooter.y=350;  
addChild(Shooter);

// Checks the clock function every 1000 milisecond (1 second)  
timer1.start();  
timer\_gun.start();  
timer1.addEventListener(TimerEvent.TIMER, clock1);  
timer\_gun.addEventListener(TimerEvent.TIMER, shooter\_clock);  
timer1.addEventListener(TimerEvent.TIMER, DisplayCoins);  
stage.addEventListener(MouseEvent.MOUSE\_MOVE, mousemove);  
stage.addEventListener(KeyboardEvent.KEY\_DOWN, change\_shooter);  
stage.addEventListener(KeyboardEvent.KEY\_DOWN, shoot);

function shooter\_clock(e:TimerEvent):void {  
shootAllow=true;  
}  
// Function that increments the timer  
function clock1(evt:TimerEvent):void {  
// every time this function is checked increment second by one  
second\_u+=1;  
if (second\_u==10) {  
second\_u=0;  
second\_d+=1;  
}  
timer\_txt.text=“00:”+second\_d+second\_u+“s”;  
}

function mousemove(e:MouseEvent):void {  
Shooter.x=mouseX;  
Shooter.y=350;  
}  
// for the different shooters  
function change\_shooter(e:KeyboardEvent):void {  
switch (e.keyCode) {  
case 65 :  
removeChild(Shooter);  
Shooter = new shooter1\_mc();  
addChild(Shooter);  
Shooter.x=mouseX;  
Shooter.y=350;  
break;  
case 83 :  
removeChild(Shooter);  
Shooter = new shooter2\_mc();  
Shooter.x=mouseX;  
Shooter.y=350;  
addChild(Shooter);  
break;  
case 68 :  
removeChild(Shooter);  
Shooter = new shooter3\_mc();  
Shooter.x=mouseX;  
Shooter.y=350;  
addChild(Shooter);  
break;  
case 70 :  
removeChild(Shooter);  
Shooter = new shooter4\_mc();  
Shooter.x=mouseX;  
Shooter.y=350;  
addChild(Shooter);  
break;  
}  
}

//======= creating bullets =================

function shoot(e:KeyboardEvent):void {  
if (e.keyCode==Keyboard.SPACE && shootAllow==true) {  
shootAllow=false;  
Bullet.x=Shooter.x;  
Bullet.y=Shooter.y;  
addChild(Bullet);  
Bullet.addEventListener(Event.ENTER\_FRAME, moveBullet);  
}  
}

function moveBullet(e:Event):void {  
trace(DisplayCoins);  
e.target.y-=18;  
if (e.target.y\<=-10) {  
e.target.removeEventListener(Event.ENTER\_FRAME, moveBullet);  
removeChild(MovieClip(e.target));  
}  
}

//==================================

//to create the coins  
function DisplayCoins(e:Event) {  
var newCoin= new coin\_mc();  
newCoin.x=50;  
newCoin.y=100;  
addChild(newCoin);  
newCoin.addEventListener(Event.ENTER\_FRAME, Coins\_move);  
newCoin.removeEventListener(Event.ENTER\_FRAME, shoot);

}

function Coins\_move(e:Event):void {  
e.target.x+=3;  
if (e.target.x\>=400 || e.target.hitTestObject(Bullet)) {  
e.target.removeEventListener(Event.ENTER\_FRAME, Coins\_move);  
removeChild(MovieClip(e.target));  
removeChild(MovieClip(Bullet));  
}  
}
