Solved

a staggered preloader

Posted on 2002-06-09
8
406 Views
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 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...
0
Comment
Question by:juststeve
8 Comments
 
LVL 5

Expert Comment

by:stef4s
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)
     
0
 
LVL 5

Expert Comment

by:stef4s
ID: 7069220
also I can send you an fla that might help
0
 
LVL 7

Expert Comment

by:ssdesign
ID: 7082897
send the FLA to me too, i will look into the matter
0
 
LVL 5

Expert Comment

by:stef4s
ID: 7086243
um I need an email address to do that.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:rootdir
ID: 7094870
stef4s
please send me too fla file, email is 'rotdir@hotmail.com'
thanks
0
 
LVL 5

Expert Comment

by:stef4s
ID: 7095857
ssdesign what is you email?
0
 

Author Comment

by:juststeve
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:
//           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);
}
0
 
LVL 5

Accepted Solution

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

Netminder
CS Moderator
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now