①、使用<mx:SoundEffect />标签, @Embed, mouseDownEffect
<?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
<?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], SoundAsset类, SoundAsset.play()事件
<?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>
本文介绍了在Flash中使用不同方法播放音效的具体实现方式,包括使用<mx:SoundEffect/>标签配合@Embed和mouseDownEffect属性,以及利用SoundAsset类结合play()方法播放声音文件。

被折叠的 条评论
为什么被折叠?



