Skip to main content
Inspiring
July 13, 2010
Answered

loaded sound won't play..

  • July 13, 2010
  • 1 reply
  • 637 views

Can someone please help me out with this... Why won't my sound play? It should play on MousOver and stop on MouseOut... Thank you ahead of time!

stop();

import flash.display.MovieClip;
import flash.events.MouseEvent;

var req:URLRequest = new URLRequest("squeeak.wav");
var sound:Sound = new Sound();
var controller:SoundChannel;

function soundLoaded(event:Event):void
{
    controller = sound.play();
    controller.stop();

this.addEventListener(MouseEvent.ROLL_OVER, playSound);
this.addEventListener(MouseEvent.ROLL_OUT, stopSound);
this.addEventListener(MouseEvent.CLICK, onClickHandler);
this.addEventListener(MouseEvent.MOUSE_DOWN, onPressHandler);
this.addEventListener(MouseEvent.MOUSE_UP, onReleaseHandler);

}

// if you want a hand cursor
this.buttonMode = true;
this.useHandCursor = true;

function playSound(myEvent:MouseEvent) {
    trace("On");
    this.gotoAndPlay("one");
    controller = sound.play();
}
function stopSound(myEvent:MouseEvent) {
    trace("Out");
    this.gotoAndPlay("two");
    controller.stop();

}
function onClickHandler(myEvent:MouseEvent) {
    trace("I waited for Press AND Release!!!");
    this.gotoAndPlay("three");
}
function onPressHandler(myEvent:MouseEvent) {
    trace("Press");
}
function onReleaseHandler(myEvent:MouseEvent) {
    trace("Release");
    this.gotoAndPlay("four");
}


sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.load(req);

This topic has been closed for replies.
Correct answer kglad

because you're loading a wav.  try an mp3.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
July 13, 2010

because you're loading a wav.  try an mp3.

Inspiring
July 13, 2010

Thank you!!!! it Worked!

kglad
Community Expert
Community Expert
July 13, 2010

you're welcome.