Hi I'm loading an external swf into a MovieClip, and I want it to stop until I choose to play. Currently it plays upon loading immediately.
var mc:MovieClip;
var swfLoader:Loader = new Loader();
swfLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, eventLoaded);
var request:URLRequest;
request = new URLRequest("external.swf");
swfLoader.load (request);
function eventLoaded(e:Event): void
{
mc = e.target.content as MovieClip;
// does not stop the clip
mc.Stop ();
}
So I tried adding a Event.ENTER_FRAME to the movieclip and stop it there, that will stop but it will play the first frame. Is there a way to get it to stay stopped when loaded until I choose Play?
It's actually very close to what Jochen Hilgers suggested. However, in this instance, the event you want is actually
INIT
instead ofCOMPLETE
.INIT
is fired when the content is not yet fully loaded but is ready for use (and will start playing on its own).Attach the event with
And handle it with
You'll notice that you can cast the
content
property ofcurrentTarget
as a MovieClip and stop it even before it has been attached to the stage.It is important to note that it is not safe to use the
content
property in aPROGRESS
event (or any time prior to anINIT
orCOMPLETE
event). You will get an error to the effect that the object is not ready.I wrote this simple TestCase and it works fine... the loaded swf is quite simple, just a tween on the main timeline.
I was looking for a similar problem/solution, but my problem was little diferent. I know this was not your issue, but looks fair to share my solution. When I tried to do
with the content of a loader, my Flash IDE showed me this error:
"Property stop not found on flash.display.AVM1Movie and there is no default value."
This happened to me because the swf I imported was created using AS1, and not AS3 as the main movie ( so I decompiled the swf to a fla and recompiled using as3, it was an output from After Effects). Now I know AVM1 and AVM2 are classes that represent actionscript 1 and 2 files.