Say i have a movieclip named a_Mc ( ClassA ) .
I have a sub-movieclip named b_Mc ( ClassB )
CASE 1: Accessing the sub-movieclip b_Mc which is already present inside the a_Mc movieclip
( Since Flash IDE has “Automatic instance naming” OFF )
ClassA mentions the name of b_Mc as => var b_Mc:MovieClip;
NOTE HERE: That the variable name MUST BE same as the name of the instance on stage.
So i can access it as : trace( a_Mc.b_Mc);
CASE 2: Accessing the sub-movieclip b_Mc after adding it dynamically
var b_Mc:ClassB = new ClassB();
b_Mc.name = "someName" ;
a_Mc.addChild(b_Mc) ;
So i can access it as : trace( a_Mc.getChildByName("someName"));
I wanna understand, why is there such implementation difference when on the contrary things must be similar. How exactly flash player manages “existing instance names”, “dynamically added instance names” and “variable names used in related classes to represent those instance names” ?
Thanks
Vishwas.
You are actually doing two different things there.
In case 1
b_Mcis a variable contained within Class A.In case 2
b_Mcis a child of thea_McMovieClip’s display list.So in case 2, you can access
b_Mcby just doingtrace(b_Mc);. You don’t have to go througha_Mcsince the variable was created outside of the class.There is a difference between something being a display list child (case 2) and being a member variable of an object (case 1).
If you wanted to dynamically create the sub-movieclip you could do:
There you’re assigning the new clip to the
b_Mcvariable within Class A.Then you could access it the same as in case 1:
You could also create the
b_Mcwithin Class A and assign it to theb_Mcvariable directly:Note that all of these are independent of whether or not
b_Mcis a child of A’s display list, or whether or not is on the display list at all.