A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Delete Object from Array

  1. #1
    Junior Member
    Join Date
    Dec 2011

    Delete Object from Array

    I have many objects(movieclips) on my stage and I put them in an array

    Actionscript Code:
    for(var i = 0; i<numChildren; i++)
                    if(getChildAt(i) is MC)
    so I can do a hittest on them.

    then when I go to the next level (let's say from level 1 to level 2) there are again multiple objects from the class MC that go into that array. i believe that the objects from level 1 are still in my 'mcarray'. how can i remove just the ones from level 1?

    each time i go to another level the game lags more and more and i really need to fix that.

    thanks for the help!

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Austin, TX
    If you want mcarray to only contain stuff from the new level, you can either remove everything from it:
    while (mcarray.length > 0){
    Or, if you don't need mcarray to point to the same actual array, you can just set it to a new empty array:
    mcarray = [];
    If mcarray contains things you need to keep, then you'll need a way of determining whether to keep or discard an object.
    for (var i:int = mcarray.length-1; i >=0; i--){
      if (shouldDiscard(mcarray[i])){
        mcarray.splice(i, 1);
    where you need to define the shouldDiscard function.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    i'd do it like this:
    delete the whole array and in the next frame put the same code...i've seen it on a tutorial for beginners somewhere. not sure how to explain it though.
    sorry, i can't seem to find it but it was somewehere on here:
    you should take a look at the tutorials
    Last edited by alexAAA; 05-26-2012 at 10:32 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center