【www.gdgbn.com--flex】

flasf cs3 里的liberty 有声音 可以是 mp3  wav 等,右键选 linkage 填入类名(我这里填BTNsound),然后将它拖到场景中,发布出来(我的命名是sound.swf),放到工程src文件夹里。在flex里新建一个 类(我的Loadsound.as)代码如下:

 package
{
 public class Loadsound
 {
  [Embed(source="Sound.swf",symbol="BTNsound")]//按钮
  public static var btnSound:Class;
 }
}

然后在 mxml 里

 layout="absolute" creationComplete="init();" >

private var Sbtn:Sound = new Loadsound.btnSound() as Sound;//按钮声音
private var soundVol:SoundTransform = new SoundTransform();//音量

internal function init():void{
      soundVol.volume = 1;
  }

private function onClink():void{

      Sbtn.play(0,0,soundVol);

}

OK!这种方式才是最简单的 最实用的!

方法一:

        panFrom="-1" panTo="1" loops="1" volumeFrom = "1" volumeTo="0.1" duration="3000" useDuration="false"/>


-------------------------分析------------
1 注意 2 注意

方法二:

官方文档的 在编译器里 按下 ctrl + f12 搜索sound 就有例子,这里不多说!

package { import flash.display.Sprite; import flash.net.URLRequest; import flash.media.Sound; import flash.media.SoundChannel; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.events.Event; import flash.events.IOErrorEvent; public class Sound_playExample3 extends Sprite { private var snd:Sound = new Sound(); private var channel:SoundChannel; private var statusTextField:TextField = new TextField(); public function Sound_playExample3(){ statusTextField.autoSize = TextFieldAutoSize.LEFT; var req:URLRequest = new URLRequest(http://av.adobe.com/podcast/csbu_dev_podcast_epi_2.mp3); try { snd.load(req); channel = snd.play(); } catch (err:Error) { trace(err.message); } snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler); addEventListener(Event.ENTER_FRAME, enterFrameHandler); channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); this.addChild(statusTextField); } private function enterFrameHandler(event:Event):void { var loadTime:Number = snd.bytesLoaded / snd.bytesTotal; var loadPercent:uint = Math.round(100 * loadTime); var estimatedLength:int = Math.ceil(snd.length / (loadTime)); var playbackPercent:uint = Math.round(100 * (channel.position / estimatedLength)); statusTextField.text = "Sound file"s size is " + snd.bytesTotal + " bytes.n" + "Bytes being loaded: " + snd.bytesLoaded + "n" + "Percentage of sound file that is loaded " + loadPercent + "%.n" + "Sound playback is " + playbackPercent + "% complete."; } private function errorHandler(errorEvent:IOErrorEvent):void { statusTextField.text = "The sound could not be loaded: " + errorEvent.text;        }          e            playing."        removeEventListener(Event.ENTER_FRAME, enterFrameHandler);        } 

本文来源:http://www.gdgbn.com/flash/22167/