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?

8 people have marked this snippet as a favorite

outbox
visuallyspun
jmontanino
SmpleJohn
THEPWN3R
enajenkins
aesthetics
loric


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 

Comments

RSS Icon Subscribe to comments
Posted By: Slugtaco on April 14, 2009

Is the "customanimation" referring to the "mcwith100frame_animation"?

I received this error when trying it.

1120: Access of undefined property custom_animation.

Posted By: chrisaiv on April 24, 2009

Your custom animation is a 100 Frame MovieClip with, in this case, an instance name of "mcwith100frameanmiation"

You need to login to post a comment.