开发者

Actionscript 3.0 sounds accounting

开发者 https://www.devze.com 2023-02-26 13:43 出处:网络
I have an Array of SoundChannels actively playing. When new sound is going to play, I append its SoundChannel to this array.

I have an Array of SoundChannels actively playing. When new sound is going to play, I append its SoundChannel to this array. I have to maintain such开发者_如何学JAVA an array in order to be able to stop all sounds at once.

I would like to remove sound channel from array when it finishes to prevent inifinite growing of my array. But when I catch e=Event.SOUND_COMPLETE, I have no information on sound channel. It is only possible to get Sound as e.target.

Actually, I can maintain Array of pairs (Sound, SoundChannel). But maybe there exists more light-weight solution?


you don't need that array :) you can just use SoundMixer.StopAll(); to stop every sound that is playing.

edit: since you want to stop all special sounds, i have a new solution. first, you create a new actionscript class and you add this code to it.

package
{
    import flash.display.DisplayObject;
    import flash.events.Event;
    import flash.media.SoundChannel;

    public class SpecialSoundChannel extends SoundChannel
    {
        var _parent:DisplayObject;

        public function SpecialSoundChannel(Parent:DisplayObject)
        {
            super();

            _parent = Parent;

            _parent.addEventListener("StopSpecialSound", stopChannel);
        }

        public function stopChannel(e:Event):void
        {
            //DO SOME OTHER STUFF YOU WANT DONE.

            stop();
        }
    }
}

every time you want to have a special sound added that is not music, you just do it like this:

var _sound:SpecialSoundChannel = new SpecialSoundChannel(this);

"this" is the class where you play and stop your soundchannel, which i am assuming is the same as where you create your soundchannel and therefore can call it "this". You add the following function to that class.

public function stopSpecialSounds():void
{
    var _e:Event = new Event("StopSpecialSound");
    dispatchEvent(_e);
}

if you want to stop all special sounds, you just call for this last function.

0

精彩评论

暂无评论...
验证码 换一张
取 消