A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Checking for key PRESS not down

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    16

    Checking for key PRESS not down

    I need something to happen every time I press a button, let's say SPACE. Lets space pressing space shoots something, every time I hold down SPACE it keeps shooting. But I want it to only shoot when I press it and not if I hold it down. I am sure there is a simple way I am oblivious of,

    Thanks!

    Klaushouse

  2. #2
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Since you know how to check for the SPACE key then the only thing you need to do is define a boolean variable, let's say: bPressed and have an enter frame event listen for it. Depending on bPressed's state ( true or false ) you can tell the movie to do different stuff. You can have a separate function that only handles this case or you could modify your existing function so that when bPressed is true then it will know that it shouldn't keep on firing continuously, if bPressed is false that means that the button is not being pressed so it should do something else...

    It really depends on how you built the whole application, at the moment I'm only guessing. There might be other workaround too but since I don't know how your code looks like, I can't give you perfect solution.

    Good luck.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center