![[AS3.0編程教學]最全的聲音控制方法_第1頁](http://file1.renrendoc.com/fileroot_temp2/2020-4/27/85eb599f-600c-4e8c-a187-8fe295c0b218/85eb599f-600c-4e8c-a187-8fe295c0b2181.gif)
![[AS3.0編程教學]最全的聲音控制方法_第2頁](http://file1.renrendoc.com/fileroot_temp2/2020-4/27/85eb599f-600c-4e8c-a187-8fe295c0b218/85eb599f-600c-4e8c-a187-8fe295c0b2182.gif)
![[AS3.0編程教學]最全的聲音控制方法_第3頁](http://file1.renrendoc.com/fileroot_temp2/2020-4/27/85eb599f-600c-4e8c-a187-8fe295c0b218/85eb599f-600c-4e8c-a187-8fe295c0b2183.gif)
![[AS3.0編程教學]最全的聲音控制方法_第4頁](http://file1.renrendoc.com/fileroot_temp2/2020-4/27/85eb599f-600c-4e8c-a187-8fe295c0b218/85eb599f-600c-4e8c-a187-8fe295c0b2184.gif)
![[AS3.0編程教學]最全的聲音控制方法_第5頁](http://file1.renrendoc.com/fileroot_temp2/2020-4/27/85eb599f-600c-4e8c-a187-8fe295c0b218/85eb599f-600c-4e8c-a187-8fe295c0b2185.gif)
已閱讀5頁,還剩4頁未讀, 繼續免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
精品文檔AS3.0編程教學最全的聲音控制方法網上做flash音樂播放器的人不少,這個作品主要是對聲音的外部讀取,然后保存,然后控制播放,暫停,停止等操作,今天這個作品就是向大家展示這些操作的方法。1. 首先我們新建一個文件,在舞臺上擺出下面這些按鈕,我們今天對這個聲音文件的操縱就如按鈕所示:動手之前我們按下Ctrl+Shift+F12,打開ActionScript設置,將“自動申明舞臺對象”打鉤取消,我們將每個對象自己用Public聲明,這樣做的好處是開發時每個元件的屬性方便引用和提醒。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. 播放按鈕功能。控制音樂播放的按鈕,單擊后音樂開始播放,并記錄音樂的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. 暫停 按鈕功能,該按鈕讓音樂暫停掉,為了能繼續播放,我們需要記錄下此時testChannel的位置,然后播放按鈕單擊時可以繼續播放/暫停按鈕功能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. 設定聲音的音量增加。控制音量就需要soundTransform對象了,它其實是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. 最后別忘了所有你定義的函數都要寫到音樂加載完成的那個函數里執行,或者構造函數也可以。就像下面這樣子:/加載音樂并控制播放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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國可伸縮乒乓球網格行業市場全景分析及前景機遇研判報告
- 2025年中國咖啡機清潔液行業市場全景分析及前景機遇研判報告
- 癌癥康復期用藥指南
- 中國防雷避雷產品行業市場深度分析及行業發展趨勢報告
- 2019-2025年中國定制酒行業市場深度分析及發展前景預測報告
- 網圍欄可行性研究報告
- 中國電動自行車電商行業發展監測及市場發展潛力預測報告
- 2025年中國豆腐行業市場深度分析及發展前景預測報告
- 起重安裝項目投資可行性研究分析報告(2024-2030版)
- 2025年 云南省觀光車駕駛-特種設備作業N2證考試練習題附答案
- 云南省2024年小升初語文模擬考試試卷(含答案)
- 湖北省武漢市2024年七年級上學期期中數學試題【附參考答案】
- 山東省青島膠州市2024-2025學年高一數學下學期期末考試試題
- 六年級數學思政融合課教學設計圓的周長
- 停機坪無人駕駛車輛應用
- 嚴重創傷病種
- 北京版三年級上冊除法豎式計算練習題300道及答案
- 《圖書館建筑設計規范JGJ38-2015》-副本
- 南樂縣元村鎮養殖協會標準章程
- 湖北2024年湖北武漢鐵路職業技術學院招聘28人筆試歷年典型考題及考點附答案解析
- 重慶市兩江新區2023-2024學年八年級下學期期末抽測英語試題(解析版)
評論
0/150
提交評論