在Flex中如何利用mx.effects SoundEffect类和ProgressBar类的completeEffect样式在进度条(ProgressBar)最后完成时播放一个声音效果的例子中我们了解了如何使用mx.effects SoundEffect类来调用声音效果。接下来的例子演示了Flex中实现调用嵌入声音效果的三种方法。
Download: main.mxml
②、使用 [Embed], <mx:SoundEffect /> ,mouseDownEffect
③、使用[Embed], SoundAsset类, SoundAsset.play()事件
Download: main.mxml
①、使用<mx:SoundEffect />标签, @Embed, mouseDownEffect
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">
- <mx:Script>
- <![CDATA[
- import mx.controls.Alert;
- private var alert:Alert;
- private function showAlert():void {
- alert = Alert.show("Are you sure you want to delete the internet?", "Confirm delete...", Alert.YES | Alert.NO);
- }
- ]]>
- </mx:Script>
- <mx:SoundEffect id="soundEffect" source="@Embed(source='assets/ding.mp3')" />
- <mx:Button label="Delete Internet?" click="showAlert();" mouseDownEffect="{soundEffect}" />
- </mx:Application>
②、使用 [Embed], <mx:SoundEffect /> ,mouseDownEffect
- Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">
- <mx:Script>
- <![CDATA[
- import mx.controls.Alert;
- [Bindable]
- [Embed('assets/ding.mp3')]
- private var ding_mp3:Class;
- private var alert:Alert;
- private function showAlert():void {
- alert = Alert.show("Are you sure you want to delete the internet?", "Confirm delete...", Alert.YES | Alert.NO);
- }
- ]]>
- </mx:Script>
- <mx:SoundEffect id="soundEffect" source="{ding_mp3}" />
- <mx:Button label="Delete Internet?" click="showAlert(); " mouseDownEffect="{soundEffect}" />
- </mx:Application>
③、使用[Embed], SoundAsset类, SoundAsset.play()事件
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">
- <mx:Script>
- <![CDATA[
- import mx.controls.Alert;
- import mx.core.SoundAsset;
- [Embed('assets/ding.mp3')]
- private var ding_mp3:Class;
- private var ding:SoundAsset = new ding_mp3() as SoundAsset;
- private var alert:Alert;
- private function showAlert():void {
- alert = Alert.show("Are you sure you want to delete the internet?", "Confirm delete...", Alert.YES | Alert.NO);
- }
- ]]>
- </mx:Script>
- <mx:Button label="Delete Internet?" click="showAlert(); ding.play()" />
- </mx:Application>
上述转载:http://miss4813.iteye.com/blog/657082
其中注意:音频文件可能无法播放,由于编码格式以及音频的采样率、比特率等影响。(详细说明参照:http://biancheng.dnbcw.info/336/336879.html)