Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

change main movie content from an external movie clip

Participant ,
Apr 27, 2013 Apr 27, 2013

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?

TOPICS
ActionScript
915
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 27, 2013 Apr 27, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 27, 2013 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 27, 2013 Apr 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); <<--

}

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 27, 2013 Apr 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 27, 2013 Apr 27, 2013

If you use the same approach as you did to add the movieclip you should be able to realize removing it.  Try to establish the code in a function in the same place for removing it as where you added it and call that function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 27, 2013 Apr 27, 2013

this is my function ( actually not really as I used someone's  lol )

function clipClick(e:Event):void {

                               

                                var targetSwf:String = e.currentTarget.ccc;

                                var swfRequest:URLRequest = new URLRequest(targetSwf);

                                var swfLoader:Loader = new Loader()

                                swfLoader.load(swfRequest);

                             

                                MovieClip(parent.parent.parent).subMc.addChild(swfLoader);

                                MovieClip(parent.parent.parent).mainMc.removeChildAt(0);<<---

                               

                             }

and because it is called from a button, so every time someone click it, it layers up, I wanted to add a line by where da arrow pointing, to remove the last added swfLoader.

shouldn't there be some simple code to do that?

see where the arrow pointing   removeChildAt(0);   kind of like that but this one doesn't do it as it just remove the whole movie.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 28, 2013 Apr 28, 2013
LATEST

There are easier ways to manage targeting objects if you maintain one point of attack for all your targeting... the main timeline.  RAther than using parent references to try to reach back thru the hierarchy, you should approach the coding from using the main timeline as the base of operations.

Instead of assigning a button within a loaded movie to try to control the main movie, just have the loaded movie dispatch an event, and have a listener assigned for that event in the main movie... assign it as soon as the file completes loading.  That way, your main timeline is in control of who stays and who goes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines