Advertisement
Scearezt

[AS2] Sound And Music

May 3rd, 2011
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //VERSION: V2.0 EXTENDED WITH LOOP BOOLEAN
  2. //FREE TO USE! NO NEED TO GIVE CREDIT!
  3. //SOUND AND MUSIC
  4. SFX = true;
  5. sss_loopSound;
  6. MUSIC = true;
  7. firstMusic = 0;
  8. this.createEmptyMovieClip("m0",100);
  9. mm0 = new Sound(m0);
  10. mm0.attachSound("bg0");
  11. mm0.onSoundComplete = function() {
  12.     mm0.start();
  13. };
  14.  
  15. //PLAY ANY SOUND ONCE OR LOOP!
  16. function playSound(id:String, vol:Number, loopVersion:Boolean) {
  17.     if (SFX) {
  18.         if (!loopVersion) {
  19.             this.createEmptyMovieClip("sss" + soundNum,10500 + soundNum);
  20.             var __reg2 = new Sound(this["sss" + soundNum]);
  21.             __reg2.attachSound(id);
  22.             __reg2.setVolume(vol);
  23.             __reg2.start();
  24.             soundNum >= 30 ? (soundNum = 0) : soundNum++;
  25.         } else {
  26.             if (!sss_loopVersion) {
  27.                 this.createEmptyMovieClip("sss_loopVersion",10531);
  28.                 sss_loopSound = new Sound(this["sss_loopVersion"]);
  29.                 sss_loopSound.attachSound(id);
  30.                 sss_loopSound.setVolume(vol);
  31.                 sss_loopSound.start();
  32.             }
  33.             sss_loopSound.onSoundComplete = function() {
  34.                 sss_loopSound.start();
  35.             };
  36.         }
  37.     }
  38. }
  39. //USAGE FOR LOOP:
  40. if (...condition) {
  41.         playSound("mySound",100,true);
  42.         //Linkage Name, Volume, is it for loop or not.
  43.     } else {
  44.                 if(sss_loopVersion){
  45.             sss_loopSound.stop();
  46.             sss_loopVersion.removeMovieClip();
  47.         }
  48.     }
  49. }
  50.  
  51. //onEnterFrame function: place this into your onEnterFrame = function(){}
  52. firstMusic == 0 ? (mm0.start(), firstMusic=1) : null;
  53. MUSIC ? mm0.setVolume(40) : mm0.setVolume(0);
  54. //if the music boolean is true then set the music's volume to 40 else set it to 0!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement