views:

7104

answers:

6

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.

How can I do that with ActionScript 3.0


Update:

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.

+2  A: 

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();
Matt W
That looks like exactly what I want to do, but when I try to access loader.content, I get a null object reference.
Ryan Smith
+4  A: 

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

James Hay
A: 

Hi Ryan,

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!

Jim Carroll
A: 

Hi Ryan,

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

A: 

Shouldfnt it be..

loader.currentTarget.content as MovieClip;

Chris
A: 

Hi,

If u want to load the symbols from flash to Flex then it will help.

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

M.Raju