5 Replies Latest reply on Jun 26, 2010 11:16 PM by kglad

    Questions about this snippet of preloader ActionScript

    tom_servo3000

      I'm working on a flash template that uses the following code for its preloader.

       

       

      onClipEvent (load) {
          total = _root.getBytesTotal();
      }

       


      onClipEvent (enterFrame) {
          loaded = _root.getBytesLoaded();
          percent = int(loaded/total*100);
          text = percent+"%";
          gotoAndStop(percent);
          if (loaded == total) {
              _root.gotoAndPlay(2);
          }
      }

       

      2 things about it that I can't figure out:

       

      The variable 'total' was created inside the first block of code, yet how is it being accessed from the second block of code?  Wouldn't there be a variable scope issue there?

       

      Also, in the 2nd block of code, when viewing the actual script in Flash, the variable 'text' is highlighted in blue indicating that it is a keyword or something.  And the dynamic text field that's supposed to be connected to the value of the variable 'text' [percent + "%"] is simply named 'z', not 'text'.  Yet the whole thing still works fine.  Don't understand how.

       

      Thanks,

      David