怎么用AS3实现一个按钮控制音频的暂停和播放
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
展开全部
package game {
import fl.controls.Button;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.ui.Mouse;
import flash.utils.getDefinitionByName;
public class SoundControl extends Sprite {
private var _sound:Sound
private var _pauseBnt:Button
private var _playBnt:Button
private var _channel:SoundChannel
public function SoundControl(soundName) {
var _c:Class=getDefinitionByName(soundName) as Class
_sound=new _c
_pauseBnt=addChild(new Button) as Button
_playBnt=addChild(new Button) as Button
_pauseBnt.addEventListener(MouseEvent.CLICK, onPause)
_playBnt.addEventListener(MouseEvent.CLICK, onPlay)
_pauseBnt.visible=false
}
private function onPause(evt:MouseEvent):void {
if (_channel) {
_channel.stop()
_channel=null
_pauseBnt.visible=false
_playBnt.visible=true
}
}
private function onPlay(evt:MouseEvent):void {
if (!_channel) {
_channel=_sound.play()
_playBnt.visible=false
_pauseBnt.visible=true
}
}
}
}
import fl.controls.Button;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.ui.Mouse;
import flash.utils.getDefinitionByName;
public class SoundControl extends Sprite {
private var _sound:Sound
private var _pauseBnt:Button
private var _playBnt:Button
private var _channel:SoundChannel
public function SoundControl(soundName) {
var _c:Class=getDefinitionByName(soundName) as Class
_sound=new _c
_pauseBnt=addChild(new Button) as Button
_playBnt=addChild(new Button) as Button
_pauseBnt.addEventListener(MouseEvent.CLICK, onPause)
_playBnt.addEventListener(MouseEvent.CLICK, onPlay)
_pauseBnt.visible=false
}
private function onPause(evt:MouseEvent):void {
if (_channel) {
_channel.stop()
_channel=null
_pauseBnt.visible=false
_playBnt.visible=true
}
}
private function onPlay(evt:MouseEvent):void {
if (!_channel) {
_channel=_sound.play()
_playBnt.visible=false
_pauseBnt.visible=true
}
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
深圳市容大彩晶科技有限公司
2024-11-20 广告
2024-11-20 广告
作为深圳市容大彩晶科技有限公司的工作人员,对于公司广告机的功能有一定的了解。公司的广告机是否支持多语言显示,具体需根据产品型号和功能配置来确定。但一般而言,现代广告机通常具备多语言显示的功能,以适应不同国家和地区的需求。建议直接查阅产品说明...
点击进入详情页
本回答由深圳市容大彩晶科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询