A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: as3 depth question?

  1. #1
    Zombie Coder EvilKris's Avatar
    Join Date
    Jun 2006
    Location
    Fukuoka, Japan.
    Posts
    796

    as3 depth question?

    before with as2 it was possible to put mc's at the same depth on every instantiation, and at times that was quite a convenient way to destroy previous mc's at the same depth, kind of acting like a handy garbage collector in a way.
    However with the new indexing as3 methods I can't seem to get the same effect, even with addChildat() and putting the same depth.
    Are there any cheeky ways to do it or will I have to look elsewhere?

  2. #2
    Senior Member
    Join Date
    Jan 2006
    Location
    USA
    Posts
    383
    If you don't have a reference, I'm guessing that if you remove it from the display list.. since it will have nothing pointing to it, it will be garbage collected.
    Code:
    displayObjectContainer.addChildAt(yournewmc, index);
    displayObjectContainer.removeChildAt(index+1);
    or
    Code:
    displayobjectContainer.removeChildAt(index);
    displayObjectContainer.addChildAt(yournewmc, index);
    If you have a reference to the mc you want to delete but not the index, here's something you can do. You have to null the variable once you're done in any case if you want it garbage collected:
    Code:
    displayObjectContainer.addChildAt(yournewmc, displayObjectContainer.getChildIndex(yourmc));
    
    displayObjectContainer.removeChild(yourmc);
    yourmc = null;

  3. #3
    Zombie Coder EvilKris's Avatar
    Join Date
    Jun 2006
    Location
    Fukuoka, Japan.
    Posts
    796
    Thanks but it's still mostly throwing out errors.

    displayObjectContainer.addChildAt(yournewmc, index);
    displayObjectContainer.removeChildAt(index+1);

    Simply doesn't work if there's a null value at index+1. I tried doing checks such as

    if (yournewmc.getChildAt(index+1) != null)

    but it doesn't work for some reason. As3 is too inscrutable to simply skip over null values.

    I thought if I just do something like

    removeChild(yournewmc);
    before even declaring the yournewmc sprite it might magically delete the previous instantation but again no cigar.

    Seriously annoying problem this. All I want is Flash to draw me some lines every frame, deleting the previously drawn lines so as to not begin grinding to a halt after a few seconds. So a task easily performed in AS2 is giving me headaches for two nights.

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