Skip to main content
Known Participant
April 17, 2017
Answered

Remove Object from Array

  • April 17, 2017
  • 1 reply
  • 1333 views

Hello,

Following Problem:

I want to remove a child from an Array. I removed all refrences, the child and set it =null. I also used weak references where i couldnt remove eventlistener. Anyways the Child is still in the Array.

for(var i = 0;i < fliesArray.length;i++){

  removeChild(fliesArray[1]);

  fliesArray[1] = null;

  TweenMax.killTweensOf(fliesArray[0]);

  removeChild(fliesArray[0]);

  fliesArray[0] = null;

I have this in my "end game" function

also I thought the Arrays in AS3 dynamicly closes the gap if an Object is deletet.

Example: Object with index 25 is deletet, object with index 26 gets index 25, index 27 gets 26 etc. pp.

is that correct?

Thanks!

This topic has been closed for replies.
Correct answer kglad

that array will not 'automatically update'.  use:

for(var i = fliesArray.length-1;i>=0;i--){

  TweenMax.killTweensOf(fliesArray[0]);

  removeChild(fliesArray[1]);

  fliesArray[0] = null;

fliesArray.splice(i,1);

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
April 17, 2017

that array will not 'automatically update'.  use:

for(var i = fliesArray.length-1;i>=0;i--){

  TweenMax.killTweensOf(fliesArray[0]);

  removeChild(fliesArray[1]);

  fliesArray[0] = null;

fliesArray.splice(i,1);

}

Known Participant
April 17, 2017

Thanks kglad, u're the best!

kglad
Community Expert
Community Expert
April 17, 2017

you're welcome.