首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为动作脚本恢复音乐按钮3

为动作脚本恢复音乐按钮3
EN

Stack Overflow用户
提问于 2013-02-10 02:43:30
回答 1查看 633关注 0票数 0

我有两个按钮:一个简历(OnBtn)和一个暂停(OffBtn),它们被分配用于控制动画的声音。暂停按钮很好,但当我再次播放它时.它从一开始就重新启动这首歌,而不是在它假设的resumeTime.这是我的密码。

代码语言:javascript
复制
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();
}
EN

回答 1

Stack Overflow用户

发布于 2013-02-10 04:10:56

将动画放在单独的MovieClip中,然后在stopMove()startMove()上调用MovieClipplay()stop()函数。

下面是一个有用的示例:http://www.swfcabin.com/open/1360494138

以及代码中的更改:

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14794156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档