![[AS3.0編程教學(xué)]最全的聲音控制方法_第1頁](http://file1.renrendoc.com/fileroot_temp2/2020-4/27/85eb599f-600c-4e8c-a187-8fe295c0b218/85eb599f-600c-4e8c-a187-8fe295c0b2181.gif)
![[AS3.0編程教學(xué)]最全的聲音控制方法_第2頁](http://file1.renrendoc.com/fileroot_temp2/2020-4/27/85eb599f-600c-4e8c-a187-8fe295c0b218/85eb599f-600c-4e8c-a187-8fe295c0b2182.gif)
![[AS3.0編程教學(xué)]最全的聲音控制方法_第3頁](http://file1.renrendoc.com/fileroot_temp2/2020-4/27/85eb599f-600c-4e8c-a187-8fe295c0b218/85eb599f-600c-4e8c-a187-8fe295c0b2183.gif)
![[AS3.0編程教學(xué)]最全的聲音控制方法_第4頁](http://file1.renrendoc.com/fileroot_temp2/2020-4/27/85eb599f-600c-4e8c-a187-8fe295c0b218/85eb599f-600c-4e8c-a187-8fe295c0b2184.gif)
![[AS3.0編程教學(xué)]最全的聲音控制方法_第5頁](http://file1.renrendoc.com/fileroot_temp2/2020-4/27/85eb599f-600c-4e8c-a187-8fe295c0b218/85eb599f-600c-4e8c-a187-8fe295c0b2185.gif)
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
精品文檔AS3.0編程教學(xué)最全的聲音控制方法網(wǎng)上做flash音樂播放器的人不少,這個(gè)作品主要是對聲音的外部讀取,然后保存,然后控制播放,暫停,停止等操作,今天這個(gè)作品就是向大家展示這些操作的方法。1. 首先我們新建一個(gè)文件,在舞臺上擺出下面這些按鈕,我們今天對這個(gè)聲音文件的操縱就如按鈕所示:動手之前我們按下Ctrl+Shift+F12,打開ActionScript設(shè)置,將“自動申明舞臺對象”打鉤取消,我們將每個(gè)對象自己用Public聲明,這樣做的好處是開發(fā)時(shí)每個(gè)元件的屬性方便引用和提醒。2. 3我們新建一個(gè)文檔類,首先聲明舞臺上這些按鈕,并定義聲音變量: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屬性。為了防止連擊,我們定義一個(gè)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ù)播放,我們需要記錄下此時(shí)testChannel的位置,然后播放按鈕單擊時(shí)可以繼續(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. 快進(jìn)聲音。單擊該按鈕時(shí),我們讓聲音從當(dāng)前位置向前播放500毫秒,也就是快進(jìn)半秒。/快進(jìn)按鈕功能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. 設(shè)定聲音的音量增加??刂埔袅烤托枰猻oundTransform對象了,它其實(shí)是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. 設(shè)定聲音的音量減小。/音量減小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. 設(shè)定聲音的平衡度向左,點(diǎn)擊此按鈕聲音的平衡性會左移,直到變成左聲道。/平衡向左移動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. 最后別忘了所有你定義的函數(shù)都要寫到音樂加載完成的那個(gè)函數(shù)里執(zhí)行,或者構(gòu)造函數(shù)也可以。就像下面這樣子:/加載音樂并控制播放private function soundLoadOver(e:Event):voidtestSound.removeEventListener(Event.COMPLETE, soundLoadOver);soudLoad = true;playBtnEvent();pauseBtnEvent();stopBtnEvent();qucikBtnEvent();volumeUpBtnEvent();volumeDownBtnEvent();panRightBtnEvent();panLeftBtnEvent();13. 所有這些一個(gè)個(gè)代碼合
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 門診護(hù)理質(zhì)控工作計(jì)劃
- 小動物小班課件
- 檢測理論考試題及答案
- 環(huán)創(chuàng)教師培訓(xùn)
- 躺床老人護(hù)理常規(guī)
- 基礎(chǔ)漢字考試題及答案
- 升降機(jī)培訓(xùn)課件
- 子宮及附件超聲檢查技術(shù)要點(diǎn)
- 青少年戶外培訓(xùn)課件
- 護(hù)理質(zhì)量評價(jià)指標(biāo)講解
- 2025浙江嘉興市海寧市嘉睿人力招聘5人筆試參考題庫附帶答案詳解析版
- 2025年安徽蚌埠市龍子湖區(qū)東方人力資源有限公司招聘筆試參考題庫含答案解析
- 2025至2030中國云計(jì)算行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢及投資規(guī)劃深度研究報(bào)告
- 語文(西藏卷)-2025年中考考前預(yù)測卷(全解全析)
- 2025中考?xì)v史高頻點(diǎn)速記大全
- 《STP戰(zhàn)略規(guī)劃與應(yīng)用》課件
- 建筑施工安全協(xié)議范本5篇
- 【中學(xué)】【主題班會】護(hù)紅色根脈 圓復(fù)興夢想
- 2025年特種設(shè)備作業(yè)人員氣瓶充裝P證考試題庫
- 《智能駕駛輔助系統(tǒng)ADAS》課件
- 2024年自然資源部所屬單位招聘筆試真題
評論
0/150
提交評論