Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash AS3项目的声音库_Flash_Actionscript 3_Audio - Fatal编程技术网

Flash AS3项目的声音库

Flash AS3项目的声音库,flash,actionscript-3,audio,Flash,Actionscript 3,Audio,我正在寻找一个好的和简单的as3库,可以帮助我管理我开发的Flash应用程序中的声音 我需要一个能容纳我声音的东西(不超过25),当我调用某些声音播放时,它应该播放。我建议 俄文文本,但代码清晰我建议 俄语文本,但代码清晰我使用“SoundManager”类处理所有声音。这是一个非常简单的库来处理声音 package { import com.greensock.TweenMax; import flash.events.Event; import flash.media

我正在寻找一个好的和简单的as3库,可以帮助我管理我开发的Flash应用程序中的声音

我需要一个能容纳我声音的东西(不超过25),当我调用某些声音播放时,它应该播放。

我建议 俄文文本,但代码清晰

我建议 俄语文本,但代码清晰

我使用“SoundManager”类处理所有声音。这是一个非常简单的库来处理声音

package
{
    import com.greensock.TweenMax;
    import flash.events.Event;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundLoaderContext;
    import flash.media.SoundTransform;
    import flash.net.URLRequest;
    import flash.utils.Dictionary;
    import flash.utils.getQualifiedClassName;

    /**
     * The SoundManager is a singleton that allows you to have various ways to control sounds in your project.
     * <p />
     * The SoundManager can load external or library sounds, pause/mute/stop/control volume for one or more sounds at a time,
     * fade sounds up or down, and allows additional control to sounds not readily available through the default classes.
     * <p />
     * This class is dependent on TweenLite (http://www.tweenlite.com) to aid in easily fading the volume of the sound.
     *
     * @author Matt Przybylski [http://www.reintroducing.com]
     * @version 1.0
     */

     /**
     * 
     * Modified by Oliver-Bogdan Iancu
     * 
     */

    public class SoundManager
    {
//- PRIVATE & PROTECTED VARIABLES -------------------------------------------------------------------------
        // singleton instance
        private static var _instance:SoundManager;
        private static var _allowInstance:Boolean;
        private var _soundsDict:Dictionary;
        private var _sounds:Array;
        private var $callBackFun:Function;

//- PUBLIC & INTERNAL VARIABLES ---------------------------------------------------------------------------
//- CONSTRUCTOR -------------------------------------------------------------------------------------------
        // singleton instance of SoundManager
        public static function getInstance():SoundManager
        {
            if (SoundManager._instance == null)
            {
                SoundManager._allowInstance = true;
                SoundManager._instance = new SoundManager();
                SoundManager._allowInstance = false;
            }
            return SoundManager._instance;
        }
        public function SoundManager()
        {
            this._soundsDict = new Dictionary(true);
            this._sounds = new Array();
            if (!SoundManager._allowInstance)
            {
                throw new Error("Error: Use SoundManager.getInstance() instead of the new keyword.");
            }
        }
//- PRIVATE & PROTECTED METHODS ---------------------------------------------------------------------------
//- PUBLIC & INTERNAL METHODS -----------------------------------------------------------------------------
        /**
         * Adds a sound from the library to the sounds dictionary for playing in the future.
         *
         * @param $linkageID The class name of the library symbol that was exported for AS
         * @param $name The string identifier of the sound to be used when calling other methods on the sound
         *
         * @return Boolean A boolean value representing if the sound was added successfully
         */
        public function addLibrarySound($linkageID:*, $name:String):Boolean
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                if (this._sounds[i].name == $name) return false;
            }
            var sndObj:Object = new Object();
            var snd:Sound = $linkageID;
            sndObj.name = $name;
            sndObj.sound = snd;
            sndObj.channel = new SoundChannel();
            sndObj.position = 0;
            sndObj.paused = true;
            sndObj.volume = 1;
            sndObj.startTime = 0;
            sndObj.loops = 0;
            sndObj.pausedByAll = false;
            this._soundsDict[$name] = sndObj;
            this._sounds.push(sndObj);
            return true;
        }
        /**
         * Adds an external sound to the sounds dictionary for playing in the future.
         *
         * @param $path A string representing the path where the sound is on the server
         * @param $name The string identifier of the sound to be used when calling other methods on the sound
         * @param $buffer The number, in milliseconds, to buffer the sound before you can play it (default: 1000)
         * @param $checkPolicyFile A boolean that determines whether Flash Player should try to download a cross-domain policy file from the loaded sound's server before beginning to load the sound (default: false)
         *
         * @return Boolean A boolean value representing if the sound was added successfully
         */
        public function addExternalSound($path:String, $name:String, $buffer:Number = 1000, $checkPolicyFile:Boolean = false):Boolean
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                if (this._sounds[i].name == $name) return false;
            }
            var sndObj:Object = new Object();
            var snd:Sound = new Sound(new URLRequest($path), new SoundLoaderContext($buffer, $checkPolicyFile));
            sndObj.name = $name;
            sndObj.sound = snd;
            sndObj.channel = new SoundChannel();
            sndObj.position = 0;
            sndObj.paused = true;
            sndObj.volume = 1;
            sndObj.startTime = 0;
            sndObj.loops = 0;
            sndObj.pausedByAll = false;
            this._soundsDict[$name] = sndObj;
            this._sounds.push(sndObj);
            return true;
        }
        /**
         * Removes a sound from the sound dictionary.  After calling this, the sound will not be available until it is re-added.
         *
         * @param $name The string identifier of the sound to remove
         *
         * @return void
         */
        public function removeSound($name:String):void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                if (this._sounds[i].name == $name)
                {
                    this._sounds[i] = null;
                    this._sounds.splice(i, 1);
                }
            }
            delete this._soundsDict[$name];
        }
        /**
         * Removes all sounds from the sound dictionary.
         *
         * @return void
         */
        public function removeAllSounds():void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                this._sounds[i] = null;
            }
            this._sounds = new Array();
            this._soundsDict = new Dictionary(true);
        }
        /**
         * Plays or resumes a sound from the sound dictionary with the specified name.
         *
         * @param $name The string identifier of the sound to play
         * @param $volume A number from 0 to 1 representing the volume at which to play the sound (default: 1)
         * @param $startTime A number (in milliseconds) representing the time to start playing the sound at (default: 0)
         * @param $loops An integer representing the number of times to loop the sound (default: 0)
         *
         * @return void
         */
        public function playSound($name:String, $volume:Number = 1, $startTime:Number = 0, $loops:int = 0, $callBackFun:Function = null):SoundChannel
        {

            this.$callBackFun = $callBackFun;
            var snd:Object = this._soundsDict[$name];
            snd.volume = $volume;
            snd.startTime = $startTime;
            snd.loops = $loops;
            if (snd.paused)
            {
                snd.channel = snd.sound.play(snd.position, snd.loops, new SoundTransform(snd.volume));
            }
            else
            {
                snd.channel = snd.sound.play($startTime, snd.loops, new SoundTransform(snd.volume));
            }
            if ($callBackFun != null)
                snd.channel.addEventListener(Event.SOUND_COMPLETE, onSoundCompleteEvent);
            snd.paused = false;

            return snd.channel;
        }

        private function onSoundCompleteEvent(e:Event):void 
        {
            $callBackFun.call();
        }
        /**
         * Stops the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return void
         */
        public function stopSound($name:String):void
        {
            var snd:Object = this._soundsDict[$name];
            snd.paused = true;
            snd.channel.stop();
            snd.position = snd.channel.position;
        }
        /**
         * Pauses the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return void
         */
        public function pauseSound($name:String):void
        {
            var snd:Object = this._soundsDict[$name];
            snd.paused = true;
            snd.position = snd.channel.position;
            snd.channel.stop();
        }
        /**
         * Plays all the sounds that are in the sound dictionary.
         *
         * @param $useCurrentlyPlayingOnly A boolean that only plays the sounds which were currently playing before a pauseAllSounds() or stopAllSounds() call (default: false)
         *
         * @return void
         */
        public function playAllSounds($useCurrentlyPlayingOnly:Boolean = false):void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                var id:String = this._sounds[i].name;
                if ($useCurrentlyPlayingOnly)
                {
                    if (this._soundsDict[id].pausedByAll)
                    {
                        this._soundsDict[id].pausedByAll = false;
                        this.playSound(id);
                    }
                }
                else
                {
                    this.playSound(id);
                }
            }
        }
        /**
         * Stops all the sounds that are in the sound dictionary.
         *
         * @param $useCurrentlyPlayingOnly A boolean that only stops the sounds which are currently playing (default: true)
         *
         * @return void
         */
        public function stopAllSounds($useCurrentlyPlayingOnly:Boolean = true):void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                var id:String = this._sounds[i].name;
                if ($useCurrentlyPlayingOnly)
                {
                    if (!this._soundsDict[id].paused)
                    {
                        this._soundsDict[id].pausedByAll = true;
                        this.stopSound(id);
                    }
                }
                else
                {
                    this.stopSound(id);
                }
            }
        }
        /**
         * Pauses all the sounds that are in the sound dictionary.
         *
         * @param $useCurrentlyPlayingOnly A boolean that only pauses the sounds which are currently playing (default: true)
         *
         * @return void
         */
        public function pauseAllSounds($useCurrentlyPlayingOnly:Boolean = true):void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                var id:String = this._sounds[i].name;
                if ($useCurrentlyPlayingOnly)
                {
                    if (!this._soundsDict[id].paused)
                    {
                        this._soundsDict[id].pausedByAll = true;
                        this.pauseSound(id);
                    }
                }
                else
                {
                    this.pauseSound(id);
                }
            }
        }
        /**
         * Fades the sound to the specified volume over the specified amount of time.
         *
         * @param $name The string identifier of the sound
         * @param $targVolume The target volume to fade to, between 0 and 1 (default: 0)
         * @param $fadeLength The time to fade over, in seconds (default: 1)
         *
         * @return void
         */
        public function fadeSound($name:String, $targVolume:Number = 0, $fadeLength:Number = 1):void
        {
            var fadeChannel:SoundChannel = this._soundsDict[$name].channel;
            TweenMax.to(fadeChannel , $fadeLength, { volume: $targVolume } );
        }

        /**
         * Mutes the volume for all sounds in the sound dictionary.
         *
         * @return void
         */
        public function muteAllSounds():void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                var id:String = this._sounds[i].name;
                this.setSoundVolume(id, 0);
            }
        }
        /**
         * Resets the volume to their original setting for all sounds in the sound dictionary.
         *
         * @return void
         */
        public function unmuteAllSounds():void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                var id:String = this._sounds[i].name;
                var snd:Object = this._soundsDict[id];
                var curTransform:SoundTransform = snd.channel.soundTransform;
                curTransform.volume = snd.volume;
                snd.channel.soundTransform = curTransform;
            }
        }
        /**
         * Sets the volume of the specified sound.
         *
         * @param $name The string identifier of the sound
         * @param $volume The volume, between 0 and 1, to set the sound to
         *
         * @return void
         */
        public function setSoundVolume($name:String, $volume:Number):void
        {
            var snd:Object = this._soundsDict[$name];
            var curTransform:SoundTransform = snd.channel.soundTransform;
            curTransform.volume = $volume;
            snd.channel.soundTransform = curTransform;
        }
        /**
         * Gets the volume of the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return Number The current volume of the sound
         */
        public function getSoundVolume($name:String):Number
        {
            return this._soundsDict[$name].channel.soundTransform.volume;
        }
        /**
         * Gets the position of the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return Number The current position of the sound, in milliseconds
         */
        public function getSoundPosition($name:String):Number
        {
            return this._soundsDict[$name].channel.position;
        }
        /**
         * Gets the duration of the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return Number The length of the sound, in milliseconds
         */
        public function getSoundDuration($name:String):Number
        {
            return this._soundsDict[$name].sound.length;
        }
        /**
         * Gets the sound object of the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return Sound The sound object
         */
        public function getSoundObject($name:String):Sound
        {
            return this._soundsDict[$name].sound;
        }
        /**
         * Identifies if the sound is paused or not.
         *
         * @param $name The string identifier of the sound
         *
         * @return Boolean The boolean value of paused or not paused
         */
        public function isSoundPaused($name:String):Boolean
        {
            return this._soundsDict[$name].paused;
        }
        /**
         * Identifies if the sound was paused or stopped by calling the stopAllSounds() or pauseAllSounds() methods.
         *
         * @param $name The string identifier of the sound
         *
         * @return Number The boolean value of pausedByAll or not pausedByAll
         */
        public function isSoundPausedByAll($name:String):Boolean
        {
            return this._soundsDict[$name].pausedByAll;
        }
//- EVENT HANDLERS ----------------------------------------------------------------------------------------
//- GETTERS & SETTERS -------------------------------------------------------------------------------------
        public function get sounds():Array
        {
            return this._sounds;
        }
//- HELPERS -----------------------------------------------------------------------------------------------
        public function toString():String
        {
            return getQualifiedClassName(this);
        }
//- END CLASS ---------------------------------------------------------------------------------------------
    }
}
包
{
导入com.greensock.TweenMax;
导入flash.events.Event;
导入flash.media.Sound;
导入flash.media.SoundChannel;
导入flash.media.SoundLoaderContext;
导入flash.media.SoundTransform;
导入flash.net.URLRequest;
导入flash.utils.Dictionary;
导入flash.utils.getQualifiedClassName;
/**
*SoundManager是一个单独的组件,它允许您使用各种方法来控制项目中的声音。
*

*SoundManager可以加载外部或库中声音,一次暂停/静音/停止/控制一个或多个声音的音量, *淡入淡出声音向上或向下,并允许对默认类中不可用的声音进行额外控制。 *

*这个类依赖于TweenLite(http://www.tweenlite.com)有助于降低音量。 * *@作者马特·普兹比尔斯基[http://www.reintroducing.com] *@version 1.0 */ /** * *由Oliver Bogdan Iancu修改 * */ 公共类声音管理器 { //-私有和保护变量------------------------------------------------------------------------- //单例实例 私有静态var_实例:SoundManager; 私有静态变量_allowstance:Boolean; 私人语音:字典; 私有变量:数组; 私有变量$callBackFun:函数; //-公共和内部变量--------------------------------------------------------------------------- //-建造师------------------------------------------------------------------------------------------- //SoundManager的单例实例 公共静态函数getInstance():SoundManager { if(SoundManager.\u实例==null) { SoundManager.\u Allowistance=true; SoundManager._实例=新建SoundManager(); SoundManager.\u Allowistance=false; } 返回SoundManager.\u实例; } 公共职能经理() { 这是新字典(真); 这个。_sounds=new Array(); 如果(!SoundManager.\u allowInstance) { 抛出新错误(“错误:使用SoundManager.getInstance()而不是new关键字。”); } } //-私有和受保护的方法--------------------------------------------------------------------------- //-公共和内部方法----------------------------------------------------------------------------- /** *将库中的声音添加到声音词典中,以便将来播放。 * *@param$linkageID导出为的库符号的类名 *@param$name对声音调用其他方法时要使用的声音的字符串标识符 * *@return Boolean表示声音添加是否成功的布尔值 */ 公共函数addLibrarySound($linkageID:$name:String):布尔值 { 对于(var i:int=0;i我使用“SoundManager”类来处理所有声音。处理声音非常简单

package
{
    import com.greensock.TweenMax;
    import flash.events.Event;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundLoaderContext;
    import flash.media.SoundTransform;
    import flash.net.URLRequest;
    import flash.utils.Dictionary;
    import flash.utils.getQualifiedClassName;

    /**
     * The SoundManager is a singleton that allows you to have various ways to control sounds in your project.
     * <p />
     * The SoundManager can load external or library sounds, pause/mute/stop/control volume for one or more sounds at a time,
     * fade sounds up or down, and allows additional control to sounds not readily available through the default classes.
     * <p />
     * This class is dependent on TweenLite (http://www.tweenlite.com) to aid in easily fading the volume of the sound.
     *
     * @author Matt Przybylski [http://www.reintroducing.com]
     * @version 1.0
     */

     /**
     * 
     * Modified by Oliver-Bogdan Iancu
     * 
     */

    public class SoundManager
    {
//- PRIVATE & PROTECTED VARIABLES -------------------------------------------------------------------------
        // singleton instance
        private static var _instance:SoundManager;
        private static var _allowInstance:Boolean;
        private var _soundsDict:Dictionary;
        private var _sounds:Array;
        private var $callBackFun:Function;

//- PUBLIC & INTERNAL VARIABLES ---------------------------------------------------------------------------
//- CONSTRUCTOR -------------------------------------------------------------------------------------------
        // singleton instance of SoundManager
        public static function getInstance():SoundManager
        {
            if (SoundManager._instance == null)
            {
                SoundManager._allowInstance = true;
                SoundManager._instance = new SoundManager();
                SoundManager._allowInstance = false;
            }
            return SoundManager._instance;
        }
        public function SoundManager()
        {
            this._soundsDict = new Dictionary(true);
            this._sounds = new Array();
            if (!SoundManager._allowInstance)
            {
                throw new Error("Error: Use SoundManager.getInstance() instead of the new keyword.");
            }
        }
//- PRIVATE & PROTECTED METHODS ---------------------------------------------------------------------------
//- PUBLIC & INTERNAL METHODS -----------------------------------------------------------------------------
        /**
         * Adds a sound from the library to the sounds dictionary for playing in the future.
         *
         * @param $linkageID The class name of the library symbol that was exported for AS
         * @param $name The string identifier of the sound to be used when calling other methods on the sound
         *
         * @return Boolean A boolean value representing if the sound was added successfully
         */
        public function addLibrarySound($linkageID:*, $name:String):Boolean
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                if (this._sounds[i].name == $name) return false;
            }
            var sndObj:Object = new Object();
            var snd:Sound = $linkageID;
            sndObj.name = $name;
            sndObj.sound = snd;
            sndObj.channel = new SoundChannel();
            sndObj.position = 0;
            sndObj.paused = true;
            sndObj.volume = 1;
            sndObj.startTime = 0;
            sndObj.loops = 0;
            sndObj.pausedByAll = false;
            this._soundsDict[$name] = sndObj;
            this._sounds.push(sndObj);
            return true;
        }
        /**
         * Adds an external sound to the sounds dictionary for playing in the future.
         *
         * @param $path A string representing the path where the sound is on the server
         * @param $name The string identifier of the sound to be used when calling other methods on the sound
         * @param $buffer The number, in milliseconds, to buffer the sound before you can play it (default: 1000)
         * @param $checkPolicyFile A boolean that determines whether Flash Player should try to download a cross-domain policy file from the loaded sound's server before beginning to load the sound (default: false)
         *
         * @return Boolean A boolean value representing if the sound was added successfully
         */
        public function addExternalSound($path:String, $name:String, $buffer:Number = 1000, $checkPolicyFile:Boolean = false):Boolean
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                if (this._sounds[i].name == $name) return false;
            }
            var sndObj:Object = new Object();
            var snd:Sound = new Sound(new URLRequest($path), new SoundLoaderContext($buffer, $checkPolicyFile));
            sndObj.name = $name;
            sndObj.sound = snd;
            sndObj.channel = new SoundChannel();
            sndObj.position = 0;
            sndObj.paused = true;
            sndObj.volume = 1;
            sndObj.startTime = 0;
            sndObj.loops = 0;
            sndObj.pausedByAll = false;
            this._soundsDict[$name] = sndObj;
            this._sounds.push(sndObj);
            return true;
        }
        /**
         * Removes a sound from the sound dictionary.  After calling this, the sound will not be available until it is re-added.
         *
         * @param $name The string identifier of the sound to remove
         *
         * @return void
         */
        public function removeSound($name:String):void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                if (this._sounds[i].name == $name)
                {
                    this._sounds[i] = null;
                    this._sounds.splice(i, 1);
                }
            }
            delete this._soundsDict[$name];
        }
        /**
         * Removes all sounds from the sound dictionary.
         *
         * @return void
         */
        public function removeAllSounds():void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                this._sounds[i] = null;
            }
            this._sounds = new Array();
            this._soundsDict = new Dictionary(true);
        }
        /**
         * Plays or resumes a sound from the sound dictionary with the specified name.
         *
         * @param $name The string identifier of the sound to play
         * @param $volume A number from 0 to 1 representing the volume at which to play the sound (default: 1)
         * @param $startTime A number (in milliseconds) representing the time to start playing the sound at (default: 0)
         * @param $loops An integer representing the number of times to loop the sound (default: 0)
         *
         * @return void
         */
        public function playSound($name:String, $volume:Number = 1, $startTime:Number = 0, $loops:int = 0, $callBackFun:Function = null):SoundChannel
        {

            this.$callBackFun = $callBackFun;
            var snd:Object = this._soundsDict[$name];
            snd.volume = $volume;
            snd.startTime = $startTime;
            snd.loops = $loops;
            if (snd.paused)
            {
                snd.channel = snd.sound.play(snd.position, snd.loops, new SoundTransform(snd.volume));
            }
            else
            {
                snd.channel = snd.sound.play($startTime, snd.loops, new SoundTransform(snd.volume));
            }
            if ($callBackFun != null)
                snd.channel.addEventListener(Event.SOUND_COMPLETE, onSoundCompleteEvent);
            snd.paused = false;

            return snd.channel;
        }

        private function onSoundCompleteEvent(e:Event):void 
        {
            $callBackFun.call();
        }
        /**
         * Stops the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return void
         */
        public function stopSound($name:String):void
        {
            var snd:Object = this._soundsDict[$name];
            snd.paused = true;
            snd.channel.stop();
            snd.position = snd.channel.position;
        }
        /**
         * Pauses the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return void
         */
        public function pauseSound($name:String):void
        {
            var snd:Object = this._soundsDict[$name];
            snd.paused = true;
            snd.position = snd.channel.position;
            snd.channel.stop();
        }
        /**
         * Plays all the sounds that are in the sound dictionary.
         *
         * @param $useCurrentlyPlayingOnly A boolean that only plays the sounds which were currently playing before a pauseAllSounds() or stopAllSounds() call (default: false)
         *
         * @return void
         */
        public function playAllSounds($useCurrentlyPlayingOnly:Boolean = false):void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                var id:String = this._sounds[i].name;
                if ($useCurrentlyPlayingOnly)
                {
                    if (this._soundsDict[id].pausedByAll)
                    {
                        this._soundsDict[id].pausedByAll = false;
                        this.playSound(id);
                    }
                }
                else
                {
                    this.playSound(id);
                }
            }
        }
        /**
         * Stops all the sounds that are in the sound dictionary.
         *
         * @param $useCurrentlyPlayingOnly A boolean that only stops the sounds which are currently playing (default: true)
         *
         * @return void
         */
        public function stopAllSounds($useCurrentlyPlayingOnly:Boolean = true):void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                var id:String = this._sounds[i].name;
                if ($useCurrentlyPlayingOnly)
                {
                    if (!this._soundsDict[id].paused)
                    {
                        this._soundsDict[id].pausedByAll = true;
                        this.stopSound(id);
                    }
                }
                else
                {
                    this.stopSound(id);
                }
            }
        }
        /**
         * Pauses all the sounds that are in the sound dictionary.
         *
         * @param $useCurrentlyPlayingOnly A boolean that only pauses the sounds which are currently playing (default: true)
         *
         * @return void
         */
        public function pauseAllSounds($useCurrentlyPlayingOnly:Boolean = true):void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                var id:String = this._sounds[i].name;
                if ($useCurrentlyPlayingOnly)
                {
                    if (!this._soundsDict[id].paused)
                    {
                        this._soundsDict[id].pausedByAll = true;
                        this.pauseSound(id);
                    }
                }
                else
                {
                    this.pauseSound(id);
                }
            }
        }
        /**
         * Fades the sound to the specified volume over the specified amount of time.
         *
         * @param $name The string identifier of the sound
         * @param $targVolume The target volume to fade to, between 0 and 1 (default: 0)
         * @param $fadeLength The time to fade over, in seconds (default: 1)
         *
         * @return void
         */
        public function fadeSound($name:String, $targVolume:Number = 0, $fadeLength:Number = 1):void
        {
            var fadeChannel:SoundChannel = this._soundsDict[$name].channel;
            TweenMax.to(fadeChannel , $fadeLength, { volume: $targVolume } );
        }

        /**
         * Mutes the volume for all sounds in the sound dictionary.
         *
         * @return void
         */
        public function muteAllSounds():void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                var id:String = this._sounds[i].name;
                this.setSoundVolume(id, 0);
            }
        }
        /**
         * Resets the volume to their original setting for all sounds in the sound dictionary.
         *
         * @return void
         */
        public function unmuteAllSounds():void
        {
            for (var i:int = 0; i <this._sounds.length; i++)
            {
                var id:String = this._sounds[i].name;
                var snd:Object = this._soundsDict[id];
                var curTransform:SoundTransform = snd.channel.soundTransform;
                curTransform.volume = snd.volume;
                snd.channel.soundTransform = curTransform;
            }
        }
        /**
         * Sets the volume of the specified sound.
         *
         * @param $name The string identifier of the sound
         * @param $volume The volume, between 0 and 1, to set the sound to
         *
         * @return void
         */
        public function setSoundVolume($name:String, $volume:Number):void
        {
            var snd:Object = this._soundsDict[$name];
            var curTransform:SoundTransform = snd.channel.soundTransform;
            curTransform.volume = $volume;
            snd.channel.soundTransform = curTransform;
        }
        /**
         * Gets the volume of the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return Number The current volume of the sound
         */
        public function getSoundVolume($name:String):Number
        {
            return this._soundsDict[$name].channel.soundTransform.volume;
        }
        /**
         * Gets the position of the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return Number The current position of the sound, in milliseconds
         */
        public function getSoundPosition($name:String):Number
        {
            return this._soundsDict[$name].channel.position;
        }
        /**
         * Gets the duration of the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return Number The length of the sound, in milliseconds
         */
        public function getSoundDuration($name:String):Number
        {
            return this._soundsDict[$name].sound.length;
        }
        /**
         * Gets the sound object of the specified sound.
         *
         * @param $name The string identifier of the sound
         *
         * @return Sound The sound object
         */
        public function getSoundObject($name:String):Sound
        {
            return this._soundsDict[$name].sound;
        }
        /**
         * Identifies if the sound is paused or not.
         *
         * @param $name The string identifier of the sound
         *
         * @return Boolean The boolean value of paused or not paused
         */
        public function isSoundPaused($name:String):Boolean
        {
            return this._soundsDict[$name].paused;
        }
        /**
         * Identifies if the sound was paused or stopped by calling the stopAllSounds() or pauseAllSounds() methods.
         *
         * @param $name The string identifier of the sound
         *
         * @return Number The boolean value of pausedByAll or not pausedByAll
         */
        public function isSoundPausedByAll($name:String):Boolean
        {
            return this._soundsDict[$name].pausedByAll;
        }
//- EVENT HANDLERS ----------------------------------------------------------------------------------------
//- GETTERS & SETTERS -------------------------------------------------------------------------------------
        public function get sounds():Array
        {
            return this._sounds;
        }
//- HELPERS -----------------------------------------------------------------------------------------------
        public function toString():String
        {
            return getQualifiedClassName(this);
        }
//- END CLASS ---------------------------------------------------------------------------------------------
    }
}
包
{
导入com.greensock.TweenMax;
导入flash.events.Event;
导入flash.media.Sound;
导入flash.media.SoundChannel;
导入flash.media.SoundLoaderContext;
导入flash.media.SoundTransform;
导入flash.net.URLRequest;
导入flash.utils.Dictionary;
导入flash.utils.getQualifiedClassName;
/**
*SoundManager是一个单独的组件,它允许您使用各种方法来控制项目中的声音。
*

*SoundManager可以加载外部或库中声音,一次暂停/静音/停止/控制一个或多个声音的音量, *淡入淡出声音向上或向下,并允许对默认类中不可用的声音进行额外控制。 *

*这个类依赖于TweenLite(http://www.tweenlite.com)有助于降低音量。 * *@作者马特·普兹比尔斯基[http://www.reintroducing.com] *@version 1.0 */ /** * *由Oliver Bogdan Iancu修改 * */ 公共类声音管理器 { //-私有和保护变量------------------------------------------------------------------------- //单例实例 私有静态var_实例:SoundManager; 私有静态变量_allowstance:Boolean; 私人语音:字典; 私有变量:数组; 私有变量$callBackFun:函数; //-公共和内部变量--------------------------------------------------------------------------- //-建造师------------------------------------------------------------------------------------------- //SoundManager的单例实例 公共静态函数getInstance():SoundManager { if(SoundManager.\u实例==null) { SoundManager.\u Allowistance=true; SoundManager._实例=新建SoundManager(); SoundManager.\u Allowistance=false; } 返回SoundManager.\u实例; } 公共职能经理() { 这是新字典(真); 这个。_sounds=new Array(); 如果(!SoundManager.\u allowInstance) {