首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >循环声音flash as3

循环声音flash as3
EN

Stack Overflow用户
提问于 2016-08-18 17:58:36
回答 2查看 220关注 0票数 0

我已经创建了一个打开/关闭按钮的声音使用闪光AS3。这些都是有效的,但每当我按下关闭按钮,然后是打开按钮,音乐不再播放?

我相信这是一个循环问题,但我会错吗?如果是循环问题,我不确定该使用什么代码。

我还需要为btnOn函数添加代码,因为当我打开.swf时,声音会自动播放。

下面是我的当前代码:

代码语言:javascript
复制
var mySound:Sound = new sandstorm(); //(sandstorm is my sound file)

var myChannel:SoundChannel = new SoundChannel();

var lastPosition:Number = 0;

myChannel = mySound.play();

btnOff.addEventListener(MouseEvent.CLICK, onClickPause);

function onClickPause(e:MouseEvent):void {

lastPosition = myChannel.position;

myChannel.stop();

}

干杯:)

EN

回答 2

Stack Overflow用户

发布于 2016-08-18 18:52:33

你的代码只显示事件监听器的onClickPause (我想那是你的停止按钮)。但是在哪里是开始/播放按钮的事件侦听器。在play按钮上,必须再次调用play函数。这里有一个很棒的教程:http://www.republicofcode.com/tutorials/flash/as3sound/

票数 0
EN

Stack Overflow用户

发布于 2016-08-22 13:24:10

你可以试试下面的代码。它使用一个按钮来实现音频暂停/恢复功能...

代码语言:javascript
复制
var mySound:Sound = new sandstorm(); //(sandstorm is my sound file)
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
var audioState : String = "paused"; //will become either "playing" or "paused"


myChannel = mySound.play(); //this line starts playback
audioState = "playing"; //update because you started playback with above line

btnOff.addEventListener(MouseEvent.CLICK, onPlayPause);


function onPlayPause(e:MouseEvent):void 
{

    if (audioState == "playing") //IF already playing
    {
        lastPosition = myChannel.position; //note current "audio time" when pausing
        myChannel.stop(); //stop playback
        audioState = "paused"; //update for next time click is used
    }
    else if (audioState == "paused") //or ELSE IF was already paused then...
    {
        myChannel = mySound.play(lastPosition); //resume playback
        audioState = "playing"; //update for next time click is used
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39015221

复制
相关文章

相似问题

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