as2与as3应用

来源:互联网 发布:mac appstore关闭更新 编辑:程序博客网 时间:2024/06/14 08:13

 

/*2009.6.25

as2.0播放器*/
代码有点简单:

var temp;

temp = 1;
function aa() {
 mysound = new Sound();
 mymusic_array = new Array("1.mp3", "2.mp3", "3.mp3", "4.mp3", "5.mp3");

 mysound.loadSound(mymusic_array[temp-1],true);
 mysound.onLoad = function(success) {
  if (success) {
   mysound.start(0);
  }
 };
 mysound.onSoundComplete = function() {
  temp++;
  if (temp>5) {
   temp = 1;
  }
  aa();
 };
}
onEnterFrame = function () {
 myarray = new Array("爱情呼叫转移", "青花瓷", "track", "洛丽塔", "白色恋人");
 music_name = myarray[temp-1];
 zongchangdu = "总长:"+int(mysound.duration/1000)+"秒";
 yibofang = "已播放:"+int(mysound.position/1000)+"秒";
 huanchong = "缓冲:"+int(mysound.getBytesLoaded()/mysound.getBytesTotal()*100)+"%";
 _root.kongzhitiao.huakuai._x = 248*((int(mysound.position/1000))/(int(mysound.duration/1000)));
};
aa();

 

/*2009.11.25.as3.0播放器代码*/

/*2009.11.25 by Balloon*/
var playPP:Number;
var ctrlSnd:SoundChannel;
var mySong:Sound=new Sound();
mySong.load(new URLRequest("http://www.33477.cn/s.mp3"));
mySong.addEventListener(Event.OPEN,handler1);
mySong.addEventListener(ProgressEvent.PROGRESS,handler2);
mySong.addEventListener(Event.COMPLETE,handler3);
mySong.addEventListener(IOErrorEvent.IO_ERROR,handler4);

function handler1(e:Event) {
 //trace("开始加载歌曲");
}
function handler2(e:ProgressEvent) {
 bl_txt.text=String(e.bytesLoaded);
 bt_txt.text=String(e.bytesTotal);
 per_txt.text=int(e.bytesLoaded/e.bytesTotal*100)+"%";
}
function handler3(e:Event) {

 ctrlSnd=mySong.play();
 addEventListener(Event.ENTER_FRAME,pp);
}
function handler4(e:IOErrorEvent) {
 //trace("加载出错!");
}

function pp(e:Event) {
 playPP=ctrlSnd.position;
 pp_txt.text="已播放"+int(ctrlSnd.position/1000)+"秒";
 progressBar_mc.scaleX=ctrlSnd.position/mySong.length;
}
play_btn.addEventListener(MouseEvent.CLICK,playSnd);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSnd);
stop_btn.addEventListener(MouseEvent.CLICK,stopSnd);
function stopSnd(e:MouseEvent) {
 ctrlSnd.stop();
 removeEventListener(Event.ENTER_FRAME,pp);
 pp_txt.text="已停止";
 progressBar_mc.scaleX=0;
 playPP=0;
}
function playSnd(e:MouseEvent) {
 ctrlSnd.stop();
 ctrlSnd=mySong.play(playPP);
 addEventListener(Event.ENTER_FRAME,pp);

}
function pauseSnd(e:MouseEvent) {
 ctrlSnd.stop();
}

原创粉丝点击