Basically, I have two routines: One is a CDK collision check, and the other is a generic verification of an array. They're both inside the same Timer Event. There are two arrays - the collisionList and the MasterArray, and the object is in both of them.
First, the collision routine:
var collisions:Array = collisionList.checkCollisions();
for(var i:uint = 0; i < collisions.length; i++)
{ var firstShape:Sprite = collisions[i].object1;
if(firstShape.name=="Obj1") {
collisions[i].object1.x = -20;
collisionList.removeItem(collisions[i].object1);
}
}
Then I have:
for each(var i in MasterArray) {
Shape1:Sprite = MasterArray[i];
if (i.x < 0) { removeChild(Shape1); MasterArray.splice(this,1); }
}
But it doesn't work. It gives me a massive crash. If I don't change the object x in the collision routine, the moment it's moved out of the screen by any other function, it disappears and all is well.
However, even if I just touch on it with the collision routine (for example, if I state I want its x at 20), the next time something happens and moves it to x < 0, I get the same crash.
If I don't do anything on the MasterArray check and do a removeChild on the collision check, it works fine too.
This is the error I get in either case:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild() at game2_Scene1_fla::MainTimeline/TimeCheck() at flash.utils::Timer/_timerDispatch() at flash.utils::Timer/tick()
Thanks!