2 Replies Latest reply on Jan 3, 2007 9:03 PM by sutuy

    Embed sound

    sutuy
      I'm a newbie. i want to try embed sound in flex. so, i open the HELP. and try this code.

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

      <mx:Script>
      <![CDATA[

      import flash.media.*;

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

      public var snd:SoundAsset = new sndCls() as SoundAsset;
      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>

      when i run this code, i found a problem. it says :

      "unable to resolve 'mySound.mp3' for transcoding"

      event i change the sound url with mine, the eror still occur. anyone can tell me, how to embed the sound ?

        • 1. Re: Embed sound
          chris.huston.t10 Level 3
          Your code is fine but you need to put the sound file in the same directory as your Flex app or specify a different directory for the source. Flex is looking for the sound but cannot find it which is why you are getting the error.

          Vygo
          • 2. Re: Embed sound
            sutuy Level 1
            ya, it's works. thank's.
            after i check my code. i have fault in the source url :
            i just copy paste url from windows explorer : "C:\ConvertedFiles\pakmardi.mp3"
            and it must be "C:/ConvertedFiles/pakmardi.mp3".

            Thx for ur help Masamune ! ^_^