I can play a sound file in Adobe AIR if I use the the flash.media.Sound class but I have request a URL to do it. What I need to do is load it as an embedded asset in the AIR app. I have tried using mx.core.media library but this does not work either.
Here is a simple app that shows the problem:
<fx:Script>
<![CDATA[
// Embed MP3 file.
import flash.media.Sound;
import mx.core.SoundAsset;
[Embed(source="ding.mp3")]
[Bindable]
public var sndCls:Class;
private var myReq:URLRequest = new URLRequest("ding.mp3");
private var snd:Sound;
private var sndAsset:Sound;
private var myChannel:SoundChannel;
protected function myButton_clickHandler(event:MouseEvent):void
{
sndAsset = new sndCls() as SoundAsset;
myChannel = sndAsset.play();
}
protected function myReqButton_clickHandler(event:Mouse开发者_StackOverflow中文版Event):void
{
snd = new Sound(myReq);
snd.play();
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:Button id="myButton" label="Play Embedded" click="myButton_clickHandler(event)"/>
<s:Button id="myReqButton" label="Play Requested" click="myReqButton_clickHandler(event)"/>
You need ding.mp3 in the same directory to test it.
Any suggestions welcome
Thanks
Steve
Embedded resource cannot be bindable, since it is constant. Try to remove [Bindable]. If that doesn't help, post error messages (if any) or describe symptoms what's wrong.
精彩评论