Skip to main content
March 12, 2008
Question

Why is this a good thing?

  • March 12, 2008
  • 2 replies
  • 187 views
I have my file working, but help me out here...I am trying to understand why this is a good thing.

I have a document class called DocClass. It extends MovieClip. In it, I have a holder mc that calls in a dynamically generated mc (from library) that has in it another dynamically generated mc (also from the library). From DocClass, I wanted to make changes in the label that existed in the sub/sub mc.

In AS2, this would be done with:
holderMC.dynamMC1.dynamMC2.labelName = "changed text";

In AS3, it goes like this:
(DocClass(root) as MovieClip).holderMC.getChildByName("dynamMC1").getChildByName("dynamMC2").labelName.text = "changed text";

DocClass was already extending MovieClip AND it works elsewhere by just referencing DocClass(root).doSomething(). However, it seems like it loses the knowledge that it is the root MC when I am trying to dive into the sub clips. Am I missing something? Did I resolve it in a "best practices" way? If so...why does this happen and if Adobe intended it, why is it a good thing?
This topic has been closed for replies.

2 replies

Inspiring
March 13, 2008
quote:

Originally posted by: bnailWedge
Am I missing something?


well... maybe :)

is the label text required to change because some *event* occurred? (nudge-nudge)

(a famous programmer named Henry WadswOOrth LOOngfellOOw once said:
I shot an arrow into the air
it fell to earth I know not where)

There comes some point of many nested levels where your current approach becomes too burdensome, and so it becomes advisable to undertake the overhead of some custom event + handling.

Also, note that:
(DocClass(root) as MovieClip).holderMC...
can and should be only:
holderMC...
since you are using that from the main timeline to begin with

Also, why can't you just use:
holderMC.dynamMC1.dynamMC2.labelName = "changed text";

where e.g. dynamMC1 is a handle which refers to an object and not the content of the name property on that object

Craig Grummitt
Inspiring
March 12, 2008
if you dynamically created dynamMC1 and dynamMC2, then at the time of instantiation you could create references to these mcs in public variables. in which case your code to change the label could be exactly the same:
holderMC.dynamMC1.dynamMC2.labelName = "changed text";

as far as best practice, no that wouldn't be the best practice. best practice would require better encapsulation. the DocClass shouldn't be editing a label of a dynamically created object inside a dynamically created object inside a holder to begin with!