I’ve got a project with a bunch of stuff floating around the screen (enter_frame moves them all around). I instantiate them with one function, and I want to have them removed in a separate function (all timeline code, no .as files). I want them to remove themselves after floating 500 px off screen. Here are the two I’ve tried:
for (var i:int = 0; i < this.numChildren - 1; i++)
{
if ((getChildAt(i).x < -500 ||
getChildAt(i).x > stage.stageWidth + 500 ||
getChildAt(i).y < -500 ||
getChildAt(i).y > stage.stageHeight + 500))
{
removeChildAt(i);
trace(this.numChildren);
}
}
This one works for a percentage of the items. (in same function as instantiation)
function fadeAway(e:Event):void
{
e.target.alpha *= 0.98;
if (same as above [if more than 500 px off screen])
{
e.target.parent.removeChild(e.target);
}
}
I tried both this and e.currentTarget. One threw errors and the other did nothing. Is this the standard way to remove children? If not, what is the “correct” way? Thanks.