a staggered preloader

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 http://216.64.209.105/comp/ 

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...

FRAMEACTION
unitNum = 1;
holdUnit = Unit_1;

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

  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 {
   unitNum++;
   _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.

thankx
--steve...
juststeveAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

stef4sCommented:
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)
     
stef4sCommented:
also I can send you an fla that might help
ssdesignCommented:
send the FLA to me too, i will look into the matter
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

stef4sCommented:
um I need an email address to do that.
rootdirCommented:
stef4s
please send me too fla file, email is 'rotdir@hotmail.com'
thanks
stef4sCommented:
ssdesign what is you email?
juststeveAuthor Commented:
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:
//           AN ASSET PRELOADER
// 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;
_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);
          loadNext();
      } 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;
                        gotoAndStop(1);
                        // not loading this one any more, load the next
                        //_root["load"+this._name] = false;
                        delete _parent["load"+this._name];
                        _root.loadNext();
                  }
            }
      }
}
onClipEvent (data) {

    _visible = 0;
    gotoAndStop(1);
}
NetminderCommented:
Per request, points refunded and question closed.

Netminder
CS Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.