addChild merely adds an object to the top of the DisplayList.  Every frame, 
the Flash Player renders objects in the display list; it loops through the 
list from bottom to top, and renders each in turn to the screen.  So, those 
higher are rendered above those in lower.

All you are doing is putting the child to the top of the list again; you 
won't see anything change, nor will any errors be thrown, if it is the only 
one in the list.  However...

This, shows how a blue box is drawn on top of a black one; think about it 
like the blue box being in depth 1, and the black box in depth 0.

package
{
 import flash.display.MovieClip;

 public class MooGoo extends MovieClip
 {
  public function MooGoo()
  {
   var a:MovieClip = new MovieClip();
   a.graphics.beginFill(0x000000);
   a.graphics.lineTo(300, 0);
   a.graphics.lineTo(300, 300);
   a.graphics.lineTo(0, 300);
   a.graphics.lineTo(0, 0);
   a.graphics.endFill();

   var b:MovieClip = new MovieClip();
   b.graphics.beginFill(0x0000FF);
   b.graphics.lineTo(100, 0);
   b.graphics.lineTo(100, 100);
   b.graphics.lineTo(0, 100);
   b.graphics.lineTo(0, 0);
   b.graphics.endFill();

   addChild(a);
   addChild(b);

  }
 }
}

Notice, if I then call:

addChild(a);

It'll move the black box higher in the displaylist, and redraw it, thus 
covering the blue box.  If I then do:

addChild(b);

It'll put the blue box on top again, and draw it over top of the black one. 
Think swapDepths with the difference in that you can actually remove it from 
being drawn to the screen altogether, with the benefit of your movieclip 
still existing.

BTW, MovieClip's aren't the coolest kids on the block now.  Sprite is the 
new fad.  He's like a MovieClip, but has no timeline.


----- Original Message ----- 
From: "Derek Vadneau" <[EMAIL PROTECTED]>
To: <flashcoders@chattyfig.figleaf.com>
Sent: Friday, October 28, 2005 5:58 PM
Subject: Re: [Flashcoders] Newbie AS3 question


The keyword "this" makes sense to me.  I use it for instance variables.  I
guess at the end of the day, though, as long as you're consistent anyone
can pick up your code.

For MovieClip and addChild, is this similar to the way we use XML in AS2?
As in, you use createElement, then appendChild?

I'm a little confused like Frédéric about what happens when you add a
child multiple times.  Is a new instance created for each addChild?  If
so, is the return a reference to the new instance? (again, in the same
metaphor as XML children)

If this is not the case, then would adding multiple times just cause an
error or overwrite the previous addChild?  Just wondering how you
reference the child(ren).


Derek Vadneau



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders 

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to