PDA

View Full Version : Loading an external SWF



steresa
May 31st, 2009, 09:49 PM
I know how to load an external swf file with the following AS3

var req:URLRequest = new URLRequest("http://www.beholdcreative.com/slide_home.swf");

var loader:Loader = new Loader();

loader.load(req);
addChild(loader);

loader.x = -442;
loader.y = -194;

However, I want to load an external swf that is triggered by a mouse click. I have a button with an instance name if photogallery_btn and I want to apply AS3 to this so when this button is clicked, an external swf is loaded. Can some one please show me how to right this code?

Also, how do you unload a external swf? For example, say I get the code working for the photogallery_btn so when it's clicked, an external swf file is loaded. I would like to know how to unload another external swf file once the photogallery_btn is clicked.

cbeech
June 1st, 2009, 08:19 AM
basically you would trigger the load() call in the button handler - so something like this:


var req:URLRequest = new URLRequest("http://www.beholdcreative.com/slide_home.swf");
var loader:Loader = new Loader();
loader.x = -442;
loader.y = -194;
addChild(loader);

photgallery_btn.addEventListener(MouseEvent.CLICK, loadPage);
function loadPage(e:MouseEvent):void {
loader.load(req);
}

to 'unload' a previously loaded file use... you guessed it! ;) loader.unload();

fs_tigre
June 2nd, 2009, 10:15 AM
Excuse my ignorance but what would be the benefit to unload the .swf file. What if you just move it to one side and move it back to the stage later is this valid?
Can someone point me why it would be better to unload the .swf files?
Thanks

cbeech
June 2nd, 2009, 10:35 AM
Excuse my ignorance but what would be the benefit to unload the .swf file. What if you just move it to one side and move it back to the stage later is this valid?
you can do just that :) however it may depend on your file size(s). say for instance you had 10 long animations, you wouldn't necessarily want to load them all up front. and once you do so (load), when ready to load the next file you may wish to unload the previous one to save on memory usage, and keep processing at the high speed possible - you also wouldn't want your users running into 'out of memory' errors/warnings.


Should I create all sections in one .swf file or shoud I create .swf files for each section and load them as needed?
you should consider the size of each content section (memory wise), the loading speed of each file/section, and/or the need to break it apart. there are any number of ways in which to construct systems of this type - some of it will depend on your own personal preferences and workflow.

fs_tigre
June 2nd, 2009, 10:54 AM
Thank you very much for the clarification!

Moved to a different thread

Quote:

Should I create all sections in one .swf file or shoud I create .swf files for each section and load them as needed?
you should consider the size of each content section (memory wise), the loading speed of each file/section, and/or the need to break it apart. there are any number of ways in which to construct systems of this type - some of it will depend on your own personal preferences and workflow.