Skip to main content
Inspiring
April 27, 2013
Question

change main movie content from an external movie clip

  • April 27, 2013
  • 2 replies
  • 967 views

Hi!

How do I change some content of main movie from external mc?

Lets say I have a menu on my main.swf, so when I click one of the buttons it adds a child.swf into movie clip 'mc'. Thats simple like this    mc.addChild("child.swf"); ( or something like that, there r few more steps in as3 i'm just demonstrating ).

Now how do I do that if the menu is an external movie itself(menu.swf)??  because in the menu.swf it has no recollection of what 'mc' is, so when I debug it just give me 'mc' is not defined, the buttons won't even show ? how do solve this problem?

I'm thinking if it's possible I can reference main.swf's instance names in menu.swf?

This topic has been closed for replies.

2 replies

Ned Murphy
Legend
April 27, 2013

WHile it is not clear what you have going on, if you load an swf dynamically into a movieclip, you can reference the movieclip from the loaded swf using MovieClip(parent), and you can target the main movie that is holding that movieclip using MovieClip(parent.parent).  YOu might also find MovieClip(root) can be useful in your scenario.

Inspiring
April 27, 2013

Hi, Ned, down there was the code, I used 'MovieClip(root)', it debug without problem, but when i click 'buttonMc', it gave me

Error #1010:

    at menu_fla::MainTimeline/clipClick()

.

but if i replace 'MovieClip(root)' with any mc in menu.swf, it work just fine.

on my 'main.swf', i have these

------------------------

var newLoader101:Loader = new Loader();

var request:URLRequest = new URLRequest("menu.swf");

newLoader101.load(request);

addChild(newLoader101);

newLoader101.x = 0;

newLoader101.y = 0;

--------------------------------

on my 'menu.swf', i have these

-----------------------------

var newLoader:Loader = new Loader();

var request:URLRequest = new URLRequest("child.swf");

newLoader.load(request);

//newLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded);

buttonMc.addEventListener (MouseEvent.CLICK, clipClick);

function clipClick(e:Event):void {

    MovieClip(root).mcMain.addChild(newLoader); <<--

}

--------------------------------

Inspiring
April 27, 2013

Hi Ned,

I tried MovieClip(parent.parent.parent) and it seem working, thanks a lot!

next question, how do I remove what's previously inside mcMain? So stuffs don't overlap each other?

any idea?

MovieClip(parent.parent.parent).removeChild(mcMain);  << doesn't work

removeChild(MovieClip(parent.parent.parent).mcMain); << doesn't work

Inspiring
April 27, 2013

btw the as3 script for loading child.swf is used on menu.swf, but not on main.swf. hope I making sense