2
votes

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.

6
Can you post the snippet of code tat does the loading. Will be easier to show you rather than explain in a generic wayJames Hay

6 Answers

6
votes

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

2
votes

Use the content property of the Loader object in which you are loading the SWF into. For example...

var swfTimeline:MovieClip = loader.content as MovieClip;
swfTimeline.nextFrame();
2
votes

If you want to load the symbols from Flash to Flex then this should help.

loader.contentLoaderInfo.applicationDomain.getDefinition("here linkage name") as Class

This code enables a Movieclip to be placed on stage, with it's timeline-based actionscript (stop commands at the end of the animation, etc.) intact. One way to use this is the following:

var c:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("BA_doors") as Class
_animation = new c() as MovieClip
addChild(_doors)
1
votes

If you get a null trying to get to the content, you might have to wait for a loading complete event:

   swfLoader.addEventListener(Event.COMPLETE, onSwfLoaded);

Once the swf has completely loaded, then you won't get a null any more.

One thing to be careful of is that even before you get the COMPLETE event, the main timeline on the swf will start running. You'll need to have a stop() on the first frame of the flash movie to do what you're trying to do... and even then it can be problematic. Sometimes the main timeline has a mind of its own.

In my project, we recently decided to totally clear the main timeline, and load movies out of the symbol library... Loading movieclips as symbols gives you complete control, but you would have to use transforms to get them placed correctly (since you don't have a main stage anymore.)

As long as you are using AS3 flash9 movie clips, you'll have complete control from Flex.

Enjoy!

1
votes

Shouldfnt it be..

loader.currentTarget.content as MovieClip;
0
votes

As far as I know - the only way for an AVM2 movie (your AS3 movie) to talk to an AVM1 movie (your as2 swf) is to use a LocalConnection object.

As to your first question - I am fighting the same... I need access to the loader.content property before the complete event fires.

Good luck!

Regards,

Chris