http://www.razorberry.com/blog/archivespage.php?cat=all&paged=2
Ok, this is an obscure post, but someone somewhere
might be having problems with this method while
extending mx.core.View and happen to google search for
it. :D
I came across this while creating and destroying
objects with createChild() and destroyChildAt(). The
depths seem to get messed up and you end up placing one
object on top of another in certain circumstances,
causing it to vanish.
And so I present a tweaked version. I’ve only tested it
with my application but if for some weird reason you’re
having problems with your views you can try it.
function destroyChildAt(childIndex:Number):Void
{
if (!(childIndex >= 0 && childIndex < numChildren))
return;
var childName:String = childNameBase + childIndex;
var nChildren:Number = numChildren;
destroyObject(childName);
// Shuffle all higher numbered children down
for (var i = childIndex; i < (nChildren - 1); i++)
{
var c = this[childNameBase + i] =
this[childNameBase + (i + 1)];
c.swapDepths(i+depth-nChildren);
}
// Delete the leftover slot
delete this[childNameBase + (nChildren - 1)];
depth-=1;
}