Skip to main content
Participant
January 22, 2014
Question

A shooting game

  • January 22, 2014
  • 1 reply
  • 304 views

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:)

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
January 22, 2014

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).