Controlling a movieclip in the root timeline with a button inside a loaded swf

jawaelectric2
jawaelectric2 used Ask the Experts™
on
Hi,

I'm following on from a question I've previously asked with regards to controlling the timeline in a loaded swf. I've managed to work this out with the following code, with one kind contributor in the community helped me with:
var testChild:MovieClip; // it will hold loaded movieclip reference
 /*Load in external swf */
                        var loadSwf:Loader = new Loader();
                        var requestSwf:URLRequest = new URLRequest("test.swf");
                        // add load complete handler
                        loadSwf.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
                        loadSwf.load(requestSwf);


//2. on load complete event of your external SWF, create complete handler as follows:


                        function onCompleteHandler (loadEvent:Event) 
                       {
                              // store loaded movieclip's reference in local variable testChild
                              testChild = loadEvent.currentTarget.content as MovieClip;
                              // now add loaded child in your empty_mc
                              empty_mc.addChild(testChild);
                        }

//3. Add now control timeline of testChild


function loadTest(event:MouseEvent):void
{
// testChild is reference to your loaded MovieClip (SWF)
testChild.gotoAndStop(2);
}
move_btn.addEventListener(MouseEvent.CLICK, loadTest);

Open in new window



Now I'm trying to figure out how a button within that loaded swf (called btn1) can tell a movieclip within the root timeline (called my_mc) to go to frame 2.

Can anyone help?

Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can use event's from that loaded SWF:

Loaded SWF (Child SWF)
--------------------
In your loaded SWF say you have a button, on it's click handler you'll dispatch an event

function buttonClickHandler(evt:MouseEvent):void
{
     var evt:Event = new Event("customevent", true); // setting bubble true in case this button is nested within some other parent
     dispatchEvent(evt); // receive this event in your Parent (main movie)
}
-----------------------


In your parent SWF
-------------------------------
Update your load complete handler, and listen to event dispatched by child

function onCompleteHandler (loadEvent:Event)
                       {
                              // store loaded movieclip's reference in local variable testChild
                              testChild = loadEvent.currentTarget.content as MovieClip;

                              // add event listener on loaded SWF
                              testChild.addEventListener("customevent", customEventHandler);

                              // now add loaded child in your empty_mc
                              empty_mc.addChild(testChild);
                        }

function customEventHandler(evt:Event):void
{
   // handler for child's event, here you can send my mc to 2nd frame
   my_mc.gotoAndStop(2);
}

Hope this will help.
Any success?

Author

Commented:
Hi, sorry for such a late reply - workload management issues.

Just tested your code and it works great, thank you so much for your help. As a follow on to this solution, I'm still struggling (as a designer and not a programmer by nature) to get my measly brain round some AS3 movieclip levels issues.

Essentially, I'm trying to get a swf to load into an empty movieclip (called mc_info), which is nested within a movieclip sitting on the root level (called menu_mc). The button to activate this (called btn1) is nested 2 levels deep within another movieclip on the root level.

I think the old AS2 way was

_parent._parent.mc_menu.mc_info(loadMovieclip "someMC.swf", 1);

or use _root.

I've tried using MovieClip(parent) but this method doesn't seem to be working.

Any help would be much obliged, as I say I'm a designer dipping into and attempting to learn AS3, but the old cogs aren't turing quite yet.

Thanks.

 

you can do it in onCompleteHandler (as mentioned in my code above):

// now add loaded child in your empty_mc
//empty_mc.addChild(testChild); // this was the old line

change this to:
---------------
root.menu_mc.mc_info.addChild(testChild);

or

root.getChildByName("menu_mc").getChildByName("mc_info").addChild(testChild);
-----------------------

Author

Commented:
Great advice, works perfectly thanks - you've really helped me get to grips with movieclip and swf paths.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial