<button id="ptu4h"><acronym id="ptu4h"><input id="ptu4h"></input></acronym></button>

<tbody id="ptu4h"></tbody>

    <dd id="ptu4h"><center id="ptu4h"></center></dd><dd id="ptu4h"></dd><dd id="ptu4h"><track id="ptu4h"><video id="ptu4h"></video></track></dd>
  • 16素材
    您現在的位置:首頁 > 教程中心 > Flash教程

    柔性里播放聲音的方法

     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 里

    <mx:Application xmlns:mx="http://down.flashye.com/jc/153/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);

    }

    <mx:Button x="129" y="397" label="Button" clink="onClink();"/>

    OK!這種方式才是最簡單的 最實用的!

    方法一:

    <mx:SoundEffect id="sound_effect" source="sound.mp3"
    panFrom="-1" panTo="1" loops="1" volumeFrom = "1" volumeTo="0.1" duration="3000" useDuration="false"/>

    <mx:Button x="44" y="181" label="Button" width="103" mouseDownEffect="{sound_effect}"/>
    <mx:Text x="44" y="145" text="點擊鼠標,播放音效" width="129"/>

    -------------------------分析------------
    1 注意<mx:SoundEffect的source定義了聲音的來源,和一般的Effect的target屬性不同。
    2 注意<mx:Button的mouseDownEffect屬性

    方法二:

    官方文檔的 在編譯器里 按下 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://down.flashye.com/jc/153/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. " + "Bytes being loaded:
    " + snd.bytesLoaded + " " + "Percentage of sound file that is loaded " + loadPercent + "%. " +
    "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); }
    <!-- -->
    關鍵詞: 柔性播放聲音

    相關素材

    聯系客服 加入QQ群
    素材中国