【发布时间】:2017-07-02 06:57:10
【问题描述】:
我在第 1 帧(主页)中有一个播放(恢复)/暂停按钮。但是,当用户浏览应用程序并决定通过按主页按钮返回主页时,声音会重叠。而当用户按下其他按钮时,它开始无休止地重叠。谢谢!这是使用 Adobe AIR 部署在 Android 设备中的 Actionscript 3 Flash 应用程序。这是我的代码:
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.ui.Mouse;
import flash.events.MouseEvent;
var played:Boolean = false;
var soundFile:URLRequest = new URLRequest("music.mp3");
var mySound:Sound = new Sound;
if(played== false){
played= true;
mySound.load(soundFile);
var myChannel:SoundChannel = new SoundChannel;
myChannel = mySound.play(0,999);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSound)
function pauseSound(event:MouseEvent):void
{
var position = myChannel.position;
myChannel.stop();
play_btn.addEventListener(MouseEvent.CLICK,resumeSound);
}
function resumeSound(event:MouseEvent):void
{
myChannel = mySound.play(myChannel.position);
}
}
【问题讨论】:
-
不要在时间线中使用初始化代码。除非
myChannel中存在有效的SoundChannel,否则不要启动声音,这需要更多检查。此外,position是pauseSound()中的本地函数,请移至全局,否则您将丢失数据并且无法恢复声音。 -
@Vesper 谢谢!我是Flash初学者,请多多包涵。你能给我你的更正代码版本吗?谢谢!
标签: android actionscript-3 flash audio air