Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


a staggered preloader

Posted on 2002-06-09
Medium Priority
Last Modified: 2008-02-07
This picks up on an earlier question...'Timeline movement after a function call.

The basic goal is to pre-load a series of .swf and to notify the _level0 when a certian subset of the total .swfs are done loading so _level0 can safely begin playback while the remaining swf. continue to load.

a prototype of my product is at 

Chose 'RESAP', next to last in 2nd column ...all other menu choices are dead.  

If on a dial up line...wait 30 secs or so...the screens depend on a _level being loaded and that's what we're here to iron out. If you get a blank screen...a subhead with no body text...choose the bottom arrow | Main menu and restart Intro & Coverage.

The screens are fed by a db one record per screen in a form that parses into flash vars as:

subhead_1 = "SubHead1";
bodytext_1 = "bodytext for the 1st screen";
visual_1 = "graphic";
subhead_2 = "SubHead for 2nd screen";
bodytext_2 = "bodytext for the 2nd screen";
visual_2 = "graphic2";

Text is loaded into one level while another level with all the tutorial's graphics has been loaded into a seperate level. Each screen's visual matches a lable within this level. Note that you can see the current iteraction ('ID') and the name of the visual in the lower left corner.

Every screen change fires a function that (among other things) issues a '_level39.gotoAndPlay(visual);'.

The problem is preloading that 'assets' level. The current one is 500k...some will be larger. Too big to ask a dialup user to wait for the complete tutorial to download in advance but the whole thing breaks if I give them a screen too early.

So I need to devise a way to notify the master clip that the current unit's assets are loaded. When a user clicks on a new unit to view the preloader needs to ask, have I already loaded all the assets for this unit? if not, show a 'loading' cycle...if so, show the content.

Having said all this and outlined a lable-based navigation of assets, allow me to shift gears. This approach works well for assets that are nothing more than staic visuals but I have lots of pre-existing swf that are interactive....the users have to match stuff, click stuff, rollover stuff, and so on.

I've decided this aspect of the project dictates that I load each visual into an attached clip instead of merely playing labels. The increased flexibility will be worth it.

So I need to devise a way that preloads a bunch of loadMovie actions. I'll have my preexisting .swfs and my assets level will have a loop that loads all the individual .swfs and, again, notifies _level0 that a given unit's worth of clips have finished loaded.

I started some code that metas something like this...

unitNum = 1;
holdUnit = Unit_1;

for (i=1; i < totalCount; i++){
//totalCount is number of screens/visuals of a given

  if (_root["Unit_" add i] == holdUnit){
//i'm still within the starting unit
      currentVis = _root["Visual_" add i];
      attachMovie("assetClip", visual, 39);
        loadMovie(visual, visual);
//I now have a clip that contains my asset
//responsive to clicks, drags and so on.
//least I _think I do.
//Problem is how to delay the loop until
//the this movie is has finished loaded
//before iterating the loop.

  } else {
   _level0["assetstatus" add holdUnit] = 1;

//I've finished loading all clips for the initial unit
//and notified _level0
   holdUnit = _root["Unit_" unitNum];
//of course, I still need to load the attached clip.

      currentVis = _root["Visual_" add i];
      attachMovie("assetClip", visual, 39);
        loadMovie(visual, visual);

I'm seeking verification of the soundness of this approach, optimizations, and above all...a way to delay the above loop so there are not a couple dozen 'loadMovie' methods pending at one time.

At this point I just don't think it's worth your effort to tear into the .flas and there's enough site-sensitive stuff in the loadVariables that a bad apple could hack me to kingdom come that I'm hesitant to publish them. Let me know on a case-by-case basis if you feel the need to see more.

Question by:juststeve
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 7069219
currentVis = _root["Visual_" add i];

_level0["assetstatus" add holdUnit] = 1;

I don't know what this code is supposed to do.

I would try this

mRef - eval("_root.Visual_" add i)

Expert Comment

ID: 7069220
also I can send you an fla that might help

Expert Comment

ID: 7082897
send the FLA to me too, i will look into the matter
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 7086243
um I need an email address to do that.

Expert Comment

ID: 7094870
please send me too fla file, email is 'rotdir@hotmail.com'

Expert Comment

ID: 7095857
ssdesign what is you email?

Author Comment

ID: 7326230
This turned into one of those typical Flash projects where one problem spawed a few different solutions, each of which spawed a few more problems. I appreciate the requests to review FLA but the tangled web of the project (and the then management outlook) just didn't make that practical.

The code included here has lots of project specific elements but anyone needing to do something similar (pre-load a dynamic list of swf) should be able to adapt it.

It comes in 2 parts; a function that's fired after the list of swfs to be preloaded is initialized; 2) clip events within a blank container clip that duplicates itself, fires a loadMovie against the current swf, checks the load status, when loaded...calls the original function again.

good luck

//FUNCTION loadNext:
// based on:
// Feb 6th, 2002
// Sequential Preloader BETA 2 by Jesse Stratford
// www.actionscript.org, jesse@actionscript.org
// Modified
// sjh
// 6/20/2002
// this function interacts with the 'onClipEvent's of the
// instance named 'container' to loop thru all records returned by
// buildvisuals.asp. At each loop container clip is duplicated;
// new instance is named with the 'vVisuals' field (also matches
// the timeline lable); The loadMovie is called to import the current
// [vVisual].swf into it.
// Now the clip events (on the duplcated clip) need to monitor
// the bytesloaded.  A var named 'load+vVisual instancename'
// is set to true which engages the clip event that monitor
// bytes loaded. Once the clip events determine the '.swf' has loaded
// it sets that same var to false and calls the loadNext function
// again to continue on to the next clip.

// The final part of the function has a series of if tests that
// determine if all graphics for a given unit have loaded.

function loadNext () {
//var count = _root.count;
//account for authoring mode or
// production mode
 if (this._root == _level0){
  listofswf =  _root["vVisual_" add count] add ".swf";
 } else {
  listofswf = _root.subDir add _root["vVisual_" add count] add ".swf";
//test if all graphics for unit have loaded.
        if (count == _level0.holder.unitCount1){
           _level0.myLevelStatus.unit1 = 1;
        if (count == _level0.holder.unitCount2){
           _level0.myLevelStatus.unit2 = 1;
        if (count == _level0.holder.unitCount3){
           _level0.myLevelStatus.unit3 = 1;
        if (count == _level0.holder.unitCount4){
           _level0.myLevelStatus.unit4 = 1;
        if (count == _level0.holder.unitCount5){
           _level0.myLevelStatus.unit5 = 1;
        if (count == _level0.holder.unitCount6){
           _level0.myLevelStatus.unit6 = 1;

// instance name for the next container MC
  var newName = _root["vVisual_" add count];
//trace (newName);
  if (count-1 < numMoviesToLoad) {
   // if there are still movies which need loading

      if (_root[newName].isLoaded()){
        //trace ("skipped: " add listofswf);
      } else {
      // duplicate the container MC
            _root.container.duplicateMovieClip(newName, count);

      // load the next movie in the sequence into the new container
            loadMovie (listofswf, newName);

      // we are now preloading a new movie, set the var to True
            _root["load"+newName] = true;

onClipEvent (enterFrame) {
      // if this movie needs preloading

if (_level40.activeClip == this._name){

 this._visible = true;
       this._x = _level40.clip_x;
       this._y = _level40.clip_y;
  this._xscale = _level40.clip_xscale;
  this._yscale = _level40.clip_yscale;

} else {
 this._visible = false;

      if (_root["load"+this._name]) {
            // has the loadMovie command been processed yet?

            if (total_bytes == null) {
                  total_bytes = this.getBytesTotal();
            } else {
                  // controll bar - standard % preloader code
                  loaded_bytes = this.getBytesLoaded();
                  remaining_bytes = total_bytes-loaded_bytes;
                  percent_done = int((loaded_bytes/total_bytes)*100);
                  // _root.bar.gotoAndStop(percent_done);
                  // if loading is complete
                  if (percent_done>95) {
//                        trace ("fully loaded:" add this._name );
                      _visible = 0;
                        // not loading this one any more, load the next
                        //_root["load"+this._name] = false;
                        delete _parent["load"+this._name];
onClipEvent (data) {

    _visible = 0;

Accepted Solution

Netminder earned 0 total points
ID: 7326789
Per request, points refunded and question closed.

CS Moderator

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question