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
Asked
Active
Viewed 245 times
1 Answers
2
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>

shaunhusain
- 19,630
- 4
- 38
- 51
-
And where does the sample.mp3 reside?? – Rajeev Jan 13 '11 at 17:42
-
At any base directory included within the source build path, in eclipse/flash builder this would be specified in the project properties. By default the src folder in eclipse/flash builder is the root of the compilation process so it'll start from there unless you specify other folders as base folders all paths will be relative to src (regardless of the location of the class doing the embedding). – shaunhusain Jan 13 '11 at 18:59
-
Since it's embedded into the swf during compilation the mp3 itself should not be present in the bin-debug folder or anywhere post compilation, if it is it can be removed as it would not be referenced externally. In order to reference it externally you would not embed it but would rather use a Loader to get the content into the swf in this case the path would be relative to the location of the swf. – shaunhusain Jan 13 '11 at 19:01