0
votes

Can some only indicate a small piece of FLEX/AS code which plays mp3 and with play button only,the objective is to play a sample sound for around 5 to 10 seconds.And the compiled swf should have the mp3 embeded in it

1

1 Answers

2
votes

Example below copied and pasted from: http://livedocs.adobe.com/flex/3/html/help.html?content=embed_4.html

<?xml version="1.0"?>
<!-- embed/EmbedSound.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[

            import flash.media.*; 

            [Embed(source="sample.mp3")]
            [Bindable]
            public var sndCls:Class;

            public var snd:Sound = new sndCls() as Sound; 
            public var sndChannel:SoundChannel;

            public function playSound():void {
                sndChannel=snd.play();
            }   

            public function stopSound():void {
                sndChannel.stop();
            }   
        ]]>
    </mx:Script>

    <mx:HBox>
        <mx:Button label="play" click="playSound();"/>
        <mx:Button label="stop" click="stopSound();"/>
    </mx:HBox>
</mx:Application>