View Single Post
Codemonkey's Avatar Codemonkey Codemonkey is offline Super Moderator 2006-11-05 #17 Old  
015a - Creating sounds
 
To create new sound objects that you can individually control, use can use the following function:

ActionScript Code:
  1. function loadSound(sound:String, vol:Number):Object {
  2.     // create sound container
  3.     var d:Number = _root.getNextHighestDepth();
  4.     var emptyMC:MovieClip = _root.createEmptyMovieClip("empty" + d, d);
  5.     // create sound
  6.     var sound:Sound = new Sound(emptyMC);
  7.     sound.attachSound(sound);
  8.     sound.setVolume(vol);
  9.     return sound;
  10. }
Usage:

ActionScript Code:
  1. var gunshot:Sound = loadSound("gunshot", 100);
  2. var squeeky:Sound = loadSound("squeeky", 60);