0

我有 2 个按钮:1 个恢复(onBtn)和 1 个暂停(offBtn),用于控制动画的声音。暂停按钮工作正常,但当我再次播放时......它从头开始重新播放歌曲而不是打开假设 resumeTime ......这是我的代码......


import flash.events.Event;
import flash.events.MouseEvent;

onBtn.addEventListener(MouseEvent.CLICK, startMove);
offBtn.addEventListener(MouseEvent.CLICK, stopMove);

var resumeTime:Number = 0;
var isPlaying:Boolean;
var mySound:Sound = new MySong();
var channel1:SoundChannel = new SoundChannel();


onBtn.visible=false;
isPlaying=true;
channel1=mySound.play();


function stopMove(event:MouseEvent):void {

    resumeTime=channel1.position;
    channel1.stop();
    onBtn.visible =true;
    offBtn.visible=false;
    isPlaying=false;
    stop();

}

function startMove(event:MouseEvent):void {
    channel1=mySound.play(resumeTime);
    onBtn.visible=false;
    offBtn.visible=true;
    isPlaying=true;
    play();
}
4

1 回答 1

0

将您的动画放在单独的MovieClipthen on中stopMove(),然后startMove()调用 that 的play()andstop()函数MovieClip

这是一个工作示例:http ://www.swfcabin.com/open/1360494138

以及代码中的更改:

import flash.events.Event;
import flash.events.MouseEvent;

stop(); ////

onBtn.addEventListener(MouseEvent.CLICK, startMove);
offBtn.addEventListener(MouseEvent.CLICK, stopMove);

var resumeTime:Number = 0;
var isPlaying:Boolean;
var mySound:Sound = new MySong();
var channel1:SoundChannel = new SoundChannel();

onBtn.visible=false;
isPlaying=true;
channel1=mySound.play(0);


function stopMove(event:MouseEvent):void {
    resumeTime=channel1.position;
    channel1.stop();
    onBtn.visible =true;
    offBtn.visible=false;
    isPlaying=false;
    movieClip.stop(); //// Animation moved to movieClip
}

function startMove(event:MouseEvent):void {
    if(resumeTime >= mySound.length) {
    //// Go back to start when sound has finished playing
    resumeTime = 0;
    }
    channel1=mySound.play(resumeTime);
    onBtn.visible=false;
    offBtn.visible=true;
    isPlaying=true;
    movieClip.play(); //// Animation moved to movieClip
}
于 2013-02-10T04:10:56.883 回答