-
Sound looping when arrow keys pressed down?
Hey all, i have a loopable sound effect of footsteps in my flash.
Im trying to figure out a way to have it play whenever one or more of the Arrow keys are pressed down and then immediatly stop when theyre not.
Haven't have much luck, the ways ive been trying its either been duplicated sound or the sound loop plays out Before stopping.
Any suggestions on how to solve this? Thanks!
-
.
Hi,
AS2 or AS3?
Can you attach what you already have save us reinventing things and sounds
Or at lease a file with the sound file and your loop init
-
.
Hi,
If it's AS2 then you can try this, with a sound in the library AS linkage name of step, I'm sure you can alter any names to suit yourself.
PHP Code:
var keyDownListener:Object = new Object();
var keyUpListener:Object = new Object();
keyDownListener.onKeyDown = function()
{
if (Key.isDown(Key.LEFT) || (Key.isDown(Key.RIGHT)) || Key.isDown(Key.UP) || (Key.isDown(Key.DOWN)))
{
Key.removeListener(keyDownListener);
Key.addListener(keyUpListener);
doLoop = true;
loopSound();
}
};
keyUpListener.onKeyUp = function()
{
if (Key.isDown(Key.LEFT) || (Key.isDown(Key.RIGHT)) || Key.isDown(Key.UP) || (Key.isDown(Key.DOWN)))
{
// do nothing if any arrow keys still pressed
}
else
{
doLoop = false;
stopSound();
}
};
Key.addListener(keyDownListener);
function loopSound()
{
snd = new Sound();
snd.attachSound("step");
snd.start();
snd.onSoundComplete = function()
{
stopSound();
};
}
function stopSound()
{
if (doLoop)
{
loopSound();
}
else
{
snd.stop();
Key.addListener(keyDownListener);
}
}
If it's AS3 then I'm sure you could convert it over
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|