我有两个按钮:一个简历(OnBtn)和一个暂停(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();
}发布于 2013-02-10 04:10:56
将动画放在单独的MovieClip中,然后在stopMove()和startMove()上调用MovieClip的play()和stop()函数。
下面是一个有用的示例: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
}https://stackoverflow.com/questions/14794156
复制相似问题