Copy link to clipboard
Copied
i'm building a shooting game in which you need to shoot the creatures in order to score how many is possible and win the game.. i saw this code in several websites but i don't understand the "if" condition and why we need "removeChild" and "Splice" both??
The code:
function fl_EnterFrameHandler_5(event:Event):void
{
notequals.start();
//trace(dmutsArray.length);
for (i = 0; i < dmutsArray.length; i++)
{
if (MovieClip(dmutsArray).currentFrame == MovieClip(dmutsArray).totalFrames)
{
var obj:MovieClip = dmutsArray;
trace(MovieClip(obj.parent));
MovieClip(obj.parent).removeChild(obj);
dmutsArray.splice(dmutsArray.indexOf(obj), 1);
misses++;
txtMissed.text = "Missed: " + String(misses) + " / " + String((difficulty == 0) ? 20 : 10);
if ((difficulty == 0 && misses >= 20) || (difficulty == 1 && misses >= 10))
{
notequals.removeEventListener(TimerEvent.TIMER,enterdmuiot);
removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler_5);
gotoAndStop(3);
}
break;
}
}
}
Thx:)
Copy link to clipboard
Copied
removeChild removes the object from the display list. splice removes the object reference from the array (and, if there are no other references etc, allows flash to clear the memory used by the removed object).
Find more inspiration, events, and resources on the new Adobe Community
Explore Now