16.png  

動作:

import flash.events.Event;
import fl.events.SliderEvent

var sound:Sound=new Sound(new URLRequest("1.mp3"));  //載入1.mp3
var soundCtl:SoundChannel=new SoundChannel();  //宣告SoundChannel
var transformSound:SoundTransform=new SoundTransform();  //宣告SoundTransform
transformSound.volume=1; //預設音量:1最大聲,0~1
soundCtl.soundTransform=transformSound;  //設定SoundChannel的音量
var setre:Number=0;  //播放的位置
var soundVolume:Number=10;  //音量改成0~10

sound.addEventListener(Event.COMPLETE,$complete);  //音樂載入完成
function $complete($e:Event):void{  //音樂載入完成的執行函數
 soundCtl=sound.play();  //播放(位置=0,重覆次數:無限次)
 soundCtl.addEventListener(Event.SOUND_COMPLETE,$soundComplete);  //播放完畢的監聽事件
 stop_btn.addEventListener(MouseEvent.CLICK,$stop);  //停止鍵的監聽
 play_btn.addEventListener(MouseEvent.CLICK,$play);  //播放鍵的監聽
 pause_btn.addEventListener(MouseEvent.CLICK,$pause);//暫停鍵的監聽
 pre_btn.addEventListener(MouseEvent.CLICK,$pre);    //上一首鍵的監聽
 next_btn.addEventListener(MouseEvent.CLICK,$next);  //下一首鍵的監聽
 vol_btn.up_btn.addEventListener(MouseEvent.CLICK,$up);    //音量大聲鍵的監聽
 vol_btn.down_btn.addEventListener(MouseEvent.CLICK,$down);//音量小聲鍵的監聽
}
function $soundComplete($e:Event){  //播放完畢的執行函數
 if(cont<5){  //共有5首mp3
  cont+=1; //跳下一首
 }else{
  cont=1;  //跳第1首
 }
 soundCtl.stop();  //先停止上一首mp3
 sound=new Sound(new URLRequest(cont + ".mp3"));  //載入下一首mp3
 soundCtl=sound.play();        //播放
 soundCtl.addEventListener(Event.SOUND_COMPLETE,$soundComplete);  //播放完畢的監聽事件
}
function $stop($e:MouseEvent):void{  //停止的執行函數
 soundCtl.stop();  //音樂停止
 setre=0;          //音樂位置:0,所以按「播放」時,會從頭播放
}

function $play($e:MouseEvent):void{  //播放的執行函數
 soundCtl=sound.play(setre,0);
}

function $pause($e:MouseEvent):void{  //暫停的執行函數
 setre=soundCtl.position;  //紀錄音樂的位置
 soundCtl.stop();          //音樂停止
}

function $next($e:MouseEvent):void{  //下一首的執行函數
 if(cont<5){  //共有5首mp3
  cont+=1; //跳下一首
 }else{
  cont=1;  //跳第1首
 }
 soundCtl.stop();  //先停止上一首mp3
 sound=new Sound(new URLRequest(cont + ".mp3"));  //載入下一首mp3
 soundCtl=sound.play();        //播放
 soundCtl.addEventListener(Event.SOUND_COMPLETE,$soundComplete);  //播放完畢的監聽事件
}

function $pre($e:MouseEvent):void{  //上一首的執行函數
 if(cont==1){  //如果在第1首,那上一首是第5首
  cont=5;
 }else{
  cont-=1;  //跳上一首
 }
 soundCtl.stop();  //先停止上一首mp3
 sound=new Sound(new URLRequest(cont + ".mp3"));  //載入上一首mp3
 soundCtl.addEventListener(Event.SOUND_COMPLETE,$soundComplete);  //播放完畢的監聽事件
 soundCtl=sound.play();       //播放
}

function $up($e:MouseEvent):void{  //音量調整大聲的執行函數
 if(soundVolume<10){  //音量小於10
         soundVolume+=2; //音量+2
   vol_btn.gotoAndStop(soundVolume/2+1);  //音量到適合的關鍵影格
    }
 transformSound.volume=soundVolume/10;    //音量0~10轉成0~1
    soundCtl.soundTransform=transformSound;  //設定音樂音量
}

function $down($e:MouseEvent):void{  //音量調整小聲的執行函數
    if(soundVolume>0){      //音量大於0
           soundVolume-=2;  //音量-2
     vol_btn.gotoAndStop(soundVolume/2+1);//音量到適合的關鍵影格
    }
 transformSound.volume=soundVolume/10;   //音量0~10轉成0~1
    soundCtl.soundTransform=transformSound; //設定音樂音量
}

如需範例檔,請MAIL:css6666@yahoo.com.tw

如果您認為內容不錯,也請幫我點個廣告,謝謝。

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 css6 的頭像
    css6

    美奇電腦

    css6 發表在 痞客邦 留言(0) 人氣()