Movieclip in library referencing variables in main document class

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?

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

:slight_smile:

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.

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.

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.

Wow… simple and works like a charm, thanks!

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 :slight_smile:

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 :slight_smile:

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?

Any other ideas?