Re: Short syntax for accessing nested display objects? (AS3)

Troy Rollins <[email protected]> Sat, 20 Oct 2007 00:30:07 -0400
Newsgroups gmane.comp.web.flashcoders.devel
Message-ID <[email protected]>
On Oct 19, 2007, at 10:05 AM, Alistair Colling wrote:

> var cont:Sprite = new Sprite();
> this.addChild(cont);
> var cont1:Sprite = new Sprite();
> cont.addChild(cont1);
> var child1:Sprite = new H1();
>
> var target =cont.getChildByName("cont1");
> var targ2 = target.getChildByName("child1");	
>
> targ2._visible = false;

Well, if you _really_ want to, you can do it with 1...

//////////////////////////
// This code will run in a frame script
import flash.display.*;

var cont:Sprite = new Sprite();
cont.name = "cont"
this.addChild(cont);
var cont1:Sprite = new Sprite();
cont1.name = "cont1"

var child1:Sprite = new Sprite();
child1.name = "child1"
cont1.addChild(child1);
cont.addChild(cont1);


var childTest:Sprite = Sprite(cont.getChildByName 
("cont1")).getChildByName("child1") as Sprite;
childTest.visible = true;
trace(childTest.name + " " + childTest);
stop();
///////////////////////////

Of course, I effectively casted twice in one line, but hey...  ;-)

--
Troy
RPSystems, Ltd.
http://www.rpsystems.net


_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders