|
|||||||
| Tutorials:flash:actionscript:basic_preloader_2 | ||||
|
Basic Preloader by PineappleClock Add a movieclip to your stage, then click on the movieclip and enter this actionscript: onClipEvent(load) { //this part gets executed once, when the movieclip loads. stop(); //this stops the movie from playing. } onClipEvent(enterFrame) { if (_root.getBytesLoaded() == _root.getBytesTotal()) { //execute this part if the movie is loaded play(); } } This code is fine, but it starts the movie as soon as it loads. Usually you will want a button of some sort in order to allow the user to start the movie manually. Preloader with precentage display Create a movieclip, and a dynamic text object. Name the dynamic text object loadpercent and place it on the stage. onClipEvent(load) { stop(); //this stops the movie from playing. } onClipEvent(enterFrame) { if (_root.getBytesLoaded() == _root.getBytesTotal()) { //execute this part if the movie is loaded play(); } else { var loaded = _root.getBytesLoaded() / _root.getBytesTotal(); _root.loadpercent.text = String(Math.round(loaded * 100)) + "%"; } } |