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

 ①、使用<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>


原文地址:http://blog.minidx.com/2008/07/19/1091.html

你可能感兴趣的:(Flex中调用嵌入声音效果的三种方法)