如何可以暂停/ AS3中的Flash播放嵌入声音 [英] How can pause / play embed sound in AS3 flash
本文介绍了如何可以暂停/ AS3中的Flash播放嵌入声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有1:30分钟长度的声音。我嵌入到我瑞士法郎,并设置其与帧同步。我需要的是能够暂停,并通过ActionScript来播放这个声音。
有没有人有任何想法如何做到这一点?
解决方案
//数量进行了重新定义时,按下暂停键
VAR pausePoint:数= 0.00;
//用于一个true或false值来检查声音是否正在播放
VAR IsPlaying模块:布尔;
//认为的SoundChannel作为扬声器系统和声音作为一个MP3播放器的
VAR的SoundChannel:的SoundChannel =新的SoundChannel();
VAR的声音:声音=新的声音(新的URLRequest(SOUND.mp3));
//你应该设置x STOP的和xplay值,以匹配您的停止按钮和播放/暂停按钮的实例名称
xstop.addEventListener(MouseEvent.CLICK,clickStop);
xplay.addEventListener(MouseEvent.CLICK,clickPlayPause);
的SoundChannel = SOUND.PLAY();
IsPlaying模块= TRUE;
功能clickPlayPause(EVT:的MouseEvent){
如果(IsPlaying模块){
pausePoint = soundChannel.position;
soundChannel.stop();
IsPlaying模块= FALSE;
} 其他 {
的SoundChannel = SOUND.PLAY(pausePoint);
IsPlaying模块= TRUE;
}
}
功能clickStop(EVT:的MouseEvent){
如果(IsPlaying模块){
soundChannel.stop();
IsPlaying模块= FALSE;
}
pausePoint = 0.00;
}
I have a sound with a length of 1:30 min. I embedded it into my swf and set it to sync with the frame. I need is to be able to pause and play this sound via ActionScript.
Does anyone have any idea how to do this?
解决方案
//number that is redefined when the pause button is hit
var pausePoint:Number = 0.00;
//a true or false value that is used to check whether the sound is currently playing
var isPlaying:Boolean;
//think of the soundchannel as a speaker system and the sound as an mp3 player
var soundChannel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound(new URLRequest("SOUND.mp3"));
//you should set the xstop and xplay values to match the instance names of your stop button and play/pause buttons
xstop.addEventListener(MouseEvent.CLICK, clickStop);
xplay.addEventListener(MouseEvent.CLICK, clickPlayPause);
soundChannel = sound.play();
isPlaying = true;
function clickPlayPause(evt:MouseEvent) {
if (isPlaying) {
pausePoint = soundChannel.position;
soundChannel.stop();
isPlaying = false;
} else {
soundChannel = sound.play(pausePoint);
isPlaying = true;
}
}
function clickStop(evt:MouseEvent) {
if (isPlaying) {
soundChannel.stop();
isPlaying = false;
}
pausePoint = 0.00;
}
这篇关于如何可以暂停/ AS3中的Flash播放嵌入声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文