How to control a dynamically loaded SWF

actionscript-3flash

I have a flash piece that loads external SWF files. I need to be able to move the loaded swf file to the next frame in the main timeline.

Here's the code snippet:

var request:URLRequest = new URLRequest(file);
loader.load(request);
var swfTimeline:MovieClip = loader.content as MovieClip;
swfTimeline.nextFrame();

If I run a trace on swfTimeline, I get a null object reference. I think I found a way around that, but now the issue I'm having is that the loaded SWF is ActionScript 2 and AS3 doesn't seem to want to handle the AS2 SWF as a normal movie clip.

Best Answer

You need to add an event listener o the loader first so that you know when the load is complete. So from your code snippet i would suggest something like

var request:URLRequest = new URLRequest(file);
loader.addEventListener(Event.COMPLETE, function(event : Event) : void
{
var swfTimeline:MovieClip = loader.content as MovieClip;
swfTimeline.nextFrame();
});
loader.load(request);

Lots of different ways to organise this code but that should do the trick

Related Topic