Not yet rated

Problem

Start and Stop sound with buttons.

Solution

Using URLRequest and events

Detailed explanation

var req:URLRequest=new URLRequest("sound.mp3");
var mySound:Sound=new Sound  ;
var myController:SoundChannel;
mySound.load(req);
mySound.addEventListener(Event.COMPLETE, mySoundLoaded);

function mySoundLoaded(event:Event):void {
    play_btn.addEventListener(MouseEvent.CLICK, playMySound);
    stop_btn.addEventListener(MouseEvent.CLICK, stopMySound);
}

function playMySound(event:MouseEvent):void {
    myController=mySound.play();
}

function stopMySound(event:MouseEvent):void {
    myController.stop();
}

 

 

Need create buttons which will play and stop sound file.

 

Thank  you for reading.

Sours  you can find in attached file.


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes