2013-02-10 59 views
0

我有2個按鈕:1個簡歷(onBtn)和1個暫停(offBtn),它們被分配用於控制動畫的聲音。暫停按鈕工作正常,但是當我再次播放時...它從一開始就重新啓動首歌曲,而不是它的假設resumeTime ...這裏是我的代碼...恢復動作腳本的音樂按鈕3


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

回答

0

把你的動畫在一個單獨的MovieClip然後stopMove()startMove()調用play()stop()該功能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 
} 
+0

如果我這樣做,音樂不會玩的時候,我的動畫負載.. – mitche027 2013-02-10 05:02:20

+0

想出了一個解決方法這個問題,並編輯我的第一篇文章。 – khailcs 2013-02-10 09:21:01