PDA

View Full Version : Strange behavior with an attached sound


rrobnett
01-14-2010, 05:00 PM
Go to the following link http://www.stonehengeband.com.

Click on the Songlist menu, then click on the other menu items on the the keyboard. Hear a difference. This is strange nothing I do corrects theis issue. As can be seen in the code, the volume for the Songlist_btn is set to zero in the associated onRelease function.

Any ideas??

Here is the code associated with the menu

//------------------------------Menu--------------------------------------
//events button---------------------------------------------------
events_btn.onRollOver = function() {
events_btn.gotoAndStop("over");
}

events_btn.onRollOut = events_btn.onReleaseOutside = function() {
events_btn.gotoAndStop("normal");
}
events_btn.onPress = function() {
events_btn.gotoAndStop("press");
}
events_btn.onRelease = function() {
gotoAndStop("events");
var keySound:Sound = new Sound();
keySound.attachSound("keyboardSound");
keySound.setVolume(10);
keySound.start();
events_btn.gotoAndStop("normal");
displayReturn(949,118, "events");
loadMovieNum("calender.swf" , 99);
}
//pictures button-------------------------------------------------
pictures_btn.onRollOver = function() {
pictures_btn.gotoAndStop("over");
}
pictures_btn.onRollOut = pictures_btn.onReleaseOutside = function() {
pictures_btn.gotoAndStop("normal");
}
pictures_btn.onPress = function() {
pictures_btn.gotoAndStop("press");
}
pictures_btn.onRelease = function() {
gotoAndStop("photos");
var keySound:Sound = new Sound();
keySound.attachSound("keyboardSound");
keySound.setVolume(10);
keySound.start();
pictures_btn.gotoAndStop("normal");
displayReturn(500,118, "pictures");
loadMovieNum("photo_gallery.swf" , 99);
}
//songlist button-------------------------------------------------
songlist_btn.onRollOver = function() {
songlist_btn.gotoAndStop("over");
}
songlist_btn.onRollOut = songlist_btn.onReleaseOutside = function() {
songlist_btn.gotoAndStop("normal");
}
songlist_btn.onPress = function() {
songlist_btn.gotoAndStop("press");
}
songlist_btn.onRelease = function() {
gotoAndStop("songlist");
var keySound:Sound = new Sound();
keySound.attachSound("keyboardSound");
keySound.setVolume(0);
keySound.start();
songlist_btn.gotoAndStop("normal");
loadMovieNum("mp3player.swf" , 99);
displayReturn(50,118, "songlist");
}
//videos button-------------------------------------------------
videos_btn.onRollOver = function() {
videos_btn.gotoAndStop("over");
}
videos_btn.onRollOut = videos_btn.onReleaseOutside = function() {
videos_btn.gotoAndStop("normal");
}
videos_btn.onPress = function() {
videos_btn.gotoAndStop("press");
}
videos_btn.onRelease = function() {
gotoAndStop("videos");
var keySound:Sound = new Sound();
keySound.attachSound("keyboardSound");
keySound.setVolume(10);
keySound.start();
displayReturn(500,118, "videos");
videos_btn.gotoAndStop("normal");
loadMovieNum("video_gallery.swf" , 99);
}

Continuity-B
01-14-2010, 09:10 PM
There's no need to declare, create, attach a sound to and set the volume of a new Sound object within each event handler; you're duplicating code. Just do it once outside all the functions and you'll be able to target it all the same from within them.

That should negate your problem, although I can't see the cause of it immediately.

eg, put all this...


var keySound:Sound = new Sound();
keySound.attachSound("keyboardSound");
keySound.setVolume(10);

...on it's own before the event handlers, then just use...

keySound.start();

...from within each.

rrobnett
01-14-2010, 10:03 PM
Originally I did have the it written as you suggest, but the problem was still there. I changed it, to the way it was in my last post, to see if that had any effect.

I found a cure for the problem since I posted this.


var keySound:Sound = new Sound();
keySound.attachSound("keyboardSound");
keySound.setVolume(15);

//songlist button-------------------------------------------------
songlist_btn.onRollOver = function() {
songlist_btn.gotoAndStop("over");
}
songlist_btn.onRollOut = songlist_btn.onReleaseOutside = function() {
songlist_btn.gotoAndStop("normal");
}
songlist_btn.onPress = function() {
songlist_btn.gotoAndStop("press");
}
songlist_btn.onRelease = function() {
gotoAndStop("songlist");
songlist_btn.gotoAndStop("normal");
displayReturn(50,118, "songlist");
keySound.start();
keySound.onSoundComplete = function() {
loadMovieNum("mp3player.swf" , 99);
}
}

I don't know why it needs the onSoundComplete function for this one and not the others????