Link to home
Start Free TrialLog in
Avatar of designaire
designaireFlag for United States of America

asked on

add new sound to next scene

I'm using as3 and I have sound running using the page below. When it finishes it goes to the next scene. Is there anyway I can change the sound on the next page without repeating all the code with next functions etc... It also has stop, rewind and a next and previous button.
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
import flash.media.SoundTransform;

//btn_stop.addEventListener(MouseEvent.CLICK, stopScene);

var myChannel:SoundChannel = new SoundChannel();
var soundReq:URLRequest = new URLRequest("test_05.mp3");
var mySound:Sound = new Sound();
mySound.load(soundReq);
 
mySound.addEventListener(Event.COMPLETE, onComplete);

function onComplete (event:Event):void {
      var myChannel:SoundChannel = new SoundChannel();
      myChannel = mySound.play();
      myChannel.addEventListener(Event.SOUND_COMPLETE, soundFinished);
}
 
function soundFinished (event:Event):void {
      myChannel.addEventListener(Event.SOUND_COMPLETE, soundFinished);
      trace("my sound finished!");
	  gotoAndPlay(2, "Scene 2"); 
} 

var myTransform = new SoundTransform();
var lastPosition:Number = 0;
//myChannel = mySound.play();
myTransform.volume = 0.5;
myChannel.soundTransform = myTransform;

btn_rewind.addEventListener(MouseEvent.CLICK, onClickPlay);

function onClickPlay(e:MouseEvent):void{
	myChannel.stop();
	myChannel = mySound.play();
	myTransform.volume = 0.5;
}

btn_mute.addEventListener(MouseEvent.CLICK, onClickMuteOn);
function onClickMuteOn(e:MouseEvent):void{
	lastPosition = myChannel.position;
	myChannel.stop();
}

btn_playsound.addEventListener(MouseEvent.CLICK, onClickMuteOff);
function onClickMuteOff(e:MouseEvent):void{
		myChannel = mySound.play(lastPosition);
}

btn_back.addEventListener(MouseEvent.CLICK, goBack);
btn_next.addEventListener(MouseEvent.CLICK, goForward);

function goBack(event:MouseEvent):void {
    prevScene();
}

function goForward(event:MouseEvent):void {
    nextScene();
}

function stopScene(event:MouseEvent):void {
    stop();
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of designaire

ASKER

Thanks I wish I could understand it all. I know something about classes but perhaps not enough. The rewind button and the continue to the next button didn't seem to work however. I'll look at it more tormorrow and if you see anything that would cause that let me know (I will award you points reguardless)
Hi designaire,
Do you need my help or you can close this question?
Thanks,
David
Thanks, I'll work on it! I'll post again if I need it.