0

アニメーションのサウンドを制御するために割り当てられた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

Put your animation in a separate MovieClip then on stopMove() and startMove() you call the play() and stop() functions of that MovieClip.

Here's a working example: http://www.swfcabin.com/open/1360494138

And the changes in your code:

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 に答える