# Movieclip in library referencing variables in main document class

**URL:** https://forum.kirupa.com/t/movieclip-in-library-referencing-variables-in-main-document-class/265389
**Category:** flash
**Created:** [July 8, 2008, 1:50pm UTC](https://forum.kirupa.com/t/movieclip-in-library-referencing-variables-in-main-document-class/265389 "2008-07-08T13:50:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![dualpixel](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@dualpixel](https://forum.kirupa.com/u/dualpixel)
#### Post date: [July 8, 2008, 1:50pm UTC](https://forum.kirupa.com/t/movieclip-in-library-referencing-variables-in-main-document-class/265389/1 "2008-07-08T13:50:18Z")

</div>

I have a main.fla and a main document class (main.as)

Within the main.fla file I have a movieclip in the library with the linkage id of “myMC” and it is exported within the first frame.

Within that movieclip I have two images that I would like to attach ToolTips to, however, the key is to reference the text for the tooltips from XML as I have done previously through the main.as class.

I keep getting this error Access of undefined property toolTip and XML\_mc

Here is the code within myMC in the library

ActionScript Code:  
[LEFT]  
\_button1.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]ROLL\_OVER[/COLOR], launchToolTip[COLOR=#000000])[/COLOR];  
function launchToolTipCOLOR=#000000[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]  
toolTip.[COLOR=#000080]addTip[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[/LEFT]

Note: In main.as I have toolTip and XML\_mc both referenced as public variables within the package.

Any ideas?

---

<div class="post-metadata">

### Author: ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)
#### Post date: [July 8, 2008, 2:05pm UTC](https://forum.kirupa.com/t/movieclip-in-library-referencing-variables-in-main-document-class/265389/2 "2008-07-08T14:05:01Z")

</div>

Quit putting code inside movieclips. It was bad habit in AS1, worse in AS2 and horrible in AS3

🙂

---

<div class="post-metadata">

### Author: ![dualpixel](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@dualpixel](https://forum.kirupa.com/u/dualpixel)
#### Post date: [July 8, 2008, 2:44pm UTC](https://forum.kirupa.com/t/movieclip-in-library-referencing-variables-in-main-document-class/265389/3 "2008-07-08T14:44:34Z")

</div>

I agree with you, however, in this case I don’t know how else to approach it. I am pulling the movieclip on to the stage using \<img\> tags embedded into a textfield within an XML file encapsulated by CDATA tags. Therefore, I need to accomplish everything to pull within the movieclip, somehow putting the actions of the image rollovers within the MC itself, otherwise I do not see how I can reference it.

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [July 8, 2008, 3:01pm UTC](https://forum.kirupa.com/t/movieclip-in-library-referencing-variables-in-main-document-class/265389/4 "2008-07-08T15:01:02Z")

</div>

in myMC your scope is myMC. Your toolTip and XML\_mc properties are defined in main. To access those properties, you have to go through that main (document/main timeline/root) object.

```auto
var toolTip = main(root).toolTip;
var XML_mc = main(root).XML_mc;

// existing code...

```

Note that root is typed as a displayObject, so for Flash to recognize that those properties actually exist on the true value of root, you need to cast it to your document class, main.

---

<div class="post-metadata">

### Author: ![dualpixel](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@dualpixel](https://forum.kirupa.com/u/dualpixel)
#### Post date: [July 8, 2008, 3:24pm UTC](https://forum.kirupa.com/t/movieclip-in-library-referencing-variables-in-main-document-class/265389/5 "2008-07-08T15:24:42Z")

</div>

Wow… simple and works like a charm, thanks!

---

<div class="post-metadata">

### Author: ![dthought](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/dthought/32/3573_2.png) [@dthought](https://forum.kirupa.com/u/dthought)
#### Post date: [July 8, 2008, 3:34pm UTC](https://forum.kirupa.com/t/movieclip-in-library-referencing-variables-in-main-document-class/265389/6 "2008-07-08T15:34:04Z")

</div>

Still, I agree with sekasi… you shouldn’t get used to this method as a way of doing things… it will lead to trickier code later on 🙂

Better to use your main document class to tell the children what to do, rather than have the children know explicit details about the code structure of their parent 🙂

---

<div class="post-metadata">

### Author: ![dualpixel](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@dualpixel](https://forum.kirupa.com/u/dualpixel)
#### Post date: [July 8, 2008, 4:57pm UTC](https://forum.kirupa.com/t/movieclip-in-library-referencing-variables-in-main-document-class/265389/7 "2008-07-08T16:57:00Z")

</div>

Once again, I have to agree. For now I have it working, however, if I was to do it the opposite way of using the main doc class to reference the child movieclip, is there a way to retrieve everything that the movieclip itself has on it’s stage? For instance, if it has two movieclips within it that have instance names, could I go from document class to the movieclip and then scan the movieclip to see all instances on the stage of that movieclip?

That is the only way I could see this working the other way, the process will just be reversed and applied before the content appears on screen.

Your thoughts?

---

<div class="post-metadata">

### Author: ![dualpixel](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@dualpixel](https://forum.kirupa.com/u/dualpixel)
#### Post date: [July 9, 2008, 2:33pm UTC](https://forum.kirupa.com/t/movieclip-in-library-referencing-variables-in-main-document-class/265389/8 "2008-07-09T14:33:10Z")

</div>

Any other ideas?
