- Home
- Tutorials
- Flash
- Intermediate
- Creating preoloaders for the attachSound Method
Creating preoloaders for the attachSound Method
This article has been added to your 'Favorites' list.

Page 2 of 2
Guy Watson
This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via support AT actionscript DOT org.
View all articles by Guy WatsonNow for the preloader:
Inside of your main movie, create a new movieclip and place it on the frame that you want your sound to start loading,from your library.
Select the movieclip on the main timeline and right-click, choose actions, then copy and paste this script into the actions window:
onClipEvent(load){
loadMovieNum("sound.swf",1)
}
onClipEvent(enterFrame){
percentloaded=Math.floor(_level1.getBytesLoaded()/_level1.getBytesTotal()*100)
percentdisplay=percentloaded + "%"
if(percentloaded == 100 && !initialized){
_level1.mysound()
initialized=true
_visible=false
}
}
initialized=true;
If you dont want to display a petcentage then remove the line which says:
percentdisplay=percentloaded + "%";
Also inside of this movieclip you should create your loading sound animation which will play only while the sound.swf file is loading, this is easily accomplished by setting the visiblity of the movieclip to zero when the sound.swf file has loaded:
_visible=false;
Some people have told me that sound doesnt play on any other level than the main movie(_level0), actually it does, the sound object (new Sound()) has an optional paramter in which you can specify a timeline, the timeline can be a movieclip, a level or _root:
mysoundobj=new Sound(_root);
I hope this was of some use to somebody, if not then nevermind. Happy flashing peoples!

