0

我在音乐播放器中有四种不同的曲目(吉他、贝斯、鼓、人声)。它们都被命名为复选框,用于检查/取消选中当前可以听到哪一首曲目,并且我还有一个播放按钮可以开始。因此,当检查例如人声和吉他时,我只想听到这两种乐器以及贝司和鼓在后台静音播放。

问题是当我开始选中这两个框时,我无法在播放时更改其他框,因为状态是静态的,并且在点击框时不会动态更改。

只是我的代码的摘录,只有吉他和人声,以便于理解:

        var vocals:Sound = new Sound();
        var vocalsChannel:SoundChannel = new SoundChannel();
        var vocalsTransform = new SoundTransform();
        vocalsChannel.soundTransform = vocalsTransform;
        vocals.load(new URLRequest("songsample.mp3"));

        var guitar:Sound = new Sound();
        var guitarChannel:SoundChannel = new SoundChannel();
        var guitarTransform = new SoundTransform();
        guitarChannel.soundTransform = guitarTransform;
        guitar.load(new URLRequest("funky.mp3"));

        voc_mc.addEventListener(MouseEvent.CLICK, _selectedVoc);
        git_mc.addEventListener(MouseEvent.CLICK, _selectedGit);

        function _selectedVoc(e:MouseEvent):void
        {
            var bool:Boolean = e.target.selected;

            if(bool)
            {
                vocalsTransform.volume = 1;

            }
            else
            {
                vocalsTransform.volume = 0;

            }
        }


        function _selectedGit(e:MouseEvent):void
        {
            var bool:Boolean = e.target.selected;

            if(bool)
            {
                guitarTransform.volume = 1;

            }
            else
            {
                guitarTransform.volume = 0;


            }
        }

        play_mc.addEventListener(MouseEvent.CLICK,
                                 function(evt:MouseEvent)
        {
            vocalsChannel = vocals.play(0,0,vocalsTransform);
            guitarChannel = guitar.play(0,0,guitarTransform);
        })

        stop_mc.addEventListener(MouseEvent.CLICK,
                                 function(evt:MouseEvent)
        {
            vocalsChannel.stop();
            guitarChannel.stop();
        })
4

1 回答 1

2

您需要重置通道上的 soundTransform 属性:

    function _selectedVoc(e:MouseEvent):void
    {
        var bool:Boolean = e.target.selected;

        if(bool)
        {
            vocalsTransform.volume = 1;

        }
        else
        {
            vocalsTransform.volume = 0;

        }
        vocalsChannel.soundTransform = vocalsTransform;
    }
于 2013-02-26T17:43:48.883 回答