?
Solved

How to make a key is pressed in Flash.

Posted on 2005-03-09
11
Medium Priority
?
184 Views
Last Modified: 2010-04-03
I create a fighting game which player may control the fighters with FLASH 5.
I use if(key.isdown(ENTER){
to perform some action inside the movieclip.

Now, i wanna build AI for computer fighters.
Is there got any action scripts make a key is pressed?
That means the action scripts is doing pressing a key function....

And i wanna make the numlock key is ON or CLOSE always by using action script.
is it possible? I just need info...

Sorry, not much point left for me....so i only give 25.
0
Comment
Question by:wkwebsite
  • 4
  • 4
9 Comments
 
LVL 18

Expert Comment

by:Billystyx
ID: 13497880
What key press do you want it to do and why?

Billystyx
0
 

Author Comment

by:wkwebsite
ID: 13499968
Because my game fighter's movieclip got if (key.isdown......) actions.

When user press a key, the fightermc will moves. User may press different key to control the mc n perform alot of actions.

Now i wanna build AI system on the same fighter mc. That means the fighter mc will move randomly. I wanna the key is pressed automatically for the same mc (which user may control it in players versus mode, but computer control it in Computer versus mode).

I tried to create a movieclip send order for that mc with .gotoAndPlay actions.....but gotoAndplay actions not running for that mc, because it will cancel the current movement, n also something may not move correct according the fighter's skills.

(something like fighter must jump first before punch in the air) n......different fighters may have different kinds of movement. 800 frames for each......no point for me to add a script check if the if the fighter is jump, or get hit or knocked down then goto frame  bla bla bla..........
(i will go crazy........if i doing this......)


So, i think the best way is make the player control Key be pressed randomly.....
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13500080
I'm sorry I don't know, but for player vs computer it would make more sense (I think) to have a function for computerplayer  - even if you were able to mimic keystrokes, it would most likely confuse the player's keystrokes.

Billystyx
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
LVL 6

Expert Comment

by:nishasrilankan
ID: 13504719
Flash cannot simulate Key Press event. Only trapping can be achieved with onKeyPressed() event...

If a function is attached to a key (or accociated rather) then yes, you could simulate it, by calling that function.

Lets say you have the Key F2. When F2 is pressed on the Keyboard, it calls the function "myFunction". So now you want to simulate this? Well, whatever you doing, just call the "myFunction".


Hope this explains it well.

0
 

Author Comment

by:wkwebsite
ID: 13517041
ar.r.....the function u said is like if key.isdown, then call function......function is already there,
but wat i want to make a key is pressed itself... Like Key F2 function u said, the function is there, but i wanna make the F2 is pressed..so that the function will run.

i think it is impossible for flash to do that thing...
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13517267
You can put a list of possible choices in an array and then access that randomly to activate the function/s - if that helps

Billystyx
0
 

Author Comment

by:wkwebsite
ID: 13563903
thx billy, i know wat u mean..but the main thing is the trigger.
Key is not pressed won't run the action inside.....i donno how to explain it.

Ok,let say inside my movieclip frames got scripts like

IF 1st Frame
If(key.isdown(left) && this._x>enemy.x){ // LEFT KEY is DOwn
gotoAndPlay(40);  // FOR BLOCK
}

If(this.hitTest(enemy.hit){
gotoAndPlay(50);
}

BUT In 40th Frame
If(key.isdown(left) && this._x>enemy.x){  // LEFT KEY IS Down
gotoAndPlay(100);  // FOR ROLLING BACKWARD
}

So, when a "LEFT" key is pressed in different situation, the fighter mc will act differently n accordingly.

IF i using everysecond running function, letsay running ROLLING action(LEFT KEY): THe fighter must be getting hit first before he can rolling back. Different situation will hav different key reaction. if running function everysecond, the fighter maybe suddenly jump n punch (must jump before punch) or it can rolling backward anytime without getting a hit first.

I cannot make a if function to check that fighter is jump or block or hurling a power b4 to running a function. coz it is too hard to make it, n alot of value( like if block == true, jump ==true or rush==true) need to be added in For 800 frame X 8 fighters.

I really donno how to explain this 2 make u all understand.
anyway, thanks for ur help. :)




0
 
LVL 18

Accepted Solution

by:
Billystyx earned 600 total points
ID: 13564127
The only thing I can suggest is that you may have to rewrite all of these moves for computer fighter. .. if its true that you want the computer now to move randomly, and the random moves mostly relate to which frame is playing, you may need a
if(computerplayerrandom==true){
randomplay();//where randomplay is a function full of random moves for the computer
}else{
if(key.isDown etc....
}

but aside from that I don't know if I can help

Billystyx
0
 

Author Comment

by:wkwebsite
ID: 13571833
ermmm, thanks 4 help,
i change 2 another question....
i wanna ask is there anyway to make the NumLock key or Caplock is on always with action scripts?


n for Flash 5.
IF(key.isDOwn(Punch)){   //
gotoAndPlay (500);
}

If i holding the "Punch", the mc will go to frame 500 (for punch action).
 how do i make it punch once only.

So i try to use this for punch.
IF(key.isDOwn(Punch) && action==0){   //
 action=1;
 gotoAndPlay (500);
}

outside the mc i put
Onclipevent(keyup){
   action=0;
}

But i think is not a good idea.....coz if got two fighters, key collision will happens alwiz.....
Somemore, when a player press more than 4 keys, the other side of player will not able to control the fighter. And also, the timing is very hard to get for the movement key.....

Let say, a special movement keys is down, forward n then punch to be pressed in sequence
but i can only make like

if (key.isdown(Down) && Key.isdown(forward) && key.isdown(Punch){
gotoAndplaY(700);
}

So the user just hit 3 keys together but not in sequence for the special move.

anyway to solve?

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question