var song:SoundChannel=new SoundChannel(); // 首先创建一个频道
var _sound:Sound = new Sound( ); //新建一个新的声音
_sound.load(new URLRequest("http://www.solelyfan.cn/works/yundong/yundong.mp3"));//把音乐加载到新的声音里面
var currentMusicPosition:Number=0; //定义记录播放位置0开始播放 如果设置1000那么后退一秒
my_btn.txt.text="播放"; //定义文本初始值
my_btn.txt.selectable =false; //定义初始Boolean为false
my_btn.addEventListener(MouseEvent.CLICK,_play); /创建一个监听器 鼠标点击
var my_B:Boolean=true; //变量一个Boolean为ture
function _play(e:MouseEvent):void { //创建函数
if (my_B) { //如果my_B为ture
song=_sound.play(currentMusicPosition); //记录播放位置
my_btn.txt.text="停止"; //文本显示“停止”
} else { //否则
currentMusicPosition=song.position; // 记录当前播放位置
song.stop(); //声音停止
my_btn.txt.text="播放"; //文本显示“播放”
}
my_B=!my_B;
}
联系客服