Be a Supporter!

How to removeChild object in array

  • 286 Views
  • 8 Replies
New Topic Respond to this Topic
stegrd
stegrd
  • Member since: Nov. 5, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
How to removeChild object in array 2012-11-06 04:22:09 Reply

IS there any way to remove a movieclip/object (from an array) from the screen without using removeChild? Thanks!


thanks egg!

stegrd
stegrd
  • Member since: Nov. 5, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to How to removeChild object in array 2012-11-06 04:32:16 Reply

Can someone help me with this bit of code i have?

for(j=0;j<i;j++){
			BA[j].time--;
				
			
				if(BA[j].time<=0){
					BA[j].alpha -= 1;
				
				}
			
			
				if(BA[j].alpha < 0)
				{
					removeChild(BA[j]);
					
				}
}

thanks egg!

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to How to removeChild object in array 2012-11-06 04:47:39 Reply

At 11/6/12 04:22 AM, stegrd wrote: IS there any way to remove a movieclip/object (from an array) from the screen without using removeChild?

No. If something doesn't work, you should not try to find the error in the language.
Most of the time, it's you fault as a programmer that the code is not "working".

You want to ask yourself if something can be more transparent than completely transparent

if(BA[j].alpha < 0)

To do a simple fade, just use a tween engine.
There's one built into As3 (Tween class) which is not as nice as external ones:
http://www.greensock.com/get-started-tweening/

=)

Don't reinvent the wheel.

ScrumTurd
ScrumTurd
  • Member since: Sep. 10, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to How to removeChild object in array 2012-11-06 10:12:05 Reply

At 11/6/12 04:22 AM, stegrd wrote: IS there any way to remove a movieclip/object (from an array) from the screen without using removeChild? Thanks!

Dunno about not using removeChild, if you're having problems removing it from the array and the stage at the same time try this:

private function destroy(ob:DisplayObject):void {

if(ob.stage) {
removeChild(ob);
objectsArray.splice(objectsArray.indexOf(ob), 1);
ob = null;
}
}

Call with: destroy(BA[j]);
Of course that means you would have to break out of your for loop or reset the j index.

ScrumTurd
ScrumTurd
  • Member since: Sep. 10, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to How to removeChild object in array 2012-11-06 10:13:46 Reply

removeChild(ob);

Sorry, that should be ob.parent.removeChild(ob);
It's more flexible.

ScrumTurd
ScrumTurd
  • Member since: Sep. 10, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to How to removeChild object in array 2012-11-06 11:02:06 Reply

if(BA[j].alpha < 0)

Hold on, shouldn't this be if(BA[j].alpha == 0)

Max-Vador
Max-Vador
  • Member since: Nov. 12, 2005
  • Offline.
Forum Stats
Member
Level 13
Animator
Response to How to removeChild object in array 2012-11-06 11:22:28 Reply

At 11/6/12 11:02 AM, ScrumTurd wrote:
if(BA[j].alpha < 0)
Hold on, shouldn't this be if(BA[j].alpha == 0)

yes, if it's checking that the object isn't visible(in terms of alpha) then equality is better than <

but his fade isn't really a fade, since alpha is 0-1, and off the bat it drops it by 1(100%)

if he wants a fade it should be -= 0.1 or whatever increment, if he just wants it to disappear then he can skip the alpha all together and set a function of just destroying the movieclip

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to How to removeChild object in array 2012-11-06 11:41:04 Reply

At 11/6/12 04:22 AM, stegrd wrote: IS there any way to remove a movieclip/object (from an array) from the screen without using removeChild? Thanks!

why in the world would you need to do that? Why can't you just removeChild it?


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
ScrumTurd
ScrumTurd
  • Member since: Sep. 10, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to How to removeChild object in array 2012-11-06 12:19:11 Reply

but his fade isn't really a fade, since alpha is 0-1, and off the bat it drops it by 1(100%)

I thought that as well, I think he's using reference l (L) instead of 1.