AS3在滑块值上播放声音

时间:2012-11-22 00:32:21

标签: actionscript-3

有可能吗?我是ActionScript 3& S的新手。一直在玩滑块组件。我已经设置了一个带有图像的滑块,并设置了一个要播放的声音,所以如果该值大于0则会播放,如果它大于4则会停止。然而,当我导出它并且它没有错误。我确信我必须将event.value更改为其他内容而不是数字。或者更确切地说使用另一个事件,但我不确定。所以如果你站在这些图像之间,我会认为mp3会继续播放,而不是重新启动每个值。这就是我所拥有的


function changeHandler(event:SliderEvent):void { 
        aLoader.source = "pic"+event.value+".jpeg";

}

function music(event:SliderEvent):void {
    var mySound:Sound = new tes1();
    var myChannel:SoundChannel = new SoundChannel();
    mySound.load(new URLRequest("tes1.mp3"));





        if (event.value > 0 || event.value > 4 ){
            myChannel = mySound.play();
        }

        else{
            myChannel.stop();
        }
}

1 个答案:

答案 0 :(得分:0)

您正在每个滑块事件中创建一个新的声道,如果该值超出所需范围,则停止该新声道。但它一开始并没有播放任何声音。

你可能想要的是将声道存储在事件处理程序之外,当值在该范围内跳跃时可能不会重放声音:

slider.addEventListener(SliderEvent.CHANGE, music);

// Stores the sound channel between slider movements.
var myChannel:SoundChannel = new SoundChannel();
var isPlaying:Boolean = false;

function music(event:SliderEvent):void {
    var mySound:Sound = new tes1();
    mySound.load(new URLRequest("tes1.mp3"));  

    if (event.value > 0 || event.value > 4) {

        // Check if we are already playing the sound and, if yes, do nothing
        if (!isPlaying) {
            myChannel = mySound.play();
            isPlaying = true;
        }

    } else {
        myChannel.stop();
        isPlaying = false;
    }
}

因此当值超出所需范围时,它会停止播放最后一个声音,当值在范围内移动时,它会继续播放而不是重新开始。

相关问题