Hey everyone,
I'm having some issues with removing the children of a Sprite. Below is my code:
I'm having some issues with removing the children of a Sprite. Below is my code:
private function onTitleClick(e:MouseEvent):void {
var proj:Project = e.currentTarget as Project;
var images:XMLList = proj.images;
_counter = 0;
_thumbCount = images.length();
_bottomContainer.alpha = 0;
clearBottomCont();
for (var i = 0; i < _thumbCount; i++) {
var thumb:ProjectThumb = new ProjectThumb(images[i].@thumb, images[i].@url);
thumb.addEventListener(Event.COMPLETE, thumbLoaded);
}
}
private function thumbLoaded(e:Event):void {
var thumb:ProjectThumb = e.target as ProjectThumb;
thumb.x = (120 + 10) * _counter;
_bottomContainer.addChild(thumb);
_counter++;
if (_counter == _thumbCount) {
trace(_counter); //outputs the right value
trace(_thumbCount); //outputs the right value
trace(_bottomContainer.numChildren); //doesn't always output the right value (it should output the same value as _thumbCount)
_bottomContainer.x = stage.stageWidth;
_bottomContainer.y = stage.stageHeight - 120;
TweenLite.to(_bottomContainer, 0.7, { x: (stage.stageWidth - _bottomContainer.width), alpha:1 } );
}
}
private function clearBottomCont():void {
if (_bottomContainer.numChildren > 0) {
for (var i:uint = 0; i < _bottomContainer.numChildren; i++)
_bottomContainer.removeChildAt(i);
}
}
So what's going on and how can I solve this problem?