PDA

View Full Version : Sound Problems


wyclef
05-27-2003, 05:07 PM
Hi, I'm having trouble with this script. I'm trying to set it up so if a sound is already playing, and you click on a button that should be playing the same sound it just keeps playing instead of starting over, but the only result i get out of this script is a sound plays once only when you press the mouse button down and then when you release the mouse button no sounds will play anymore. Your help would be appreciated, thanks.


overSound = new Sound();
overSound.attachSound("sound1");
clickSound = new Sound();
clickSound.attachSound("sound2");

infoSound = new Sound();
infoSound.attachSound("info");
mediaSound = new Sound();
mediaSound.attachSound("media");
contactSound = new Sound();
contactSound.attachSound("contact");
linksSound = new Sound();
linksSound.attachSound("links");
merchandiseSound = new Sound();
merchandiseSound.attachSound("merchandise");
homeSound = new Sound();
homeSound.attachSound("home");

mySounds = [infoSound, mediaSound, contactSound, linksSound, merchandiseSound];

biography_btn.onRollOver = news_btn.onRollOver = events_btn.onRollOver = function() {
overSound.start(0, 1);
};
biography_btn.onPress = news_btn.onPress = events_btn.onPress = function() {
clickSound.start(0, 1);
if (alreadyPlaying != true) {
infoSound.start(0, 999);
alreadyPlaying = true;
}
};
biography_btn.onRelease = function() {
gotoAndPlay(15);
for(var i=0;i<this._parent.mySounds.length;i++){
this._parent.mySounds[i].stop();
image_loader.unloadMovie();
}
};
news_btn.onRelease = function() {
gotoAndPlay(17);
for(var i=0;i<this._parent.mySounds.length;i++){
this._parent.mySounds[i].stop();
image_loader.unloadMovie();
}
};
events_btn.onRelease = function() {
gotoAndPlay(19);
for(var i=0;i<this._parent.mySounds.length;i++){
this._parent.mySounds[i].stop();
image_loader.unloadMovie();
}
};

photos_btn.onRollOver = audio_btn.onRollOver = video_btn.onRollOver = function() {
overSound.start(0, 1);
};
photos_btn.onPress = audio_btn.onPress = video_btn.onPress = function() {
clickSound.start(0, 1);
if (alreadyPlaying != true) {
mediaSound.start(0, 999);
alreadyPlaying = true;
}
};
photos_btn.onRelease = function() {
gotoAndPlay(30);
for(var i=0;i<this._parent.mySounds.length;i++){
this._parent.mySounds[i].stop();
image_loader.unloadMovie();
}
};
audio_btn.onRelease = function() {
gotoAndPlay(32);
for(var i=0;i<this._parent.mySounds.length;i++){
this._parent.mySounds[i].stop();
image_loader.unloadMovie();
}
};
video_btn.onRelease = function() {
gotoAndPlay(34);
for(var i=0;i<this._parent.mySounds.length;i++){
this._parent.mySounds[i].stop();
image_loader.unloadMovie();
}
};

farafiro
06-01-2003, 10:46 AM
why don't disable the button's which its song's currently playing ;)

wyclef
06-01-2003, 04:43 PM
i have to leave those buttons active because they provide access to important areas

farafiro
06-02-2003, 08:15 AM
put all the onPress code into an onRelease

wyclef
06-30-2003, 04:38 AM
would this code make a difference if I used MCs instead of actual buttons?

farafiro
06-30-2003, 07:02 AM
I don't think so, why??

wyclef
06-30-2003, 02:50 PM
are you positive?

farafiro
06-30-2003, 02:58 PM
HUH :confused: :confused:

wyclef
06-30-2003, 03:00 PM
are you sure that it wuoldn't make a difference if I changed the buttons to MCs?

farafiro
06-30-2003, 03:07 PM
in this case, YES

wyclef
06-30-2003, 03:27 PM
Ok, here is the updated code. Let me try to explain a bit what i'm trying to do with the sound because the way i'm doing it now is not working.

If you notice, there are 5 sets of buttons. Each set has the same sound loop associated with it. What i'm trying to do is create a way where if btn1 for instance is selected, and infoSound is playing, I can click btn2 and have infoSound keep playing instead of starting over again. Let me know if this makes anymore sense.




// --------------------------------------------------------------------------------------
this.createEmptyMovieClip("soundMC", 1);

mySoundLinkages = ["over", "click", "home", "media", "info", "contact", "links", "merchandise"];

mySounds = [];

while (mySoundLinkages.length) {
n = mySoundLinkages.shift();
s = this[n + "Sound"] = new Sound(soundMC.createEmptyMovieClip(n+"Sound", ++soundMC.depth));
s.attachSound(n);
mySounds.push(s);
}

delete mySoundLinkages;

delete n;
delete s;
// --------------------------------------------------------------------------------------
Button.prototype.setSounds = function(frameNum, soundObject) {
this.onRelease = function() {

for(var i in this._parent.mySounds){
var s = this._parent.mySounds[i];

if (s == soundObject) {

if (!s.alreadyPlaying) {
s.alreadyPlaying = true;
s.start(0, 999);
}

} else {

s.alreadyPlaying = false;
s.stop();
}
}

image_loader.unloadMovie();
gotoAndPlay(frameNum);
};
};
// --------------------------------------------------------------------------------------
for (var i = 1; i<=17; i++) {
this["btn" + i].onRollOver = function() {
overSound.start(0, 1);
};
}
// --------------------------------------------------------------------------------------
for (var i = 1; i<=17; i++) {
this["btn" + i].onPress = function() {
clickSound.start(0, 1);
};
}
// --------------------------------------------------------------------------------------
btn1.setSounds(15, infoSound);
btn2.setSounds(17, infoSound);
btn3.setSounds(19, infoSound);

btn4.setSounds(30, mediaSound);
btn5.setSounds(32, mediaSound);
btn6.setSounds(34, mediaSound);

btn7.setSounds(45, contactSound);
btn8.setSounds(47, contactSound);
btn9.setSounds(49, contactSound);
btn10.setSounds(51, contactSound);
btn11.setSounds(49, contactSound);
btn12.setSounds(51, contactSound);

btn13.setSounds(60, linksSound);
btn14.setSounds(62, linksSound);

btn15.setSounds(75, merchandiseSound);
btn16.setSounds(77, merchandiseSound);

btn17.setSounds(1, homeSound);

farafiro
07-02-2003, 08:35 AM
yup, I can understand that
but sin't the over/click sounds should be that small as they doesn't need a check to be so??

farafiro
07-02-2003, 02:38 PM
I mean that these sounds' durations shouldn't be that large, so u don't need sucha code

wyclef
07-13-2003, 11:05 PM
Hi, I updated the script from post 06-30-2003. Now things are starting to work a little better. Just one more question.... I added btn17 which would represent the home button, so whenever you click on it to go home it would play a sound for the homepage. This works, but how can I tell homeSound to already be playing when you first come to the home page?

farafiro
07-14-2003, 04:30 AM
huh
r u sure u wanna do this??
just attach it on the HOME frame

wyclef
07-21-2003, 12:51 PM
Yes, I'm sure. I've already created all these sound objects, there has to be a way to have homeSound start playing on the first frame. and stop when the movie is sent to other frames. If there is anyone out there that can help me with this that would be great.

farafiro
07-27-2003, 04:40 AM
have u tried what I've told ya??