18 Replies Latest reply: Apr 20, 2012 6:30 AM by thunderxlight11111 RSS

    adding and removing child

    thunderxlight11111 Community Member

      hi how are you guys ?i hope you all fine .

       

      iam trying to understand how add and removing child work and i did this  short code

       

       

       

      here how its work

      1-the main stage is empty nothing in it

      2- in the library there is class called (MAINMAP1)  the only class in the project

      3- i did 2 codes in the (MAINMAP1) class ,  the first didn.t  work and the other  work.

      4- iam running from the main stage.

       

      here

      the first code

      package

       

      {

      import flash.system.System;

      import flash.system.fscommand;

       

          import flash.display.MovieClip;

      import flash.media.Sound;

          import flash.media.SoundChannel;

          import flash.events.KeyboardEvent;

       

          import flash.ui.Keyboard;

       

          import flash.events.Event;

       

          import flash.events.MouseEvent;

          import flash.display.Stage;

      public class MAINMAP1 extends MovieClip {

       

       

        public function MAINMAP1(){

          MovieClip(parent).addChild(this);

        }

       

      }

      }

      it doesn.t add any thing in the main stage it still empty

       

      but the other work (when i added instance of the map class to the main stage this code remove it)

       

      package

       

      {

      import flash.system.System;

      import flash.system.fscommand;

       

          import flash.display.MovieClip;

      import flash.media.Sound;

          import flash.media.SoundChannel;

          import flash.events.KeyboardEvent;

       

          import flash.ui.Keyboard;

       

          import flash.events.Event;

       

          import flash.events.MouseEvent;

          import flash.display.Stage;

      public class MAINMAP1 extends MovieClip {

       

       

        public function MAINMAP1(){

           MovieClip(parent).removeChild(this);

        }

       

      }

      }

       

       

      thats all

      i hope you guys can help  me

      thank you