I have used AS 2 before, this is my first AS 3 project. I need MCs to be added dynamically inside container objects. After adding them, I am unable to access them via direct referencement. I can do this with the getChildByName() method but this is tiresome. Also, I noticed that the instances do not appear in the variables panel with their given name at the expected parent/child path but instead they all appear with their import variable names under "this". (in the example below, I have "cont" and "mc1" both showing under "this"). Here is my code :
var cont:Sprite = new Sprite() ;
cont.name = "Container" ;
addChild(cont) ;
var mc1:MovieClip = new MovieClip() ;
mc1.name="mc" ;
cont.addChild(mc1) ;
var ref1 = getChildByName("Container") ;
trace(ref1.name) ; // returns "Container"
trace(mc1.parent.name) ; // returns "Container"
var ref = ref1.getChildByName("mc") ;
ref.x = 100 ;
trace(ref.x) ; // returns 100
trace(ref1.mc1.x ) ; // DOES NOT WORK
trace(Container.mc.name) ; // DOES NOT WORK
Am I missing something ? Why am I unable to access my child MC via Container.mc ? Thank you for your help, Quentin
For the most part I got this covered here: Object Members vs Instance Names.
In order to access children via dot notation syntax, you need to declare these children as members of the container object. Something like that:
Once more: member names are different from instance names. After the script above your display list hierarchy is following: