designaire
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();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi designaire,
Do you need my help or you can close this question?
Thanks,
David
Do you need my help or you can close this question?
Thanks,
David
ASKER
Thanks, I'll work on it! I'll post again if I need it.
ASKER