all groups > flash actionscript > november 2007 >
You're in the

flash actionscript

group:

Actionscript button problems


Actionscript button problems Dimcloud
11/2/2007 4:13:23 PM
flash actionscript:
I'm doing a flash based web site for school and need help with buttons i am
making. They are "piano" keys in which i need them to play a sound when i press
the button down, but the sound should stop when i release the button. Please I
really need the help!!


Re: Actionscript button problems jmoggio
11/2/2007 7:57:19 PM
try

on(release){
stopAllSounds();
Re: Actionscript button problems clbeech
11/3/2007 2:37:04 AM
create your sounds using AS Sound Objects, then target the Sound Object using
code. With a sound (preferably mp3) in the Library, and a Linkage identifier
specific to the sound, on the timeline of the 'key' MC wirte the following:

PS. in this example I have used the Linkage id of 'note_C', and a SoundObject
instance name of 'key_C'. you will want to elaborate on the references to
different octives. Also the two parameters in the Sound.start() method, are
1)the offset seconds, and 2) the amount of loops the instance will play.
Assuming that you will want to keep the file size as small as possible, you
will only need a sound bite of a second or two, and then it will loop
continuously (well 999 times here but you can set it higher) then it will stop
when the button is released.

stop();

var key_C:Sound = new Sound(this);
Sound.attachSound('note_C');

this.onPress = function() {
key_C.start(0, 999);
}

this.onRelease = function() {
Key_C.stop();
}
AddThis Social Bookmark Button