Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Kaleb242

After using SWFLoader autoPlay:false, how to play() later?

Recommended Posts

After using SWFLoader with autoPlay:false to load a swf and stop it's contents, how can you get the content to play later (on demand)?

 

Here's my set of loaded swf files...

var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
queue.append( new SWFLoader("swfs/main.swf", {name:"mainClip", estimatedBytes:211461, container:container_mc, x:0, y:0, visible:false, autoPlay:false}) );
queue.append( new SWFLoader("swfs/promo1.swf", {name:"promo1", estimatedBytes:190440, container:container_mc, x:0, y:0, visible:false, autoPlay:false}) );
queue.append( new SWFLoader("swfs/promo2.swf", {name:"promo2", estimatedBytes:76251, container:container_mc, x:0, y:0, visible:false, autoPlay:false}) );

 

I see that there is a protected method in SWFLoader.as called _stopMovieClips(obj:DisplayObject) used when autoPlay==false, but I don't see a public method such as playMovieClips() to be used later if you have used autoPlay:false initially.

 

What is the best strategy for preloading several swfs with autoPlay set to false, then targeting one of these later and play() it's contents?

 

I'm loading in AS3 .SWF files that are timeline animations provided by a designer with no stop frames on them, so I need to use autoPlay:false, and want to trigger one to play at a later time (after loading is complete, of course).

 

I traced the following trying to pinpoint the loaded swf to target, but I'm having difficulty trying to get it to play...

 

trace((container_mc.getChildAt(0).name)); // mainClip
trace((container_mc.getChildAt(0).parent).name); // container_mc
trace((container_mc.getChildAt(0).parent.parent).name); // root1
trace((queue.content)); // [object ContentDisplay]

 

It's probably something very simple, I'm just not finding a quick solution in the documentation and I want to make sure that I do this the proper way, as intended by LoaderMax.

 

Thanks,

~K

Link to comment
Share on other sites

It should be as simple as calling play() on the rawContent, like:

 

myLoader.rawContent.play();

 

For the record, the protected _stopMovieClips() method is only used internally to prepare a loaded swf for disposal (garbage collection).

Link to comment
Share on other sites

Thanks Jack.

 

LoaderMax.getContent("mainClip").rawContent.visible = true;
LoaderMax.getContent("mainClip").rawContent.play();

Link to comment
Share on other sites

Since autoPlay:false loops through all movieclips of the loaded swf and stops them from running, you may find that you'll need to restart all movieclips on the timeline of your loaded swf when you want to play it at a later time on demand... just calling play() on the rawContent may not be enough.

 

In my case, I discovered that the designer that gave me several AS3 swfs to load, also included several animated movieclip masks on the timeline, which autoPlay:false had stopped every clip on the timeline, so they needed to be restarted. The appearance was not the same without these movieclips playing too.

 

It would be handy to have a public method to restart those same timeline clips that are stopped by autoPlay:false 's trigger of the _stopMovieClips method.

 

 

In my case, I created a method to play the internal clips by reverse-engineering the _stopMovieClips method:

 

var contents:ContentDisplay = LoaderMax.getContent("mainClip");
playMovieClips(contents.rawContent);

 

public function playMovieClips(obj:DisplayObject):void {
var mc:MovieClip = obj as MovieClip;
if (mc == null) {
	return;
}
mc.play();
var i:int = mc.numChildren;
while (--i > -1) {
	playMovieClips(mc.getChildAt(i));
}
}

 

Would be a nice addition to SWFLoader, considering that we'll need to write a playMovieClips function for every project that uses SWFLoader with autoPlay:false that has loaded swfs with movieclips containing timeline animations inside them.

 

Perhaps I should be using autoPlay:true to avoid the _stopMovieClips method from ever being called, and then call a stop() on the main timeline of the loaded swf when the load is complete, to avoid every MovieClip on the main timeline from being stopped.

Link to comment
Share on other sites

Since autoPlay:false loops through all movieclips of the loaded swf and stops them from running...

That's not true. I'm a little confused as to why you think autoPlay:false would call _stopMovieClips(), stopping all child MovieClips as well. All it does is call stop() on the root timeline of the subloaded swf. So calling rawContent.play() would indeed resume it playing. However, if there are subclips that begin playing right away in your swf, it would probably be wise to simply reload the content when you need to start everything over again, kinda like:

 

var loader:SWFLoader = new SWFLoader("myFile.swf", {autoPlay:false});
loader.load();

//then later when you want to display and play it...
loader.vars.autoPlay = true;
loader.load(true);
addChild(loader.content);

 

This ensures that everything initializes properly and plays as expected. Otherwise, you may have actions on the first frame of MovieClips that do certain things that wouldn't necessarily be affected with a simple stop() call. The down side is that it takes a little bit longer to reload it, but since it'd be cached, it should be very quick.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×