PDA

View Full Version : Detecting end of loaded external swf



lesterp99
December 12th, 2009, 12:27 PM
Hi,
I have a main swf file that needs to stop, load & play an external swf file the main timeline, & then resume the main timeline when the external swf has finished playing.

So I have the follwing code in a frame in the main timeline:

stop();
var swf:MovieClip;
var loader:Loader=new Loader();
var defaultSWF:URLRequest = new URLRequest("url/.swf");

loader.load(defaultSWF);
loader.x = 172;
loader.y = 180;
addChild(loader);

//////

function swfComplete(e:Event):void {
// trace ("I'm here");
removeChild(loader);
play();
}

This loads and plays OK but it's the unload and play that I'm struggling with.

What code can I use to detect the end of the external swf and either call swfComplete of goto a main timeline label?

Many thnx in anticipation,

Lesterp99
Flash CS4
AS3

snickelfritz
December 12th, 2009, 12:33 PM
Dispatch a custom event from the timeline in the loaded SWF.
Listen for the custom event on the main timeline.
Call an event handler when the event is received.
Send the playhead to the frame label in the event handler.

Scott64
December 12th, 2009, 01:18 PM
You can add an ENTER_FRAME listener to the loaded SWF and have it check to see when the currentFrame == totalFrames. That way you don't have to ensure that every SWF has custom code in it.