PDA

View Full Version : Sound and KeyDown


plugwatson
03-28-2003, 10:47 PM
Hello, Please help, I had the sound working on the timeline and also had a trace in the keydown so why isn't it playing?
[AS]
onClipEvent (keyDown) {
this.KEYsound.stop();
this.KEYsound.start(0, 1);
}
onClipEvent (load) {
this.KEYsound = new Sound();
this.KEYsound.attachSound("KEY");
this.KEYsound.setVolume(100);
}
onClipEvent (keyUp) {
this.KEYsound.stop();
}

dybenko
03-29-2003, 12:11 AM
It looks to me as though you are calling the stop() function for both the keyUp and keyDown positions... and using (this) to identify both.

That doesn't leave much options for the player - basically just stop! ;)


If you could explain a little more what exactly you have in the way of where the sound is located (in which clip) it would help.

plugwatson
03-29-2003, 09:41 PM
onClipEvent (keyDown) {
this.KEYsound.stop(); //stop the sound if already playing
this.KEYsound.start(0, 1); // play the *%^@ing sound
}
onClipEvent (load) {
this.KEYsound = new Sound();
this.KEYsound.attachSound("KEY");
this.KEYsound.setVolume(100);
}
onClipEvent (keyUp) {
this.KEYsound.stop();
}

senocular
03-29-2003, 10:08 PM
1) make sure the linkage ID is correct
2) make sure nothing else (outside code) is interupting the sound preventing it to operate correctly

3) ... watch what happens when I press and hold the A key:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
^the A key gets 'pressed' a lot in succession from my holding it down. The Flash player sees each one of those 'presses' as a onClipEvent(keyDown) event, so each time one of those key iterations occur you are stopping and restarting the sound. You can use a simple flag variable to get around this, set it true to start (load) check to see if its true in the keydown, if so in that if block play the sound and set fag to false, then in a key up set it to true again.

plugwatson
03-30-2003, 07:34 PM
thanks i'll check what you send, the sound is for a typewriter sound, so a new key down if typed quick enough should be a trigger for a new keydoen