/** * com.sekati.data.SoundCenter * @version 1.1.0 * @author jason m horwitz | sekati.com * Copyright (C) 2007 jason m horwitz, Sekat LLC. All Rights Reserved. * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php * * extended from on ca.nectere.dllFactory.SoundFactory */ import com.sekati.core.CoreObject; import com.sekati.core.FWDepth; import com.sekati.math.MathBase; import com.sekati.utils.ClassUtils; /** * Centralized Sound management solves issues calling linked sounds from dll's */ class com.sekati.data.SoundCenter extends CoreObject { private static var _instance:SoundCenter; private var _holder:MovieClip; private var _gSound:Sound; private var _gMute:Boolean; private var _gVolume:Number; private var _gPan:Number; /** * Singleton Private Constructor */ private function SoundCenter() { super( ); _holder = ClassUtils.createEmptyMovieClip( com.sekati.display.BaseClip, _root, "__SoundCenter__", {_depth: FWDepth.SoundCenter} ); //no param means it'll affect the whole application _gSound = new Sound( ); _gMute = false; } /** * Singleton Accessor * @return SoundManager */ public static function getInstance():SoundCenter { if (!_instance) _instance = new SoundCenter( ); return _instance; } /** * shorthand singleton accessor getter */ public static function get $():SoundCenter { return SoundCenter.getInstance( ); } /** * returns the holder clip so we can load the DLL swf in * @return MovieClip */ public function getHolder():MovieClip { return _holder; } /** * returns the global volume setting * @return Number */ public function getVolume():Number { return _gVolume; } /** * sets the global volume * @param n (Number) 0 to 100 * @return Void */ public function setVolume(n:Number):Void { _gVolume = MathBase.constrain( n, 0, 100 ); _gSound.setVolume( _gVolume ); } /** * returns the global pan settings * @return Number */ public function getPan():Number { return _gPan; } /** * sets the global pan * @param n (Number) -100 to 100 */ public function setPan(n:Number):Void { _gPan = MathBase.constrain( n, -100, 100 ); _gSound.setPan( _gPan ); } /** * play a sound * @param linkage (String) linkage id for sound * @param v (Number) optional sound-specific volume (else global volume from setVolume is used) * @param p (Number) optional sound-specific pan (else global pan from setPan is used) * @param loops (Number) number of times to play sound * @param msOffset (Number) miliseconds offset * @return Void */ public function play(linkage:String, v:Number, p:Number, loops:Number, msOffset:Number):Void { if (loops == null) { loops = 0; } if (msOffset == null) { msOffset = 0; } var s:Sound = new Sound( _holder ); s.attachSound( linkage ); if (v) { s.setVolume( v ); } if (p) { s.setPan( p ); } s.start( msOffset / 1000, loops ); } /** * toggle mute global application audio * @param isMute (Boolean) optional force state * @return Void */ public function mute(isMute:Boolean):Void { if (!_gMute || isMute) { _gSound.setVolume( 0 ); _gMute = true; } else if (_gMute || !isMute) { _gSound.setVolume( _gVolume ); _gMute = false; } } /** * Destroy singleton instance. * @return Void */ public function destroy():Void { _holder.destroy( ); delete _instance; super.destroy( ); } }