Flex中调用嵌入声音效果的三种方法的例子

在Flex中如何利用mx.effects SoundEffect类和ProgressBar类的completeEffect样式在进度条(ProgressBar)最后完成时播放一个声音效果的例子中我们了解了如何使用mx.effects SoundEffect类来调用声音效果。接下来的例子演示了Flex中实现调用嵌入声音效果的三种方法。 


①、使用<mx:SoundEffect />标签, @Embed, mouseDownEffect 


Download: main.mxml 
Java代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">   
  3.     
  4.     <mx:Script>   
  5.         <![CDATA[   
  6.             import mx.controls.Alert;   
  7.     
  8.             private var alert:Alert;   
  9.     
  10.             private function showAlert():void {   
  11.                 alert = Alert.show("Are you sure you want to delete the internet?""Confirm delete...", Alert.YES | Alert.NO);   
  12.             }   
  13.         ]]>   
  14.     </mx:Script>   
  15.     
  16.     <mx:SoundEffect id="soundEffect" source="@Embed(source='assets/ding.mp3')" />   
  17.     
  18.     <mx:Button label="Delete Internet?" click="showAlert();" mouseDownEffect="{soundEffect}" />   
  19.     
  20. </mx:Application>  


②、使用 [Embed], <mx:SoundEffect /> ,mouseDownEffect 

Java代码   收藏代码
  1. Download: main.mxml  
  2. <?xml version="1.0" encoding="utf-8"?>   
  3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">   
  4.     
  5.     <mx:Script>   
  6.         <![CDATA[   
  7.             import mx.controls.Alert;   
  8.     
  9.             [Bindable]   
  10.             [Embed('assets/ding.mp3')]   
  11.             private var ding_mp3:Class;   
  12.     
  13.             private var alert:Alert;   
  14.     
  15.             private function showAlert():void {   
  16.                 alert = Alert.show("Are you sure you want to delete the internet?""Confirm delete...", Alert.YES | Alert.NO);   
  17.             }   
  18.         ]]>   
  19.     </mx:Script>   
  20.     
  21.     <mx:SoundEffect id="soundEffect" source="{ding_mp3}" />   
  22.     
  23.     <mx:Button label="Delete Internet?" click="showAlert(); " mouseDownEffect="{soundEffect}" />   
  24.     
  25. </mx:Application>  


③、使用[Embed], SoundAsset类, SoundAsset.play()事件 

Download: main.mxml 
Java代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">   
  3.     
  4.     <mx:Script>   
  5.         <![CDATA[   
  6.             import mx.controls.Alert;   
  7.             import mx.core.SoundAsset;   
  8.     
  9.             [Embed('assets/ding.mp3')]   
  10.             private var ding_mp3:Class;   
  11.     
  12.             private var ding:SoundAsset = new ding_mp3() as SoundAsset;   
  13.     
  14.             private var alert:Alert;   
  15.     
  16.             private function showAlert():void {   
  17.                 alert = Alert.show("Are you sure you want to delete the internet?""Confirm delete...", Alert.YES | Alert.NO);   
  18.             }   
  19.         ]]>   
  20.     </mx:Script>   
  21.     
  22.     <mx:Button label="Delete Internet?" click="showAlert(); ding.play()" />   
  23.     
  24. </mx:Application>  

上述转载:http://miss4813.iteye.com/blog/657082

其中注意:音频文件可能无法播放,由于编码格式以及音频的采样率、比特率等影响。(详细说明参照:http://biancheng.dnbcw.info/336/336879.html)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值