mx.core.View.destroyChildAt() bugfix
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.
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;
}


July 26th, 2005 at 2:46 pm
Good to know. I incorporated my own versions of the 3 methods Flex' adds to View, and low-and-behold, 1 was failing, and I bet this is the culprit.