PDA

View Full Version : Buttons with multiple sounds


ToddziLLa
11-21-2002, 01:09 PM
Flash 5: I have a button. I have 3 sounds that I would like to be randomly played when that button is clicked on. Is there a script or even an easier way to do this? In other words, I have 3 different sounds that I would like to be played when the button is clicked, seperatelt of course. Any suggestions?

crabcake
11-21-2002, 02:04 PM
You can do it if you attach the sounds for ActionScripting, and then call them out using a random number, rather than dropping them onto the timeline. You need to go into the library and use the linkage option to export for ActionScripting. Give each of the sounds a sequential name as an identifier: something like mySound1, mySound2, mySound3.

In the timeline on which the button sits, you could then declare the sound

buttonSound = new Sound();

On the button you then attach code like

on(rollOver){
soundChoice = Math.ceil(Math.random() * 3);
buttonSound.attachSound("mySound" + soundChoice);
buttonSound.start();
}