A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Preloading External SWFs

  1. #1
    Junior Member
    Join Date
    Aug 2003
    Location
    Fresno, California
    Posts
    2

    Preloading External SWFs

    Can anyone tell me a simple way to preload an external swf without putting a preloader in the actual external file? My situation is that I want to preload at least a portion of an external file (video in swf format) before begining anything in my main movie. I am loading the swf into an empty movie clip container, but how do I check the bytes loaded for the external file and not the container clip?

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    you actually check the bytes loaded for the container clip. To test the preload, show Streaming in test mode will not work. It has to be tested on a server.

    Now let's assume your container is set on the main timeline. And that its instance name is container. You will then target it as _level0.container.

    So here's a 2 frames loop that will preload the content of _level0.container

    code:
    gotoAndPlay("loading");
    loadedbytes = _level0.container.getBytesLoaded()/1024;
    totalbytes = _level0.container.getBytesTotal()/1024;
    percent = Math.round(loadedbytes/(totalbytes)*100);
    po = "Loading: "+Number(percent)+"%";
    if (loadedbytes == 0 && totalbytes == 0) {
    po = "Waiting for reply";
    gotoAndPlay("loading");
    } else if (loadedbytes>1 && percent>99) {
    _level0.container.gotoAndStop("startFrame");
    gotoAndPlay("end");
    } else {
    gotoAndPlay("loading");
    }



    so you have an empty frame with label 'loading' then another with that code in it.
    This part:
    _level0.container.gotoAndStop("startFrame");
    means when the external swf is loaded (percent>99) it will send it to play its content. Apparently on a labeled frame. If you want the main timeline to do the same just add: _level0.gotoAndPlay("label");

    Now you can change that line (percent>99) to whatever percentage where you want your clip to play.

    hope this helps
    gparis

  3. #3
    Junior Member
    Join Date
    Aug 2003
    Location
    Fresno, California
    Posts
    2

    Thanks!

    Thanks!

    This works. I just modified it a little. I am going to try using a percentage preloader along with this (targeting the container clip). Thanks again!

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    you're welcome. to see the percentage use a dynamic field with variable name 'po' (percentage output)
    gparis

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