![[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)行舉報或認(rèn)領(lǐng)
文檔簡介
精品文檔AS3.0編程教學(xué)最全的聲音控制方法網(wǎng)上做flash音樂播放器的人不少,這個作品主要是對聲音的外部讀取,然后保存,然后控制播放,暫停,停止等操作,今天這個作品就是向大家展示這些操作的方法。1. 首先我們新建一個文件,在舞臺上擺出下面這些按鈕,我們今天對這個聲音文件的操縱就如按鈕所示:動手之前我們按下Ctrl+Shift+F12,打開ActionScript設(shè)置,將“自動申明舞臺對象”打鉤取消,我們將每個對象自己用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. 播放按鈕功能。控制音樂播放的按鈕,單擊后音樂開始播放,并記錄音樂的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. 快進(jìn)聲音。單擊該按鈕時,我們讓聲音從當(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對象了,它其實是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è)定聲音的平衡度向左,點擊此按鈕聲音的平衡性會左移,直到變成左聲道。/平衡向左移動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ù)都要寫到音樂加載完成的那個函數(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. 所有這些一個個代碼合
溫馨提示
- 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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 物業(yè)殺蟲防蟲方案(3篇)
- 美術(shù)機(jī)構(gòu)提價方案(3篇)
- 豬肉產(chǎn)品投標(biāo)方案(3篇)
- 工程材料代用管理制度
- 公交廣告企劃方案(3篇)
- 園區(qū)搬遷預(yù)算方案(3篇)
- 工廠生產(chǎn)外包方案(3篇)
- 公司采購領(lǐng)用管理制度
- 培訓(xùn)學(xué)校自主管理制度
- 包裝印刷公司管理制度
- NB/T 11637-2024煤礦瓦斯抽采系統(tǒng)管理規(guī)范
- 2025南京租房合同協(xié)議范本下載
- 農(nóng)業(yè)光伏電站項目投資估算
- 家具供貨結(jié)算協(xié)議書
- 2025年公證員資格考試全國范圍真題及答案
- 高考前2天校長在出征儀式生動員講話與在座的大家分享了3顆心
- 游客自愿離團(tuán)協(xié)議書
- 2025重慶市潼南區(qū)梓潼街道社區(qū)工作者考試真題
- 城市地理學(xué)知到智慧樹章節(jié)測試課后答案2024年秋華中師范大學(xué)
- 【MOOC】學(xué)術(shù)英語寫作-東南大學(xué) 中國大學(xué)慕課MOOC答案
- 三管三必須-新安法宣貫課件
評論
0/150
提交評論