Is it possible to limit a key press?

u see, i’ve done a key press and an animation leading to it… but, is there any way to limit it so dat it can be only be pressed for a given number of times…? after which when pressed, the animation will not be executed…

easy enough, I think.\r\radd to the button’s actions a counter like so\ron(release){\r if(buttonInaction<10){\r //any other actions go here\r buttonInaction++;\r }\r}\r\rthis should count each time the button is pressed and when it reaches 10 it will stop working…

thanks for your reply. but i have no idea where to fit it in. here’s my code >>>\r\rif (Key.isDown(Key.UP) && !_root.aGrid[_root.aPlayerPos[0] -1][_root.aPlayerPos[1]]) {\r _root.aPlayerPos[0] --;\r gotoAndPlay (“lbUp”);\r} else if (Key.isDown(Key.DOWN) && !_root.aGrid[_root.aPlayerPos[0] +1][_root.aPlayerPos[1]]) {\r _root.aPlayerPos[0] ++;\r gotoAndPlay (“lbDown”);\r} else if (Key.isDown(Key.LEFT) && !_root.aGrid[_root.aPlayerPos[0] ][_root.aPlayerPos[1]-1]) {\r _root.aPlayerPos[1]–;\r gotoAndPlay (“lbLeft”);\r} else if (Key.isDown(Key.RIGHT) && !_root.aGrid[_root.aPlayerPos[0] ][_root.aPlayerPos[1]+1]) {\r _root.aPlayerPos[1]++;\r gotoAndPlay (“lbRight”);\r} else if (Key.getCode() == 97) {\r gotoAndPlay (“throw 1”);\r} else if (Key.getCode() == 98) {\r gotoAndPlay (“throw 2”);\r} else if (Key.getCode() == 99) {\r gotoAndPlay (“throw 3”);\r} else if (Key.getCode() == 100) {\r gotoAndPlay (“throw 4”);\r} else if (Key.getCode() == 102) {\r gotoAndPlay (“throw 6”);\r} else if (Key.getCode() == 103) {\r gotoAndPlay (“throw 7”);\r} else if (Key.getCode() == 104) {\r gotoAndPlay (“throw 8”);\r} else if (Key.getCode() == 105) {\r gotoAndPlay (“throw 9”);\r} else {\r gotoAndPlay (_currentframe-1);\r}\r\ras you can see, when a key is pressed an animation is played. Now i want to limit this >> \r} else if (Key.getCode() == 97) {\r gotoAndPlay (“throw 1”);\r\rthanks…

I edited the post to get rid of those pesky Emoticons… they apear all in the code if you don’t turn them off.\r\rI’ll think about this. I think I’m going to need to print this out to decypher it. :slight_smile:

Without fully going through your code you can do this (sample taken from your script.\r\rif (Key.isDown(Key.UP) && !_root.aGrid[_root.aPlayerPos[0] -1][_root.aPlayerPos[1]] && upKey < 10) {\rupKey += 1;\r_root.aPlayerPos[0] --;\rgotoAndPlay (“lbUp”);\r} else if (Key.isDown(Key.DOWN) && !_root.aGrid[_root.aPlayerPos[0] +1][_root.aPlayerPos[1]] && downKey < 10) {\rdownKey += 1;\r_root.aPlayerPos[0] ++;\rgotoAndPlay (“lbDown”);\r\rIt may not be exactly what you’re after. If your looking to only have the user to press the keyboard 10 times no matter what key is pressed, then what about…\r\rif (pressKey < 10) {\rpressKey += 1;\rinsert all your other code in here\r}\r\rStill knowing me, I;m probably wrong. :slight_smile: \r\r\r(edited to remove Emoticons)

i’ll be waiting upuaut8… thanks…\r\rhmm, thanks aaron… i’ve looked through and tried, but i have no idea why it doesn’t work…\r\rand yeah, i was thinking of limiting d keypress regardless of any key… but how?

Sorry… been a little distracted trying to make changes on my guestbook and such. I haven’t forgotten about you.\r

I forgot all about this question until yesterday. Sorry.\r\rThis code is based on the concept that the source you have given above is inside a movieclip.\r\rTo limit a key press, the way I solved the puzzle required 2 movieclips. One the tester, and one that does the action.\r\rThe test clip I placed outside of the stage and called it testaction The actionscript for that clips is\r\ronClipEvent (keyDown) {\r pressKey ++;\r}\r\rThe movieclip with your code in it I called doaction It’s code is\r\ronClipEvent (enterFrame) {\r if (oldpressKey < _root.testaction.pressKey && oldpressKey < 11) {\r oldpressKey = _root.testaction.pressKey;\r // insert your required code here.\r }\r}\r\rAll you have to do then is change 11 to whatever limit you want in key presses. To quickly test that this code worked I just added the line\r\r_x += 10;\r\runder oldkeypress = _root.testaction.pressKey; which made doaction clip move everytime until I hit my key press limit of 10.\r\rLet me know if this works.

thankx aaron… i juz read your tip and i’m gonna try it out soon… i’ll get back to you if it works…

Here’s the cleaned up code. My brain is not working at all. Only need one movie clip, not two. God knows what I was thinking.\r\ronClipEvent (keyDown) {\r pressKey ++;\r}\ronClipEvent (enterFrame) {\r if (oldpressKey < pressKey && oldpressKey < 10) {\r oldpressKey = pressKey;\r // _x +=10; this is the line to test it, or where to insert your code\r }\r}\r\rSorry.