1

I have an issue with a child SWF loaded into a parent. The loading is pretty basic, everything should be ok. The problem is when the child has more than one frame, the SWF just loops indefinitely. When completed the child will have multiple frames and forward/back buttons, but I've distilled it down to two frames with a different image on each and no code save for stop(); I have another parent which I didn't create (and you don't want to see) that will accept an AS2 SWF but loops on AS3, which is where this whole project originated... Any insight is greatly appreciated....

This is the code for the parent:

var _swfLoader:Loader;
var _swfContent:MovieClip;

loadSWF("test4.swf");

function loadSWF(path:String):void {
   var _req:URLRequest = new URLRequest();
   _req.url = path;

   _swfLoader = new Loader();
   setupListeners(_swfLoader.contentLoaderInfo);

   _swfLoader.load(_req);
}

function setupListeners(dispatcher:IEventDispatcher):void {
   dispatcher.addEventListener(Event.COMPLETE, addSWF);
   dispatcher.addEventListener(ProgressEvent.PROGRESS, preloadSWF);
}

function preloadSWF(event:ProgressEvent):void {
   var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
   // swfPreloader.percentTF.text = _perc + "%";
}

function addSWF(event:Event):void {
   event.target.removeEventListener(Event.COMPLETE, addSWF);
   event.target.removeEventListener(ProgressEvent.PROGRESS, preloadSWF);

   _swfContent = event.target.content;
   _swfContent.addEventListener("close", unloadSWF);

   addChild(_swfContent);
}

function unloadSWF(event:Event):void {
   _swfLoader.unloadAndStop();

removeChild(_swfContent);
   _swfContent = null;
}
4

1 回答 1

1

Did DaveGaur answer your question here? AS3 Stop external swf

By default, when a MovieClip is added to stage, it will play. If the MovieClip only has one frame, this will not look different. Complete event is not called until all frames and children are loaded. Dave said the INIT event is called when first frame is ready to play. So, for your code, Dave might have suggested something like this near setupListeners:

dispatcher.addEventListener(Event.INIT, stopContent, false, 0, true);

function stopContent(event:Event) {
    event.target.removeEventListener(Event.INIT, stopContent);
    _swfContent = event.target.content as MovieClip;
    _swfContent.stop();
}
于 2012-08-13T02:35:27.840 回答