A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Loading SWFs from another SWF

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    5

    Loading SWFs from another SWF

    Hi all, new member here!

    I have a SWF that contains 3 spaces for banners on a 'My Account' page. Initially they all showed the same banners to all customers but now we segment customers and that means each banner can have numerous variations. This has caused the SWF to be massive (over half a meg) for something we aim to have 80-100 Kb.

    I believe the solution is to have the current 'main' SWF be a place-holder that decides what segment the customer is in for each banner then pull another SWF file from the server - so only the banner being displayed is the one being downloaded.

    I cannot find AS to download externally hosted SWFs... can anyone help or suggest an alternative?

    Many thanks!
    Craig

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If they are hosted on the same server as the swf which is doing the loading, then all you need is a Loader.

    If they are on a different domain, then you will need to have a cross-domain policy on the server you are loading from that authorizes that content to the loading swf. Then load it with a Loader like normal.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    5
    hey thanks for the reply.

    they will be hosted on the same server - in the same directory in fact.

    please can you give me a little more information on a 'loader'? when i search for it i only find preloaders.

    thanks
    craig

    Quote Originally Posted by 5TonsOfFlax View Post
    If they are hosted on the same server as the swf which is doing the loading, then all you need is a Loader.

    If they are on a different domain, then you will need to have a cross-domain policy on the server you are loading from that authorizes that content to the loading swf. Then load it with a Loader like normal.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    http://help.adobe.com/en_US/FlashPla...ay/Loader.html

    Loader is a class used to load content from a server at runtime. It can load images (png, jpg, etc) as well as swfs.

    A single Loader can only load one thing at a time. Loading something new into it will discard the previously loaded resource.

    Loader is itself a DisplayObject so you can put it on the display where you want your loaded thing to go, tell it to load, and the thing will show up when it gets downloaded.

    To load something, you need to use the load method with a URLRequest. Like this:
    Code:
    var loader:Loader = new Loader();
    addChild(loader);  //put your Loader on the display
    loader.load(new URLRequest("http://example.com/someswf.swf"));
    Loader and LoaderInfo (an associated class which each loader has) also dispatch events. The most common use is to listen for the Event.COMPLETE dispatched by the LoaderInfo to know when the resource is loaded. But you can also listen for various error events such as IOErrorEvent.IO_ERROR to know when something goes wrong.

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    5
    thanks for that i'll read up on it.

    would this mean i can only load a single external swf at a time? or will there still be a way to load multiple swfs to place in view simultaneously.

    thanks
    craig

    Quote Originally Posted by 5TonsOfFlax View Post
    http://help.adobe.com/en_US/FlashPla...ay/Loader.html

    Loader is a class used to load content from a server at runtime. It can load images (png, jpg, etc) as well as swfs.

    A single Loader can only load one thing at a time. Loading something new into it will discard the previously loaded resource.

    Loader is itself a DisplayObject so you can put it on the display where you want your loaded thing to go, tell it to load, and the thing will show up when it gets downloaded.

    To load something, you need to use the load method with a URLRequest. Like this:
    Code:
    var loader:Loader = new Loader();
    addChild(loader);  //put your Loader on the display
    loader.load(new URLRequest("http://example.com/someswf.swf"));
    Loader and LoaderInfo (an associated class which each loader has) also dispatch events. The most common use is to listen for the Event.COMPLETE dispatched by the LoaderInfo to know when the resource is loaded. But you can also listen for various error events such as IOErrorEvent.IO_ERROR to know when something goes wrong.

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    To load more than one thing at once, you can simply use more than one Loader.

    Or you could set an event listener for the COMPLETE event, and take the loaded content out of the loader to put it somewhere else, then load a new resource into the same loader.

    Bear in mind that the COMPLETE event is dispatched by the loaderInfo, not the Loader itself.

  7. #7
    Junior Member
    Join Date
    Feb 2012
    Posts
    5
    Thanks I think I'll understand I'll have a stab at it

    Craig

    Quote Originally Posted by 5TonsOfFlax View Post
    To load more than one thing at once, you can simply use more than one Loader.

    Or you could set an event listener for the COMPLETE event, and take the loaded content out of the loader to put it somewhere else, then load a new resource into the same loader.

    Bear in mind that the COMPLETE event is dispatched by the loaderInfo, not the Loader itself.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center