Posted By

nate63179 on 11/03/09


Tagged

flash preloader as3


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

iamgowan


Flash: preloader logic example


 / Published in: ActionScript 3
 

A method pulled from a Preloader class (vars _lastUpdate and _isComplete, _dotsExploded not included).

_lastUpdate = is the amount last sent to the preloader _isComplete = whether the preloader is finished _dotsExploded = an array of 10 falses (1/clip), as preloader advances each is set to true

This can be adapted for any preloader with 10 movieclips that need to do something every 10% loaded.

  1. /**
  2. * Updates the preload amount
  3. * @parmam percentLoaded 0-100 amount of load completed
  4. */
  5. public function update(percentLoaded:int = 0) : void
  6. {
  7. if (percentLoaded <= _lastUpdate || _isComplete) return;
  8. _lastUpdate = percentLoaded;
  9.  
  10. var currentActiveSeed:int = Math.round(percentLoaded) / 10;
  11. for (var i:int = 0; i < currentActiveSeed; i++) {
  12. var seed:MovieClip = getChildByName("dot" + String(i + 1)) as MovieClip;
  13. if (!_dotsExploded[i]) {
  14. _dotsExploded[i] = true;
  15. seed.gotoAndPlay(2);
  16. }
  17. }
  18.  
  19. if (percentLoaded == 100) {
  20. _isComplete = true;
  21. dispatchEvent( new PreloaderEvent( PreloaderEvent.COMPLETE, true, false));
  22. }
  23. //trace("Loaded " + percentLoaded);
  24. }

Report this snippet  

You need to login to post a comment.