We Recommend

Essential ActionScript 3.0 Essential ActionScript 3.0
The book focuses on the core language and object-oriented programming, but also adds a deep look at the centerpiece of Flash Player's new API: display programming. Enjoy hundreds of brand new pages covering exciting new language features, such as the DOM-based event architecture, E4X, and namespaces--all brimming with real-world sample code.


Posted By

chrisaiv on 02/08/08


Tagged

as3


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

outbox
visuallyspun


AS3: Custom Preloader


Published in: ActionScript 3 


Create a 100 frame MovieClip animation in companion with this code to create a preloader. Place the rest of your Flash application on the following Scene or Frame


  1. /***************************
  2. Event Handler
  3. ***************************/
  4. addEventListener(Event.ENTER_FRAME, loading);
  5.  
  6. /***************************
  7. Function
  8. ***************************/
  9. function loading(e:Event)
  10. {
  11. var bytestotal = stage.loaderInfo.bytesTotal;
  12. var bytesloaded = stage.loaderInfo.bytesLoaded;
  13. var percent = Math.round(bytesloaded * 100/bytestotal);
  14.  
  15. mc_with_100_frame_animation.gotoAndPlay(percent);
  16.  
  17. if (bytesloaded >= bytestotal)
  18. {
  19. gotoAndStop(2);
  20. removeEventListener(Event.ENTER_FRAME, loading);
  21. removeChild(custom_animation);
  22. }
  23. }
  24. stop();

Report this snippet 

You need to login to post a comment.