The Key.isDown
I know to make a user hold down a key in a MC you do the code:
Code:
if (Key.isDown(Key.SPACE)) {
// do stuff
}
But how do I make it to when you hold down a key like H or M and it does something?
FlashKit > Flash Help > Flash ActionScript
Posted on: 10-19-2005, 09:00 PM
View Complete Forum Thread with Replies
Sponsored Links:
Mouse Left Button IsDown: Key.isDown(1) Doesn't Work On Macs
Some of you may or may not be aware that the following code can detect that the mouse button is down. (Something that's oddly missing from the Flash API.)
Code:
if (Key.isDown(1)){
trace("left mouse button down");
}
if (Key.isDown(2)){
trace("right mouse button down");
}
However, this has been reported to not work on Mac computers!
I do not recommend using / relying on the above code.
The question is: Is anyone aware if there exists a Key Code for the Mac mouse button?
I do not own a Mac and do have close contacts to people with one, so I cannot test this for myself.
View Replies !
View Related
Mouse Left Button IsDown: Key.isDown(1) Doesn't Work On Macs
Some of you may or may not be aware that the following code can detect that the mouse button is down. (Something that's oddly missing from the Flash API.)
Code:
if (Key.isDown(1)){
trace("left mouse button down");
}
if (Key.isDown(2)){
trace("right mouse button down");
}
However, this has been reported to not work on Mac computers!
I do not recommend using / relying on the above code.
The question is: Is anyone aware if there exists a Key Code for the Mac mouse button?
I do not own a Mac and do have close contacts to people with one, so I cannot test this for myself.
View Replies !
View Related
[F8] Key.isDown(8) And Key.isDown(Key.BACKSPACAE) Problem
Hey,
I need to know when the backspace key is pressed. I've added a key listener and everything seems to work. However, the backspace key ONLY works if I click inside an input text box and then press it - otherwise the keyListener.onKeyDown function isn't called.
I don't want to use an input text box - I want the function to call without it - so how do I fix this?
Thanks for any help!
EDIT: I've just noticed that the same is happening for the "." and "," keys. No other keys do this, as far as I can see.
View Replies !
View Related
Getting Two Coordinates On Key.isDown(1) And On Key.isDown(1)
Hi Ive tried like hell to do the following little script but invane.
I want to hold down the mouse button - Key.isDown(1)
- record the coordinates where the mouse button is clicked
Move the mouse cursor arround while holding down the mouse button.
When the mousebutton is released - !Key.isDown(1)
- record the coordinate where the button is released.
I can make a textbox and display the coordinates of the mouse at all times - but only recording the FIRST coordinate (when mouse i held) and the LAST (when mouse is released) seems to be very hard?
Anyone know how this could be done?
Is there an alternative to isDown? isPressed or something like that which I've missed?
Cheers,
Mads
View Replies !
View Related
If (Key.isDown(Key.RIGHT And Key.DOWN))?
is there a way to make the key down recognize when you press two arrow keys to make something move diagonally? I want to make it show a diagonal walk sequence when i press two of the arrow keys but ... can't figure it out i'm sure it's easy. I know how to make the walking sequece show up ... just not how to make it recognize the two keys pressed.
View Replies !
View Related
Key.isDown
I am trying to control something using ascii characters for keys
Key.isDown(99)
99 is the 'c' key but I think syntax is wrong above
Key.isDown(Key.DOWN)
this is ok!
Regards
DL
View Replies !
View Related
How To Use Key.isDown
Hello!
This will be simple. I would like to know, if it is possible to use Key.isDown(Key.SOMEKEY)... without assigning it to an object. I have seen this example in flash help:
code:
onClipEvent (enterFrame) {
if(Key.isDown(Key.RIGHT)) {
this._x=_x+10;
} else if (Key.isDown(Key.DOWN)) {
this._y=_y+10;
}
}
Is it possible to stop _root by it without putting the code on a MC?
Thanks!
View Replies !
View Related
Key.isDown
I am using FLah MX 2005.
code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_root.speed += 1;
}
}
when i hold the left arrow down it keeps adding 1 i want it to only add 1 for every press or when i release
View Replies !
View Related
Key.isDown HELP
I have the following code as a pause button as my game is run threw a timer...
Code:
onClipEvent (enterFrame) {
_root.frame = _root.timer._currentframe;
if ((Key.isDown(Key.SPACE)) and (_root.pauser._currentframe == 1)) {
_root.timer.gotoAndStop(_root.frame);
_root.pauser.gotoAndStop(2);
} else if ((Key.isDown(Key.SPACE)) and (_root.pauser._currentframe == 2)) {
_root.timer.gotoAndPlay(_root.frame);
_root.pauser.gotoAndStop(1);
}
}
When i press space the pause MC appears and then disperes. I know why this happens but i cant figure out a way around it...
View Replies !
View Related
Key.isDown(13)
I seem to be having a silly problem, I just learned how to use listeners to avoid having to use loops for certain situations, and for somereason the code below doesnt work when I see if enter (13) has been pressed, but works for anyother key, whats going on ?
Code:
input_text = new String();
text_enter = new Object();
text_enter.onKeyDown = function() {
if (Key.isDown(13)) {
trace("ENTER WAS PRESSED");
}
};
Key.addListener(text_enter);
View Replies !
View Related
[AS2] [CS3] If Key.isDown
Its annoying me now I basically want to make it so if the user presses the keys
shift + l then my mc instance = my instance is toggled on and off
Code:
if (eatpane._visible = false && Key.isDown(Key.SHIFT && Key.isDown(108))) {
eatpane._visible = true;
information = rtext[9];
}else if (eatpane._visible = true && Key.isDown(Key.SHIFT && Key.isDown(108))) {
eatpane._visible = false;
information = rtext[10];
}
If anyone can fix it I would be very grateful
View Replies !
View Related
Key.isDown() Help
Key.isDown(Key.LEFT)
this code above basically means when i press LEFT key, the character moves left...
now what i want to do is when i press "A", the character moves left... but i have no idea how to code that using Key.isDown() method...
can anyone here provide help please?
thnx a lot...
View Replies !
View Related
Key.isDown?
Hello everyone, I'd like to know how to fix up this bit of code:
ActionScript Code:
if (Key.isDown(Key.SPACE)) {
Balloon._y -= 150;
Balloon1._y -= 150;
Balloon2._y -= 150;
Balloon3._y -= 150;
Balloon4._y -= 150;
Balloon5._y -= 150;
Balloon6._y -= 150;
}
You see.. I need it so everytime the person just presses the spacebar once, the balloons move up. But whenever you hold the spacebar it goes up, I need to get rid of that function.. I just need the press once one.
Thanks.
View Replies !
View Related
Key.isDown(Key.A) ?
I was wondering... what kind of code is required to make a
ActionScript Code:
If(Key.isDown(Key.A)){
line.
What I want is something to happen when the Key "A" (or any other key for that matter, not the DOWN, LEFT, UP, DOWN, SHIFT, ENTER etc) is pressed.
Anyone got a clue?
View Replies !
View Related
Key.isDown
I have a simple driving game of which the Key class is used to navigate the vehicle token. Where _root.number = # is the left, right, up, and down border limits.
It works flawlessly on a Windows environment using IE or Firefox. However NeoWare Thin Client envrionment running Linux w/ Firefox the arrow keys do not respond.
Would Linux recognize the ASCII code better? If so, can someone point me to a library with the codes. Or perhaps other suggestions.
Also, I thought about trying a different set of keys to navigate such as: I, J, K, and M respectively thinking that perhaps the arrow keys on these particular clients are mapped in such away to prevent additional interaction.
Here's the code:
function captureKeys() {
if (Key.isDown(Key.RIGHT)) {
_root.number = 3;
keyPressed = true;
} else if (Key.isDown(Key.LEFT)) {
_root.number = 4;
keyPressed = true;
}
if (Key.isDown(Key.DOWN)) {
_root.number = 2;
//keyPressed = true;
} else if (Key.isDown(Key.UP)) {
_root.number = 1;
keyPressed = true;
}
_root.onEnterFrame = function() {
captureKeys();
};
Thanks for any help
View Replies !
View Related
Key.isDown
Hello everyone.
I have a simple code which allows you to skip ahead in the timeline by pressing Enter, which works great. However, when I have klicked on it and are on the frames that do not contain this script, it's still clickable.
Does anyone know why?
Attach Code
onEnterFrame=function()
{
if (Key.isDown(Key.ENTER)) {
gotoAndPlay(210);
}
}
View Replies !
View Related
(key.isDown())
i have a mc, with 3 frames, it has a stop(); on the first frame,
when the 'n' key is pressed, i want it to gotoAndStop(2);
this is what i have:
ActionScript Code:
onClipEvent(enterFrame) { if (key.isDown(78)); { this.gotoAndStop(2); } }
but it just goes straight to the second frame, with out the 'n' key being pressed, anyone know why?
View Replies !
View Related
Key.isDown... [FMX]
Hi all,
I am trying to use th following code to animte an object across the screen:
if (Key.isDown(Key.LEFT)) {
speed++;
clip._x -= speed/5;
trace(speed);
}
speed is a variable with a set number.
the effect is a sort of acceleration.
The problem I have is: How do I reset the speed after when the Key is not down?
View Replies !
View Related
Key.isDown
hey.
i have a word game. there are some words that are randomly selected. and players just see one word and try to produce new words from that. you know classic word game.
i want players to use keyboard. for example if the word is MONDAY and a player write DAY, he / she would able to write DAY with keyboard.
Letters = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "R", "S", "T", "U", "V", "Y", "Z");
Codes = new Array(65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 89, 90);
this is the array. but how can i use this. i cant do that.
thanks in idvance.
View Replies !
View Related
Key.isDown?
this time I got a little problem with teh key.isdown stuff...
Basically I want to make a key that goes to another frame.. for example, when I press space...
Thers my code...
if (Key.isDown(32)) {
gotoAndStop(2);
}
Im not that sure where I should put it so I putted it on a MC in my first frame. The problem is that it does not work.. and I would like to know why and how to fix it.. ^^;
[edit] nvm, alredy figured it out.. -.-..
ps: where can I delete this post?
View Replies !
View Related
Key.isDown(Key.?)
I am making a kind of multiplayer game for fun but I'm having trouble with the controls.
For one of the characters it works fine since I'm using
Key.isDown(Key.LEFT)
and so forth with UP, RIGHT and DOWN
The trouble comes when I try to specify the keys for player 2. I found out that all buttons have ASCII codes and I found the codes for the buttons i need but when it comes to putting them in the script I'm all noob.
Doesn't work when I just put the numbers in like this
Key.isDown(Key.71)
If you know how to put in the codes properly please enlighten me
View Replies !
View Related
(key.isDown())
i have a mc, with 3 frames, it has a stop(); on the first frame,
when the 'n' key is pressed, i want it to gotoAndStop(2);
this is what i have:
ActionScript Code:
onClipEvent(enterFrame) { if (key.isDown(78)); { this.gotoAndStop(2); } }
but it just goes straight to the second frame, with out the 'n' key being pressed, anyone know why?
View Replies !
View Related
If(Key.isDown(?)){
its been a while since i posted.. hello guys.
I was trying to make a 2 player game where u have ur own tank that u move around and fire from and blah blah.. i did controls for player one:
if(Key.isDown(89)){ // Y Key
//speed up
}
if(Key.isDown(72)){ // H Key
//slow down
}
if(Key.isDown(74)){ // J Key
//ROTATE TANK RIGHT
}
if(Key.isDown(71)){ // G Key
//ROTATE TANK RIGHT
}
ok so thats tank controls for player one.. but for player 2, i want the controls to be:
speed up: Num 5
slow down: num 2
turn left: num 1
turn right: num3
how do i do this?
i tried (Key.isDown(53)) for Num5 but that doesnt work.. it works when i press "5" key above the "R" Key..
hope i dint confuse you..
thanks for your time
-tan
View Replies !
View Related
Something Like The If(key.isdown(something))
My very simple question is this:
Is there any simple function like if(key.isdown(something)) that only notices when you first press the key and not when you're holding it down? I know there's the on (keyPress "<Space>"), but that doesn't work inside an onClipEvent() thing. Of course I could still theoretically work my way around it by using the on (keypress "<Space>") thing outside of the onClipEvent, but it would get quite tedious with all the if's and everything.
Any help would be great.
View Replies !
View Related
Key.isDown &&
simple action:
i want my character to jump left and right. right now its possible to jump up only.
i tried this for that matter:
Code:
if(Key.isDown(Key.UP && Key.LEFT)){
this.jumpani_mc.play();
if (_root.bg_mc._x <= 850){
_root.bg_mc._x = _root.bg_mc._x+15; // moves background 15px to the right
}
}
seems both keys do not work at the same time using an "onClipEvent(onEnterFrame)"
any quick ideas are very very appreciated!
tommy
View Replies !
View Related
(Key.isDown(key.RIGHT))
I need help to understand why the code above, that is attached to a mc in the _root, works well in .exe and .swf, but doesn't run in html.
thanks a lot for any help.
JGraca
onClipEvent (load) {
x = this._x;
y = this._y;
veloc = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(key.RIGHT)) {
if (x<=200) {
x += veloc;
................
................
}
}
this._x = x;
this._y = y;
}
View Replies !
View Related
Key.isDown Works Sometimes HELP
I've got some code which seems to be working for me, but not for some other people! Something to do with different keyboards???? It's very simple.
f (!suspended) {
if (Key.isDown(Key.RIGHT)) {
_root.moveRight();
} else if (Key.isDown(Key.LEFT)) {
_root.moveLeft();
}
if (Key.isDown(Key.DOWN)) {
_root.moveDown();
} else if (Key.isDown(Key.UP)) {
_root.moveUp();
}
}
function suspendMotion() {
trace("suspending motion");
suspended=true;
}
function allowMotion() {
trace("restarting motion");
suspended=false;
}
View Replies !
View Related
Key.isDown Problem
hi i am making a top down racing game and want to have 2 players racing at the same time (on the same keyboard)
player 1 works fine using Key.isDown(Key.UP) but when i try and use ascii numbers it doesnt work with letters.
it works if i use the ascii numbers for numbers eg number 1 = 49 - this will make my car move forward, but when i use the ascii code for the letter w (119) it doesnt work. any ideas why? do i need to let flash know it is a letter ?
if (Key.isDown(119)) {
velocity += 1;
}
this is my current code...
View Replies !
View Related
Key.isDown For Mouse
Hi.
Is it possible to use the Key.isDown command to detect the left button of my mouse? Something like Key.isDown(mousedown);
Would there be any ascII value for the mouse button?
I know I could use an invisible button covering the whole movie and use the on(press) method but I was wondering if there was another way.
View Replies !
View Related
Key.isDown Problems
Hi everybody, here's my problem- i hope you guys are better at this than i am hehe.
I have a button in frame 3 of my animation that opens a URL. Unfortunately, this actionscript won't seem to get me there. I would only like to be able to see frame 3 if i push the 'Shift' Key, also known as number 16.
This works in the test .swf in flash, but not on my site- any ideas?
///actionscript here
if (Key.isDown(16)) {
gotoAndPlay (3);
}
///button actionscript in frame 3
on (release) {
getURL ("www.blah.com", "_blank");
}
PS.: yes, i do have a stop action on frame 3.
View Replies !
View Related
Key.isDown Troubles
Thanks in advance for any assistance you can offer.
I'm trying to do a simple key press action to move to next scene (right arrow) or previous scene (left arrow).
I've looked here and in Google Groups and every example shows my syntax exactly, but mine doesn't work.
I'm using Flash 5, it's not working in test movie, test scene, .swf, or Projector. End use is PC projector.
Here's what I have assigned to a 2px square MC and placed in its own layer in the scene:
onClipEvent (enterFrame) //also tried (keyDown)
{
if (Key.isDown(39)) { //also tried (Key.RIGHT)
trace ("right arrow has been pressed");
nextScene (); //also tried _root.nextScene() and _root.gotoAndPlay("SceneName",1) and neither worked
} else if (Key.isDown(37) { //as above, tried (Key.LEFT)
trace ("left arrow has been pressed");
prevScene(); //tried same alternates as above
}
}
The traces work, so it's recognizing the key press, just not responding to it. I've seen other people mention the same problem, but no solid answer. I've made sure the projector window is active.
Any thoughts?
[Edited by jdurra on 04-08-2002 at 03:56 PM]
View Replies !
View Related
Lmitations Of Key.isDown?
'ello.
Does anyone know if there is a limit (official or practical) to the numbr of simultaneous Key.isDown that can be detected?
Anyone found that flash 5 gets confused if there is more than 3 or 4 at once?
ta.
.jez
View Replies !
View Related
Key.isDown(Key.TAB) Test For BUG?
example:
http://www.unthink.net/projects/cds/tabOrder5.html
I think this has to be some sort of bug or maybe i'm just doing this wrong
:::code:::
Selection.setFocus("_root.in0"); // THis works fine
myListener = new Object();
myListener.onKeyDown = function() {
if (Key.isDown(Key.TAB)) {
Selection.setFocus("_root.in2")//This goes to the wrong field
}
};
Key.addListener(myListener);
::::::::::::::::
it seems that when i have a setFocus() inside of
myListener.onKeyDown = function()
it starts acting wacky. Try this out and see if you all have any luck with it. What my goal is that after i get this working to have on <TAB>:
tabArray = new Array("root.in1","root.in2","root.in3","root.in4", )
...on Tab...
Selection.setFocus(tabArray[i])
i++
pulling the field to focus from an array
this is the original example:
http://www.unthink.net/projects/cds/tabOrder.html
Any ideas?
View Replies !
View Related
Key.isDown Problem
Can anybody help and say why this code doesn't work?
onClipEvent (enterFrame) {
if(Key.isDown(Key.ENTER)&& _root.text1.indexOf("red")==-1){
loadMovie("red.swf",1);
}else{
_root.SoundAlert.gotoAndStop(1);
}
}
Thx
Alek
View Replies !
View Related
Key.isDown Problem
If you have two input fields (that are supposed to receive same values) on stage and want to trigger two different actions when user hits enter key you have a problem…….AT LEAST I DO !!!!!!!!! HELP.
This is what I’m trying but it doesn’t work:
onClipEvent(enterFrame){
if (_root.text1.Key.isDown(Key.ENTER) && _root.text1=="yes"){
this.gotoAndStop(1);
}else if(
_root.text2.Key.isDown(Key.ENTER) && _root.text2=="yes"){
this.gotoAndStop(2);
}
}
any ideas ?
Thx
Alek
View Replies !
View Related
Key.isDown Prob
hey,
i have a 4 frame animation of a guy walking (feet together, left foot forward, right foot, feet together)
i want the guy to walk when keys A and B are both down. i want him to stop walking when they're not both down.
i have a decent knowledge of flash MX but this one has got me baffled!
help v.v.v.much appreciated.
chris
View Replies !
View Related
Flash 5 Key.isDown
Trying to call a function based on the ENTER KEY being pressed.
Not working. The code appear below.
Or perhaps a better question...
I want to execute a ENTER KEY function that is specific to the _currentFrame the Playhead is over. Remember I'm using Flash 5.0
Thank You
function fEnterKey()
{
if(Key.isDown(13) && _root.ianswers._currentFrame==1)
{
_root.fFeedbackQ1 ();
}
else if(Key.isDown(13)&&_root.ianswers._currentFrame>6 <10)
{
_root.fFeedbackCAT2_Q1 ();
}
}
View Replies !
View Related
Iof Key.isdown Problem
hi i am having a problem i have a 2 player game and i have a code i have the first car woirking using up, down, left, right but i need to get it to work with the letters w,a,s,d
but i dont no how to i am using ASCII at teh mnoment heres the code i am trying to uuse fo one of them cant renember which btu any way any help would be grate ful it needs the if Key.isDown in
code: if (Key.isDown(Key.87))) {
speed += 1;
}
View Replies !
View Related
|