Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

A shooting game

New Here ,
Jan 22, 2014 Jan 22, 2014

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

TOPICS
ActionScript
299
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2014 Jan 22, 2014
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines