PDA

View Full Version : Dynamic Instance name vs manual Instance name?



IanCremona
November 10th, 2008, 06:47 AM
Hello,

I would like to access this object (taken from Debug > List Objects of in flash player)


ActionScript Code:

Target="_level0.promotion0.loader_mc.instance87.promoTXT"





This is what I am trying to access it with:


ActionScript Code:

trace( this.getChildByName("promotion0").loader_mc.getChildByName("instance87").promoTXT.text );






Error:


ActionScript Code:

1119: Access of possibly undefined property loader_mc through a reference with static type flash.display:DisplayObject.







what is the correct way to do this?

wvxvw
November 10th, 2008, 07:35 AM
_level0 is an AS1 / AS2 notation, are you sure your movie is using AS3?
Also, for AS3 getChildByName() returns value of type DisplayObject, you have to cast the returned value to the appropriate type. I.e. if promotion0 is of type MovieClip, then your code would look like:

(this.getChildByName("promotion0") as MovieClip).getChildByName("loader_mc");
But usually you don't want to:
- search for clips by name, because it's better to have a variable pointing to them directly.
- have such a long statements with several getChildByName() in one line.