Trying to remove multiple of children of a displayObject of type Button
for (var i:int=0; i<numChildren; i++) { if (getChildAt(i) is Button) { removeChild(getChildAt(i)); } } for (var h:int=0; h<numChildren; h++) { if (getChildAt(h) is Button) { trace("???????" } } During gameplay, it traces out "???????", and I'm not quite sure why
When you remove a child, it shifts everything down one layer, so you're actually only removing about half of the children. In your first if statement, add another line that says "i--" which will shift your i back one layer to compensate for the removed child. I believe that should work.
BlueJayy is right, numChildren decrements with every removal. But I would suggest a simpler approach of just iterating backwards:
for(i = numChildren-1;i>=0;i--)
This way, only indexes that have already been checked can shift. (e.g. if you start with numChildren = 7 (indexes 0,1,2,3,4,5,6), and you iterate backwards, finding your first Button at index 4, removing that once will shift index 5 and 6 down, but your next check at index 3 will not have changed.)