Forum Topic: how the hell do you removeChild()?

(269 views • 24 replies)

This topic is 1 page long.

<< < > >>
None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 04:38 AM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

i dont get it. heres an example of how i added a child
addEventListener(Event.ENTER_FRAME, enterFrame);
addEventListener(Event.ENTER_FRAME,moveB ullet);
addEventListener(MouseEvent.MOUSE_DOWN, shoot);
var bullets:Array = new Array();

function moveBullet(event:Event) {
for (var u:int = bullets.length-1; u>=0; u--) {
removeChild(bullet[u])
}
}

function shoot(event:MouseEvent):void {

var newBullet:Bullet = new Bullet();
newBullet.x=arm.x;
newBullet.y=arm.y;
newBullet.rotation=arm.rotation;
addChild(newBullet);
bullets.push(newBullet);
}

after i delcare the properties of the bullet initially with newBullet, i use bullets[u] to modify it dynamically. i try to remove bullets[u] within the array using removeChild(bullets[u]) and it says

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at game_fla::MainTimeline/moveBullet()

im trying to do the same thing as removeMovieClip in AS2

can you help plz thx

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

UnknownFury

Reply To Post Reply & Quote

Posted at: 7/5/09 05:19 AM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,031

At 7/5/09 04:38 AM, Jereminion wrote: function moveBullet(event:Event) {
for (var u:int = bullets.length-1; u>=0; u--) {
removeChild(bullet[u])
}
}
after i delcare the properties of the bullet initially with newBullet, i use bullets[u] to modify it dynamically. i try to remove bullets[u] within the array using removeChild(bullets[u]) and it says
removeChild(bullet[u])

You're referring to 'bullet' here, but everywhere else you've referred to 'bullets'.

Also once that's done you'll still get an error because you're removing the child yet leaving it in the array so flash is trying to remove it again (seeing as it's on an ENTER_FRAME)

Portfolio(Under construction): UnknownFury.com |
Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com
Follow me on twitter!


Mad as Hell

BloodSucker150

Reply To Post Reply & Quote

Posted at: 7/5/09 05:21 AM

BloodSucker150 LIGHT LEVEL 17

Sign-Up: 03/20/08

Posts: 944

it killes your chileds and make you to dont have kids EVER!!
MOHAHAHAHA

BBS Signature

None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 04:41 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

hello i changed it from removeChild(bullet[u]) to removeChild(bullets[u]) and here is the problem

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/re moveChild()
at zombiegamecs4_fla::MainTimeline/moveBull et()

also i changed the removeChild to be inside of an if statement so it isnt always trying to remove the child, it should only do it once.

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

knugen

Reply To Post Reply & Quote

Posted at: 7/5/09 04:47 PM

knugen LIGHT LEVEL 35

Sign-Up: 02/07/05

Posts: 4,591

When you remove a bullet from the display list you should remove it from the array as well.


None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 04:53 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

sorry i dont know how to do that i am still doing the transition from as2 to as3..this would have been as easy as(for me) as removeMovieClip(after i initially duplicated the original). i didnt even use arrays in as2 for my games..

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Xeptic

Reply To Post Reply & Quote

Posted at: 7/5/09 04:56 PM

Xeptic LIGHT LEVEL 30

Sign-Up: 05/12/05

Posts: 2,162

bullets.splice(u, 1);

should do the job.

BBS Signature

None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 05:02 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

At 7/5/09 04:56 PM, Xeptic wrote: bullets.splice(u, 1);

should do the job.

hello i tried this and got this message

TypeError: Error #1010: A term is undefined and has no properties.
at zombiegamecs4_fla::MainTimeline/moveBull et()

here is the code within the moveBullet() function that i have the splice

for (var i:int=zombies.length-1; i>0; i--) {
if (ground.hitTestPoint(bullets[u].x,bullet s[u].y,true)&&bullets[u].currentFrame==1 ) {
bullets[u].gotoAndStop(2);
bullets.splice(u, 1);
}
}

frame 1 of the bullet is the regular bullet, and frame 2 is a small shatter animation for when it hits. when it hits the ground and isnt on frame 2, it should remove the bullet from the stage( i guess by removing it from the array) only once because of checking the current frame. it does not work for some reason.

im using a for loop to create the actions of all of the dynamic bullets on the stage

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Xeptic

Reply To Post Reply & Quote

Posted at: 7/5/09 05:10 PM

Xeptic LIGHT LEVEL 30

Sign-Up: 05/12/05

Posts: 2,162

At 7/5/09 05:02 PM, Jereminion wrote: for (var i:int=zombies.length-1; i>0; i--) {
if (ground.hitTestPoint(bullets[u].x,bullet s[u].y,true)&&bullets[u].currentFrame==1 ) {
bullets[u].gotoAndStop(2);
bullets.splice(u, 1);
}
}

try:

for (var i:int = bullets.length-1; i>=0; i--) {
   if (ground.hitTestPoint(bullets[i].x, bullets[i].y, true) && bullets[i].currentFrame==1 ) {
      bullets[i].gotoAndStop(2);
      bullets.splice(i, 1);
   }
}

I'm not sure what you're trying to do, but that should work.

BBS Signature

None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 05:16 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

At 7/5/09 05:10 PM, Xeptic wrote:
At 7/5/09 05:02 PM, Jereminion wrote: for (var i:int=zombies.length-1; i>0; i--) {
if (ground.hitTestPoint(bullets[u].x,bullet s[u].y,true)&&bullets[u].currentFrame==1 ) {
bullets[u].gotoAndStop(2);
bullets.splice(u, 1);
}
}
try:

for (var i:int = bullets.length-1; i>=0; i--) {
if (ground.hitTestPoint(bullets[i].x, bullets[i].y, true) && bullets[i].currentFrame==1 ) {
bullets[i].gotoAndStop(2);
bullets.splice(i, 1);
}
}

I'm not sure what you're trying to do, but that should work.

sry for making you waste your time i should have included it before

i have 1 for loop inside of another to test the bullets hitTestPoint with the duplicated zombie arrays

for (var u:int = bullets.length-1; u>=0; u--) {//dynamic bullet loop
for (var i:int=zombies.length-1; i>0; i--) {//dynamic zombies loop
}
}

the bullets associate with u, but i can see how you thought that needed to be corrected.

i tried
bullets.splice(u,1);
bullets.splice(u,u);
bullets.splice([u],[u]);
bullets.splice(u);

still always

TypeError: Error #1010: A term is undefined and has no properties.
at zombiegamecs4_fla::MainTimeline/moveBull et()

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Xeptic

Reply To Post Reply & Quote

Posted at: 7/5/09 05:23 PM

Xeptic LIGHT LEVEL 30

Sign-Up: 05/12/05

Posts: 2,162

I should've noticed that zombies/bullets thing. Can you paste the entire function from start till end? And include it code tags? It's getting hard to read.

BBS Signature

None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 05:27 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

this.stage.addEventListener(KeyboardEven t.KEY_DOWN,down);
this.stage.addEventListener(KeyboardEven t.KEY_UP,up);
addEventListener(Event.ENTER_FRAME, enterFrame);
addEventListener(Event.ENTER_FRAME,moveB ullet);
addEventListener(Event.ENTER_FRAME,moveM olotov);
addEventListener(Event.ENTER_FRAME,shell Bounce);
addEventListener(Event.ENTER_FRAME,moveA rm);
addEventListener(Event.ENTER_FRAME,moveC ursor);
addEventListener(Event.ENTER_FRAME,zombi emovement);
addEventListener(MouseEvent.MOUSE_DOWN, shoot);

var leftdown=0;
var rightdown=0;
var jumpdown=0;
var downdown=0;
var gravity=0;
var jump=0;
var jumping=0;
var shooting=0;
var bulcount=1;
var running=0;
var turnrun=0;
var ballgravity=1;
var ballspeed=0;
var bullets:Array = new Array();
var molotovs:Array = new Array();
var shells:Array = new Array();
var zombies:Array = new Array();
var zombies2:Array = new Array();
var zombiesspawn=5;
var r;//molotov throw x
var throwy;//molotov throw y
var shot=0;
var lookup=0;
var idle=0;
var fallspeed;
var fallspeed1;
var Xd;
var Yd;
var radAngle;
var arm;
var bulletspeed=30;
var weaponselect=1;
var bulletdistance;
var cursordistance;
function zombiemovement(event:Event) {
for (var e:int = zombies.length-1; e>=0; e--) {
zombies[e].zombwalking==0;
zombies[e].zombdistance=player.x-zombies [e].x;
zombies[e].zombspeed=0;
if ((zombies[e].zombdistance>0 || zombies[e].zombdistance<0)) {
if (zombies[e].currentFrame!=2) {
zombies[e].gotoAndStop(2);
}
}
if (! ground.hitTestPoint(zombies[e].x,zombies [e].y-10,true)) {
zombies[e].y+=3;
}
if (ground.hitTestPoint(zombies[e].x,zombie s[e].y-10,true)) {
zombies[e].y-=3;
}
if (zombies[e].hitTestObject(zombies[e])&&z ombies[e].zombdead==0) {
zombies[e].x+=Math.random()*3-Math.rando m()*3;
}
if (zombies[e].zombdistance>0&&zombies[e].z ombdead==0) {
zombies[e].scaleX=-1;
//zombies[e].gotoAndStop(2);
zombies[e].zombspeed=-2*Math.random()*3;
//zombies[e].zombwalking=1;
}
if (zombies[e].zombdistance<0&&zombies[e].z ombdead==0) {
zombies[e].scaleX=1;
//zombies[e].gotoAndStop(2);
zombies[e].zombspeed=2*Math.random()*3;
//zombies[e].zombwalking=1;
}
if (zombies[e].zombhealth<=0) {
zombies[e].zombdead=1;
}
if (zombies[e].zombdead==1) {

zombies[e].rotation=90;
}
zombies[e].x-=zombies[e].zombspeed;
//trace(zombhealth)
}
}
function moveCursor(event:Event) {
if (player.scaleX>0) {
player.head.rotation = (arm.rotation)*.8;
} else if (player.scaleX <0) {
player.head.rotation = (arm.rotation*-1)*.8;
}
Mouse.hide();
cursor.x=mouseX;
cursor.y=mouseY;
}
function moveArm(event:Event) {
if (mouseX>player.x) {
player.scaleX=1;
}
if (mouseX<player.x) {
player.scaleX=-1;
}
arm.scaleX=player.scaleX;
if (player.scaleX>0) {
arm.x=player.x+5;
} else if (player.scaleX <0) {
arm.x=player.x-5;
}
arm.y=player.y-65;
Xd=arm.x-mouseX;
//Get _x distance from gun to mouse
Yd=arm.y-mouseY;
//Get _y distance from gun to mouse
radAngle=Math.atan2(Yd,Xd);
arm.rotation = int((radAngle*360/(2*Math.PI))-90);
}

function moveMolotov(event:Event) {
for (var e:int = molotovs.length-1; e>=0; e--) {
//bullets[u].x+=bullets[u].dx*8;
if (arm.hitTestPoint(molotovs[e].x,molotovs [e].y,true)) {
molotovs[e].visible=false;
} else if (!arm.hitTestPoint(molotovs[e].x,molotov s[e].y,true)) {
molotovs[e].visible=true;
}
molotovs[e].r=30;
if (! ground.hitTestPoint(molotovs[e].x,moloto vs[e].y,true)) {
molotovs[e].x += (10*Math.sin(Math.PI/180*molotovs[e].rot ation));
molotovs[e].y -= (5*Math.cos(Math.PI/180*molotovs[e].rota tion));
molotovs[e].y+=molotovs[e].throwy;
molotovs[e].throwy++;
}

molotovs[e].r-=.3;
//molotovs[e].x+=r
//molotovs[e].rotation+=r;

/*for(var ii:int=enemies.length-1;ii>0=0;ii--){
if(bullets[i].hitTestObject(enemies[ii].
mc)){
//enemyDie(ii)
continue
}
}*/

}
}
function moveBullet(event:Event) {
for (var u:int = bullets.length-1; u>=0; u--) {
//bullets[u].x+=bullets[u].dx*8;
if (arm.hitTestPoint(bullets[u].x,bullets[u ].y,true)) {
bullets[u].visible=false;
} else if (!arm.hitTestPoint(bullets[u].x,bullets[
u].y,true)) {
bullets[u].visible=true;
}
bullets[u].bulletdistance=Math.sqrt(Math .pow((bullets[u].x-player.x),2)+Math.pow ((bullets[u].y-player.y),2));

for (var i:int=zombies.length-1; i>0; i--) {

if (! ground.hitTestPoint(bullets[u].x,bullets [u].y,true)&& ! zombies[i].hitTestPoint(bullets[u].x,bul lets[u].y,true) && (bullets[u].bulletdistance<400)) {

bullets[u].x += (bulletspeed*Math.sin(Math.PI/180*bullet s[u].rotation));
bullets[u].y -= (bulletspeed*Math.cos(Math.PI/180*bullet s[u].rotation));

//removeChild(bullets[u]);

}
if (ground.hitTestPoint(bullets[u].x,bullet s[u].y,true)&&bullets[u].currentFrame==1 ) {
bullets[u].gotoAndStop(2);
bullets.splice(u,u);
trace(bullets)

}
if (zombies[i].hitTestPoint(bullets[u].x,bu llets[u].y,true)&&bullets[u].currentFram e==1) {
bullets[u].gotoAndStop(3);
//bullets.splice(u, 1);
zombies[i].zombhealth--
;
}
}

/*for(var ii:int=enemies.length-1;ii>0;ii--){
if(bullets[i].hitTestObject(enemies[ii].
mc)){
//enemyDie(ii)
continue
}
}*/

}
}
function shoot(event:MouseEvent):void {
if (weaponselect==1) {
if (shot==0) {
idle=0;
shooting=1;
if (arm.currentFrame==2) {
arm.shoot.gotoAndPlay(1);
} else {
arm.gotoAndStop(2);
}
var newBullet:Bullet = new Bullet();
newBullet.x=arm.x;
newBullet.y=arm.y;
newBullet.rotation=arm.rotation;
addChild(newBullet);
bullets.push(newBullet);
shot=1;
//
var newShell:Shell = new Shell();//calling Shell movie clip

newShell.x = arm.x+(40*Math.sin(Math.PI/180*arm.rotat ion));
//Move to gun _x
newShell.y = arm.y+((30*Math.cos(Math.PI/180*arm.rota tion))*-1);
newShell.rotation=arm.rotation+90;
addChild(newShell);
shells.push(newShell);
newShell.time1=70;

newShell.bulletdistance = Math.sqrt(Math.pow((newShell.x-player.x)
,2)+Math.pow((newShell.y-player.y),2));

newShell.fallspeed=-10;
newShell.fallspeed1=player.scaleX*.01;

}
} else if (weaponselect==2) {//molotov
if (shot==0) {
idle=0;
shooting=1;
if (arm.currentFrame==2) {
arm.armthrow.gotoAndPlay(1);
} else {
arm.gotoAndStop(4);
}
//arm.gotoAndStop(4);
var newMolotov:Molotov = new Molotov();
newMolotov.x=arm.x;
newMolotov.y=arm.y;
newMolotov.rotation=arm.rotation;
addChild(newMolotov);
molotovs.push(newMolotov);

//
newMolotov.throwy=-10;
newMolotov.r=1;
shot=1;
}
}
}
function shellBounce(event:Event) {

for (var u:int = shells.length-1; u>=0; u--) {

if (ground.hitTestPoint(shells[u].x,shells[
u].y,true)) {
shells[u].fallspeed*=-1;
shells[u].fallspeed*=.6;
shells[u].fallspeed1=0;
}
shells[u].y+=shells[u].fallspeed;
shells[u].fallspeed++;
shells[u].x+=shells[u].fallspeed1;

if (shells[u].fallspeed1>0) {
shells[u].fallspeed1+=.1;
} else if (shells[u].fallspeed1<0) {
shells[u].fallspeed1-=.1;
}
shells[u].time1--;
if (shells[u].time1<0) {

shells[u].alpha=0;
}

shells[u].rotation+=shells[u].fallspeed1 ;

}
}
function enterFrame(a) {
if (zombiesspawn>0) {
var newZombie:Zombie = new Zombie();
var zombdead=0;
newZombie.x=player.x+10+Math.random()*10 ;
newZombie.y=player.y;
//newZombie.rotation=arm.rotation;
addChild(newZombie);
zombies.push(newZombie);
newZombie.zombdead=0;
newZombie.zombhealth=3;
var zombspeed;
var zombdistance;
var zombwalking=0;
var zombwalk=0;
var zombhealth=3;
newZombie.zombiedistance=player.x-newZom bie.x;
zombiesspawn--;
}
cursordistance = Math.sqrt(Math.pow((cursor.x-player.x),2 )+Math.pow((cursor.y-player.y),2));

/*scaleX = 1+cursordistance*-.001

if(scaleX<.6){
scaleX = .6
}
scaleY = scaleX*/

//x += ((((player.x+x)*-1)+600/2)/2)
if (cursor.x>player.x) {
x += (((player.x-300+(cursordistance)/5)*-1)-
x)/6;
} else if (cursor.x<player.x) {
x += (((player.x-300-(cursordistance)/5)*-1)-
x)/6
;
}
//y += (((player.y-40+y)*-1)+400/2)/5;
if (cursor.y>player.y) {
y += (((player.y-200+(cursordistance)/5)*-1)-
y)/6;
} else if (cursor.y<player.y) {
y

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 05:32 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

thats not all of it but thats all i could fix and i think that is all you need for my problem. i tried to change the alpha to 0 instead of removing child but that makes the game lag even though it isnt visible. maybe i could try moving its y value really far away instead...i dont know i might have to if i cant figure out this array problem

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 05:44 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

ok i think i may have fixed the problem

some reason this works NOW

removeChild(bullets[u])

i think it is because im only doing it once. this is a relief. now i have a new question 8-)

i want to have my movie clips to play a clip BEFORE they removeChild. that means im going to have to put the code within the movie clip where the animation in(could be 2-3 layers within the movie clip) i just do parent.parent.parent.removeChild(bullets [u])?

or i could just check the current frame of all dynamic movie clips and do a currentFrame test, and if that is true, just removeChild once.

sweet

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 06:52 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

now that i removed the item with removeChild()...it still has a lag issue because of it still being in the array. i dont know how to get it to work correctly it just keep saying

TypeError: Error #1010: A term is undefined and has no properties.
at zombiegamecs4_fla::MainTimeline/shellBou nce()

when i use bullets.splice{u,1)

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 07:07 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

well i guess its impossible to solve my problem does anyone have an as3 example of shooting bullets and removing bullets from the stage and array? or is there a way to just make it so that error doesnt show up? it works how it should but that error just keeps coming up

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 08:11 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

when i trace my array

trace(bullets)

it just says

[object Bullet]

is that a problem

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 08:33 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

should i even use for loops for dynamic variables of duplicates or while loops?

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/5/09 10:28 PM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

any help or tutorials?

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

MrCrinkle

Reply To Post Reply & Quote

Posted at: 7/5/09 11:22 PM

MrCrinkle EVIL LEVEL 10

Sign-Up: 01/26/04

Posts: 340

I can't help you with that specific problem, but I can give you a few tips that might help. First, since you're using AS3 you should learn how to use objects; it makes your code a lot more organized and easier to read. Second, you should only use enter frame event listener. This will make you code faster and again, easier to understand.

Theres probably some tutorials that will help you at AS3: main

Oh, please use code tags.

Good luck!

If you are reading this then you must be really bored.

BBS Signature

None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/6/09 12:04 AM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

At 7/5/09 11:22 PM, MrCrinkle wrote: I can't help you with that specific problem, but I can give you a few tips that might help. First, since you're using AS3 you should learn how to use objects; it makes your code a lot more organized and easier to read. Second, you should only use enter frame event listener. This will make you code faster and again, easier to understand.

Theres probably some tutorials that will help you at AS3: main

Oh, please use code tags.

Good luck!

you mean instead of having a listener for all the functions, i should only use 1? i dont mind with the organization for now this is only 500 lines and easy enough for me to navigate with the auto format

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/6/09 07:35 AM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

still need help or example

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

Jereminion

Reply To Post Reply & Quote

Posted at: 7/6/09 09:01 AM

Jereminion NEUTRAL LEVEL 07

Sign-Up: 11/06/05

Posts: 1,147

thanks to xeptic i no longer have problems with the array. i was referencing the object even though it was removed from the array so flash had trouble identifying what i was referring to in the function.

thanks to all who replied before me for helping with my remove child problem

before:
horrible lag and error messages

now:
smooth game and no errors!!

here is the game so far

http://spamtheweb.com/ul/upload/060709/3 2418_zombiegamecs4-3.php

controls:
A-left
D-right
E-jump
mouse-aim
left click-shoot

notice how smooth it is considering all the bullets, shells, enemies, huge mcs in the foreground

Kill zombies http://www.newgrounds.com/portal/vi ew/503827
Manage a smoke shop. http://www.newgrounds.com/portal/vi ew/507244
Want to help with a flash game? visit my blog.


None

WhoknowsmeaUdiO

Reply To Post Reply & Quote

Posted at: 7/6/09 09:41 AM

WhoknowsmeaUdiO DARK LEVEL 13

Sign-Up: 04/11/07

Posts: 1,170

Try

abortion();
I'm so sorry, it had to be said.

In case you haven't noticed yet, this isn't my main anymore. PM me here.

BBS Signature

None

MrCrinkle

Reply To Post Reply & Quote

Posted at: 7/6/09 11:56 AM

MrCrinkle EVIL LEVEL 10

Sign-Up: 01/26/04

Posts: 340

At 7/6/09 12:04 AM, Jereminion wrote:
you mean instead of having a listener for all the functions, i should only use 1? i dont mind with the organization for now this is only 500 lines and easy enough for me to navigate with the auto format

I mean instead of this:

addEventListener(Event.ENTER_FRAME, enterFrame);
addEventListener(Event.ENTER_FRAME,moveB ullet);
addEventListener(Event.ENTER_FRAME,moveM olotov);
addEventListener(Event.ENTER_FRAME,shell Bounce);
addEventListener(Event.ENTER_FRAME,moveA rm);
addEventListener(Event.ENTER_FRAME,moveC ursor);
addEventListener(Event.ENTER_FRAME,zombi emovement);

you should have this:

addEventListener(Event.ENTER_FRAME, enterFrame);

function enterFrame(event:Event)
{
     moveBullet();
     moveMolotov();
     shellBounce();
     etc.
}

It will make it easier and faster, and you can also pass parameters to those functions since you can't if you call them from an event listener.

If you are reading this then you must be really bored.

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 07:02 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!