At 10/27/14 09:52 AM, Diki wrote:
You will need to set some sort of global boolean state to true when the KEY_DOWN event is fired and set it to false when the KEY_UP event is fired, and then simply use an if-statement to check the state of said boolean.
I wrote a tutorial on the subject some time ago that goes into depth regarding how to accomplish that. MSGHero also wrote an AS3 class that does the same thing, but I have not personally used it so I cannot vouch for its efficacy (not that I have any reason to think it won't work just fine).
Why not remove the event listener for checking keys, then add them back again in the key up event? Having a dictionary seems a bit complicated imo. Only limitation is that no keys can be held down. Like:
import flash.events.KeyboardEvent;
function keydown(evt:KeyboardEvent)
{
trace(evt.keyCode, "is pressed")
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keydown)
stage.addEventListener(KeyboardEvent.KEY_UP, keyup)
}
function keyup(evt:KeyboardEvent)
{
trace(evt.keyCode, "is released")
stage.addEventListener(KeyboardEvent.KEY_DOWN, keydown)
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, keydown)