Jul 19
在Flex中如何利用mx.effects SoundEffect类和ProgressBar类的completeEffect样式在进度条(ProgressBar)最后完成时播放一个声音效果的例子中我们了解了如何使用mx.effects SoundEffect类来调用声音效果。接下来的例子演示了Flex中实现调用嵌入声音效果的三种方法。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
①、使用<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>
代码:Peter deHaan 翻译/整理/编译:minidxer
