[AS3.0編程教學]最全的聲音控制方法_第1頁
[AS3.0編程教學]最全的聲音控制方法_第2頁
[AS3.0編程教學]最全的聲音控制方法_第3頁
[AS3.0編程教學]最全的聲音控制方法_第4頁
[AS3.0編程教學]最全的聲音控制方法_第5頁
已閱讀5頁,還剩4頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

精品文檔AS3.0編程教學最全的聲音控制方法網上做flash音樂播放器的人不少,這個作品主要是對聲音的外部讀取,然后保存,然后控制播放,暫停,停止等操作,今天這個作品就是向大家展示這些操作的方法。1. 首先我們新建一個文件,在舞臺上擺出下面這些按鈕,我們今天對這個聲音文件的操縱就如按鈕所示:動手之前我們按下Ctrl+Shift+F12,打開ActionScript設置,將“自動申明舞臺對象”打鉤取消,我們將每個對象自己用Public聲明,這樣做的好處是開發(fā)時每個元件的屬性方便引用和提醒。2. 3我們新建一個文檔類,首先聲明舞臺上這些按鈕,并定義聲音變量:testSound,控制變量testChannel,testTrans,testPosition。public var btnPlay:SimpleButton;public var btnPause:SimpleButton;public var btnStop:SimpleButton;public var btnQuick:SimpleButton;public var btnVocUp:SimpleButton;public var btnVocDown:SimpleButton;public var btnPanUp:SimpleButton;public var btnPanDown:SimpleButton;private var testSound:Sound;private var testChannel:SoundChannel;private var testTrans:SoundTransform;private var testPosition:Number=0;3. 4首先用下面代碼將一首叫做“test.mp3的音樂加載到舞臺。public function TestSoundMain()testSound = new Sound();testChannel=new SoundChannel();testTrans = new SoundTransform();testSound.load(new URLRequest(test.mp3);testSound.addEventListener(Event.COMPLETE,soundLoadOver);private function soundLoadOver(e:Event):voidtestSound.removeEventListener(Event.COMPLETE, soundLoadOver);soudLoad = true;4. 播放按鈕功能??刂埔魳凡シ诺陌粹o,單擊后音樂開始播放,并記錄音樂的SoundChannel屬性。為了防止連擊,我們定義一個isSoundPlay布爾變量判斷音樂是否在播放中。/播放按鈕功能private function playBtnEvent():voidbtnPlay.addEventListener(MouseEvent.CLICK, soundPlay);private function soundPlay(e:MouseEvent):voidif (isSoundPlay) return;isSoundPlay = true;testChannel = testSound.play(testPosition);5. 暫停 按鈕功能,該按鈕讓音樂暫停掉,為了能繼續(xù)播放,我們需要記錄下此時testChannel的位置,然后播放按鈕單擊時可以繼續(xù)播放/暫停按鈕功能private function pauseBtnEvent():voidbtnPause.addEventListener(MouseEvent.CLICK, soudPause);private function soudPause(e:MouseEvent):voidif (!isSoundPlay) return;isSoundPlay = false;testPosition = testChannel.position;testChannel.stop();6. 停止按鈕功能,單擊后音樂停止播放,記錄位置歸0./停止按鈕功能private function stopBtnEvent():voidbtnStop.addEventListener(MouseEvent.CLICK, soundStop);private function soundStop(e:MouseEvent):voidisSoundPlay = false;testPosition = 0testChannel.stop();7. 快進聲音。單擊該按鈕時,我們讓聲音從當前位置向前播放500毫秒,也就是快進半秒。/快進按鈕功能private function qucikBtnEvent():voidbtnQuick.addEventListener(MouseEvent.CLICK, soudQuickPlay);private function soudQuickPlay(e:MouseEvent):voidif (!isSoundPlay) return;testPosition = testChannel.position;testChannel.stop();testChannel = testSound.play(testPosition + 500);8. 設定聲音的音量增加??刂埔袅烤托枰猻oundTransform對象了,它其實是testChanel的soundTransform屬性而已,通過它來控制音量。/音量增加private function volumeUpBtnEvent():voidbtnVocUp.addEventListener(MouseEvent.CLICK, upSoudVoc);private function upSoudVoc(e:MouseEvent):voidif (!isSoundPlay) return;testTrans = testChannel.soundTransform;var addedVoc:Number = testTrans.volume 1?1:(testTrans.volume +0.05);testTrans.volume = addedVoc;testChannel.soundTransform = testTrans;9. 設定聲音的音量減小。/音量減小private function volumeDownBtnEvent():voidbtnVocDown.addEventListener(MouseEvent.CLICK, downSoundVoc);private function downSoundVoc(e:MouseEvent):voidif (!isSoundPlay) return;testTrans = testChannel.soundTransform;var downVoc:Number = testTrans.volume 1?1:(testTrans.pan + 0.05);testTrans.pan = addedPan;testChannel.soundTransform = testTrans;11. 設定聲音的平衡度向左,點擊此按鈕聲音的平衡性會左移,直到變成左聲道。/平衡向左移動private function panLeftBtnEvent():voidbtnPanDown.addEventListener(MouseEvent.CLICK, downSoundPan);private function downSoundPan(e:MouseEvent):voidif (!isSoundPlay) return;testTrans = testChannel.soundTransform;var downPan:Number = testTrans.pan 0?0:(testTrans.pan - 0.05);testTrans.pan = downPan;testChannel.soundTransform = testTrans;12. 最后別忘了所有你定義的函數都要寫到音樂加載完成的那個函數里執(zhí)行,或者構造函數也可以。就像下面這樣子:/加載音樂并控制播放private function soundLoadOver(e:Event):voidtestSound.removeEventListener(Event.COMPLETE, soundLoadOver);soudLoad = true;playBtnEvent();pauseBtnEvent();stopBtnEvent();qucikBtnEvent();volumeUpBtnEvent();volumeDownBtnEvent();panRightBtnEvent();panLeftBtnEvent();13. 所有這些一個個代碼合

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論