1 Reply Latest reply on Jul 26, 2007 1:43 PM by Vitzkrieg

    Preloader interruption problem

    saunz
      I am using the following script to preload external .swf's in my sites. The problem is that when it is interrupted (another link is clicked). It makes the parent .swf freak out (it plays continuously through the entire file without paying attention to stop commands or anything else). Anyone have an idea how to fix this?

      stop();
      loadingBar._xscale = 1;
      var loadingCall:Number = setInterval(preloadSite, 50);
      function preloadSite():Void {
      var siteLoaded:Number = getBytesLoaded();
      var siteTotal:Number = getBytesTotal();
      var percentage:Number = Math.round(siteLoaded/siteTotal*100);
      loadingBar._xscale = percentage;
      percentDisplay.text = percentage + "%";
      if (siteLoaded >= siteTotal) {
      clearInterval(loadingCall);
      play();
      }
      }

      Here is the site it's used in: http://www.vanderhurdstudio.com
        • 1. Re: Preloader interruption problem
          Vitzkrieg
          You need to clear out the Interval that loadingCall is referencing to whenever another link is clicked. The loadingCall variable is set locally and is only a refence to the global Interval being set. What's happening when another link is clicked, is the local loadingCall variable is getting deleted/reset, but the global Interval still exists and is losing it's timeline reference. When this happens, the Interval will apply whatever commands are in the function passed to it (play() in this case) upon whatever timeline the Interval can find - the parent .swf that still exists. So when this preloader is interupted, the Interval is telling the parent .swf to play() every .050 seconds and creating the effect of playing continuously through the file without stopping - it is stopping, but being told to play again faster than you can notice the stop.