我在音乐播放器中有四个不同的音轨(吉他,贝斯,鼓,人声)。它们都被命名为复选框,以选中/取消选中当前可听的曲目之一,我也有一个播放按钮开始。因此,当检查例如人声和吉他时,我只想听这两种乐器,而低音和鼓只是在后台静音演奏。

问题是,当我在选中这两个框的情况下开始比赛时,由于状态为静态并且在敲击框时不会动态更改,因此我无法在播放时更改其他框。

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

        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();
        })

最佳答案

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

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

        if(bool)
        {
            vocalsTransform.volume = 1;

        }
        else
        {
            vocalsTransform.volume = 0;

        }
        vocalsChannel.soundTransform = vocalsTransform;
    }

关于actionscript-3 - Actionscript 3,多个音轨,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15087650/

10-08 20:55