我的声音长度为1:30分钟。我将其嵌入到SWF中,并将其设置为与框架同步。我需要的是能够通过ActionScript暂停播放此声音。

有谁知道如何做到这一点?

最佳答案

//number that is redefined when the pause button is hit
var pausePoint:Number = 0.00;

//a true or false value that is used to check whether the sound is currently playing
var isPlaying:Boolean;

//think of the soundchannel as a speaker system and the sound as an mp3 player
var soundChannel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound(new URLRequest("SOUND.mp3"));

//you should set the xstop and xplay values to match the instance names of your stop button and play/pause buttons
xstop.addEventListener(MouseEvent.CLICK, clickStop);
xplay.addEventListener(MouseEvent.CLICK, clickPlayPause);

soundChannel = sound.play();
isPlaying = true;

function clickPlayPause(evt:MouseEvent) {
    if (isPlaying) {
        pausePoint = soundChannel.position;
        soundChannel.stop();
        isPlaying = false;
    } else {
        soundChannel = sound.play(pausePoint);
        isPlaying = true;
    }
}

function clickStop(evt:MouseEvent) {
    if (isPlaying) {
        soundChannel.stop();
        isPlaying = false;
    }
    pausePoint = 0.00;
}

关于flash - 如何在AS3闪光灯中暂停/播放嵌入声音,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1211393/

10-08 20:57