再学AS3(六)——音乐播放器(4):…

来源:互联网 发布:怎么提高淘宝店铺流量 编辑:程序博客网 时间:2024/06/16 06:41

主要功能:
点击停止按钮使声音停止,点击暂停按钮使声音暂停并使当前按钮呈现为播放按钮,点击播放挖掘使声音播放并使当前按钮呈现为暂停按钮。

制作过程:
1、新建FLASHCS3文档,保存名为“音乐播放器音量控制”,保存在存有音乐的文件夹内。设置文档大小:252×114像素,帧频:24fps。
2、第一层名为“播放器背景”,在该层画一个播放器背景。
3、新建图层,名为“按钮”,画三个按钮:播放(宽:38、高:38、X:126、Y:84)、暂停(宽:38、高:38、X:126、Y:84)、停止(宽:18、高:18、X:34、Y:84);在场景中的实例名分别为:bf_btn、zt_btn、tz_btn。
再学AS3(六)——音乐播放器(4):播放、暂停与停止
4、新建图层,名为“AS”,在帧上写如下代码:

//载入音乐并播放
var _sound:Sound=new Sound();
var _channel:SoundChannel=new SoundChannel();
var url:String="******.mp3";//你电脑上的MP3音乐文件名,把该文件与MP3音乐文件放在一个文件夹内。
var _request:URLRequest = new URLRequest(url);
_sound.load(_request);
_channel=_sound.play();
//暂停、播放与停止
var position:int
zt_btn.visible=true;
bf_btn.visible=false;
zt_btn.addEventListener(MouseEvent.CLICK,zt);
function zt(e:MouseEvent):void {
 zt_btn.visible=false;
 bf_btn.visible=true;
 position=_channel.position;
 _channel.stop();
}
bf_btn.addEventListener(MouseEvent.CLICK,bf);
function bf(e:MouseEvent):void {
 zt_btn.visible=true;
 bf_btn.visible=false;
 _channel=_sound.play(position);

}
tz_btn.addEventListener(MouseEvent.CLICK,tz);
function tz(e:MouseEvent):void {
 zt_btn.visible=false;
 bf_btn.visible=true;
 position=0;
 _channel.stop();
}

0 0
原创粉丝点击