Skip to main content
Known Participant
March 23, 2011
Question

MovieClipLoader and checking whether clip was previously loaded

  • March 23, 2011
  • 2 replies
  • 519 views

Hi,

I'm using a preloader and MovieClipLoader to seemingly good effect and I have an ending sequence to my preloader where it plays out once the target clip is loaded. The ending sequence features within the preloader itself (preloader_mc.endingClip). preloader_mc plays through its frames with:

function onLoadProgress(target, loadedBytes, totalBytes){
target.stop();
target._visible = false;
var StepUpBytes = totalBytes/100;
stepFrame = Math.floor(loadedBytes/StepUpBytes);
if(stepFrame<1){
  stepFrame = 1;
}
preloader_mc.gotoAndStop(stepFrame+1); 
}

until it gets to 100% and then gets to a frame telling endingClip to play. All good unless the target clip is already loaded. Then what happens is that the preloader jumps to 100% and only plays the ending sequence. I would like to have a way of checking to see if the target clip has already been loaded so as to avoid displaying only this ending portion of the preloader.

In onLoadProgress I tried:

if((loadedBytes == totalBytes) && (target._width > 0)){
  preloader_mc.removeMovieClip();
}

This isn't working but I'm confused because for each of my targets I have an empty clip and when a new one is loaded, the current one is made _visible = false. I therefore thought the (target._width > 0) bit would work since the empty clip would already house the target? Trace returns zero for width value and returns different values for loadedBytes and totalBytes even if I revisit a freshly loaded clip.

The loadClip is triggered by an onPress event as described here:

navMenu.navClip.Section3But.onPress = function  () {
startPreload("flash/construction.swf");
function startPreload(url){
  loader_mcl.loadClip(url, ConstructionClip);
    }
this.enabled = false;
onEnterFrame = function (){
  PropDevClip._visible=false;
  ProjManClip._visible=false;
  DesignClip._visible=false;
  delete onEnterFrame;
}

This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
March 23, 2011
var stepFrame1:Number=1:

function onLoadProgress(target, loadedBytes, totalBytes){
target.stop();
target._visible = false;
var StepUpBytes = totalBytes/100;
stepFrame = 1+Math.floor(loadedBytes/StepUpBytes);
if(stepFrame<1){
  stepFrame = 2;
}

stepFrame1++;
preloader_mc.gotoAndStop(Math.min(stepFrame,stepFrame1); 

if(loadedBytes==totalBytes){

preloader_mc.play();

}

}


Known Participant
March 25, 2011

HI kglad,

Thanks for the help on this one but I decided to go with a different method in the end since the target clips are relatively small so I went with a simple timing method where if the target is loaded within 500ms (not likely in my part of the world) or obviously if it's already loaded, the visual preloader is not visible since it isn't really needed.

OnPress calls:

function startTimer(){
_global.startingTime = new Date();
}

Then within onLoadComplete, I have:

var elapsedTime = new Date().getTime() - startingTime.getTime();

     if(elapsedTime < 500){
     preloader_mc._visible = false;
     }else{
     preloader_mc._visible = true;
     }

kglad
Community Expert
Community Expert
March 23, 2011

you'll need to increment another variable each time onLoadProgress() is called and goto the min of that variable and stepFrame.  then when stepFrame reaches 100 (and your onLoadProgress is no longer called) apply the play() method to your preloader.

Known Participant
March 23, 2011

Hi kglad,

Thanks for your feedback. If you wouldn't mind, could you please elaborate on what you've said there.