Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash AS3:Multiple function in one key?

Etc: if I press "space" key, inventory opens.But if I press "space" again, inventory should close.What should I use for this kind of thing?I can open it, but cant close.Thanks, sorry for bad english.(P.S: Im using flashdevelop+flixel)

like image 403
user1533057 Avatar asked Jun 06 '26 13:06

user1533057


1 Answers

Yes, this is completely possible.

var isInventOpen:Boolean = false;
function openCloseInvent(e:KeyboardEvent):void
{
    if(e.keyCode == Keyboard.SPACE && isInventOpen == false)
    {
         //Open Inventory
         isInventOpen = true;
    }

    if(e.keyCode == Keyboard.SPACE && isInventOpen == true)
    {
         //Close Inventory
         isInventOpen = false;
    }
}

More info on KeyCodes can be found here: KeyCodes, if you need it.

like image 183
Andre Angelo Avatar answered Jun 08 '26 03:06

Andre Angelo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!