Using AS3 in Flash, If you want to load an external swf movie and make it go to a specific frame to play or stop, you can achieve that using AS3 Loader class with the following code:
function loadSWF(swfURL){ var myLoader:Loader = new Loader(); var mySWF:URLRequest = new URLRequest(swfURL); myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler); myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler); myLoader.load(mySWF); } function onCompleteHandler(loadEvent:Event){ addChild(loadEvent.currentTarget.content); loadEvent.currentTarget.content.gotoAndStop(swfFrame); } function onProgressHandler(myProgress:ProgressEvent){ var percent:Number = Math.round(myProgress.bytesLoaded/myProgress.bytesTotal*100); trace(percent+"% loaded"); } var swfFrame:Number=100; loadSWF("swfs/movie.swf"); //call the function to load external swf and go to frame 100
Hope that helps.
Cheers!
WOOOOWWW, it’s nice script for my solution !!!! great !!! good job !!! and thank’s man ….
It’s incredible your code , work perfectly , thank you very much , greetings from México
Hi there, your preloaders look great, but i am having some trouble. When i use your external preloader from your “[AS3] Creating Preloader for External swf in Flash ActionScript3” tutorial my movie starts playing automatically after being loaded which i dont want. If i use your example above, it works fine and stops on the first frame of my loaded movie, but the preloader does not have any progress bar or percentage displayed whilst loading. How could i combine the two so as i have a preloader that shows percentage / load bar (like your first tutorial) yet stops at the first frame of my loaded movie.
Thanks in advance for any reply
Check this post. It has demo fla available too. It explains how you can load an external swf file with the preloader. You can easily keep loaded swf from playing and stop it at frame 1.
Thanks for the reply – that is actually the initial tutorial i was referring to. I tried adding “var swfFrame:Number=1;” to the code just before “var swfFile:String = ‘external-file.swf’;” but it did not work – am i missing something?
I also tried adding “swfFrame” into
“launchSWF(container, swfFile);” to see if that did anything, but an error said i was only allowed 2 parameters.
You can’t use two parameters as the function accept just one, see this blog post, it shows how to load and stop the loaded swf file.
i have a question. let say i have file1.swf , file2.swf, and file3.swf, how can i link this 3 files together,
let say suppose file1.swf is the main content file, but as i load file2.swf, i want the file1.swf get replaced by file2.swf. How could i unload file1.swf at that time, so that my file2.swf will become the main content file?
and again, when my current position at file2.swf, and i want it get replaced by file3.swf by clink on a button. so that the i can unload the file2.swf and let the file3.swf become the main content file..
any one have idea on it??
thank you..
Hi Yen,
It was a good and valid question and a routine requirement.
After your question, I did try this and finally could manage to load multiple external swf files one after another like a slideshow. All you have to do is the define list of swf files in an array. You can make it dynamic too by loading from xml file but I’ll keep that out in this tutorial for the sake of simplicity.
Here’s what I have done:
– Defined an array for the external swf files.
– Loaded the first swf file using Loader class.
– Added preloader for external swf file.
– Added the play/pause/rewind/forward buttons to control the swf
– Once the swf has reached its last frame, removed it and loaded next swf as defined in array as you mentioned.
– After playing the last swf, movie stops.
I have tried to make it as dynamic and feature rich as possible.
Please check this Multiple External SWF Slideshow post.
Cheers!