We are making a simple Flash game intended for mobile phones via Flash 5.5 using ActionScript 3.0. We are animating an array of objects vertically until they hit another object at the top of the stage. We instantiate each element of the array with one of 10 MovieClip animations. Each object has two event listeners; one to animate vertically and another to listen for a mouse click(which removes the object from the stage). We run into an issue when more than 10 objects are on the stage at one time. The issue is that the objects disappear sporadically and without explanation. We assume the problem is due to some type of memory/ garbage collection issue. Below is a snippit of our code that dispatches the MovieClip instances onto the stage.
function dispatch(e:TimerEvent):void{
if(count < srrayFinal.length)
{
addChild(sArrayFinal[count]);
sArrayFinal[count].x = randomNumberXtart();
sArrayFinal[count].addEventListener(Event.ENTER_FRAME, fl_AnimateVertically, false, 0, true);
sArrayFinal[count].addEventListener(MouseEvent.CLICK, taphandler, false, 0, true);
sArrayFinal[count].y = 480;
count++;
}
else
{
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, dispatch);
timer = null;
}
}
What can we do in order for the MovieClips to not disappear? Thanks!!!!
DisplayObject
on the visual tree (viaaddChild
) there's no way it gets collected. – dain