Skip to main content
Known Participant
July 16, 2010
Answered

how to call root lavel function & variables from external loaded swf file

  • July 16, 2010
  • 2 replies
  • 747 views

i have small issue in as3.  I am load "mainmenu.swf" file into "main.swf". through loader class. so now "main.swf" is parent "mainmenu.swf" file children how can call "main.swf " variable & function from "mainmenu.swf" .

This topic has been closed for replies.
Correct answer Ned Murphy

The parent of the loaded swf is the loader.  The main swf is the parent of the loader.  So to communicate with the main timeline the loaded file can use:

MovieClip(parent.parent).someFunction();

2 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
July 16, 2010

The parent of the loaded swf is the loader.  The main swf is the parent of the loader.  So to communicate with the main timeline the loaded file can use:

MovieClip(parent.parent).someFunction();

Inspiring
July 16, 2010

I'm not sure if I can help you but I'll try (mind my nickname here):

What are you trying to do?

Your mainmenu.swf is just a bunch of buttons that will load other  sections of your project?

If yes, maybe it's better to  have all this procedures related to your mainmenu button or in a  special class related to that file, and not in your main file.

In case you're doing everything with code on the timeline, you have to build your mainmenu.swf keeping in mind that, in the end, it will have a parent. Just to give you an example, you won't be able to simply use gotoAndStop if you want to move the timeline of your main file from your mainmenu. You'll use things like. parent.gotoAndStop.

Depending on what you're trying to do, to work with functions inside your loaded .swf, you'll probably need to dispatch events and I won't be able to help you.

If you're working with code on the timeLine, I think it's easy if you build your buttons in your main file an have external files to that each button will call.