Question : Control timeline within loaded movieclip

This should be an easy one for all you experts, I'm no kind of expert and this has been troubling me for a couple of days now.

I'm trying to control the timeline of an externally loaded movieclip (called test.swf), which has been loaded into an empty mc (called empty_mc) on my main swf. Basically, I just want to tell the movieclip within the loaded movieclip (called numbers) to move to frame 2 when I click a button (called move_btn).

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var test:Loader = new Loader();
empty_mc.addChild(test);
 
var url:URLRequest = new URLRequest("test.swf");
test.load(url);

function loadTest(event:MouseEvent):void
{
empty_mc.numbers.gotoAndStop(2);
}
move_btn.addEventListener(MouseEvent.CLICK, loadTest);



Can anyone help out?

Thanks in advance.

Answer : Control timeline within loaded movieclip

You need some small correction:

It would be good if you'll store child's reference in separate variable, than you can directly invoke movieclip methods on that variable.

See example:
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)
                       {
                             
                              // do whatever is needed

                              // 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);

Hope this will help.
Random Solutions  
 
programming4us programming4us