Sound Manager

i been using the Sound Manager from Matt Przybylski
for a while and added some little updates:
first make it work with the latest TweenLite Framework and to do that, you just need to make these changes:

firts, change TweenLite package from:

import gs.TweenLite;

to:

import com.greensock.TweenLite;

second, activate the VolumePlugin:

import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.VolumePlugin;

and in the Constructor, add this line:

TweenPlugin.activate([VolumePlugin]);

and that’s it, is all you need to make it work with TweenLite.

then, i added two functions to extend functionality

public function addSound($id:String):Boolean
{
	return addLibrarySound(getDefinitionByName($id), $id);
}
 
public function addMultiplesSounds(value:Array):void
{
	for each( var name_str:String in value) {
		addSound(name_str);
	}
}

the addSound function works the same as the addLibrarySound function
only hides the getDefinitionByName call (need it to create the sound item class) and sets the name id equals to the linkage id.

instead of using:

import com.reintroducing.sound.SoundManager;
import flash.utils.getDefinitionByName;
 
var manageSound:SoundManager=SoundManager.getInstance();
manageSound.addLibrarySound(getDefinitionByName("loop"), "loop");
manageSound.playSound("loop", 0, 0, 999);

just do this:

import com.reintroducing.sound.SoundManager;
 
var manageSound:SoundManager=SoundManager.getInstance();
manageSound.addSound("loop");
manageSound.playSound("loop", 0, 0, 999);

and the addMultiplesSounds function adds the functionality to create multiples sounds from the passed Array.
so you can do this:

i’d like to put all the sounds id’s in a Class, just to avoid misspells

package
{
	public class Sounds
	{
		static public const LOOP_SOUND = "LoopSound";
		static public const CLICK_SOUND01 = "ClickSound01";
		static public const CLICK_SOUND02 = "ClickSound02";
	}
}

and then just referring by the variable name

import com.reintroducing.sound.SoundManager;
 
var manageSound:SoundManager=SoundManager.getInstance();
manageSound.addMultiplesSounds([Sounds.LOOP_SOUND, Sounds.CLICK_SOUND01, Sounds.CLICK_SOUND02]);
manageSound.playSound(Sounds.LOOP_SOUND, 0, 0, 999);
manageSound.playSound(Sounds.CLICK_SOUND01);

download the final class here

for more information about how to use the SoundManager Class see here

This entry was posted in AS3 and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. derek knox
    Posted 6 May 2010 at 12:47 | Permalink

    Nice, thanks. Definitely could have figured this out, but just googled real quick to see if he had an updated version and stumbled on this. So thanks, have a good one.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*