Results 1 to 15 of 18
Thread: Key is down/Key press help
-
March 29th, 2012, 05:35 PM #133Registered User
postsKey is down/Key press help
I have a simple key is down actionscript what i am trying to do is make it a multi 'key is down' so instead of pressing ''G'' to open frame 2 a person has to type a full word for example they would need to type the word ''frame2'' on their keybored to open frame 2 instead of pressing one key, Thanks in advance!
function onEnterFrame()
{
if (Key.isDown(71))
{
gotoAndStop(2);
} // end if
} // End of the function
stop ();
-
March 29th, 2012, 05:58 PM #2
Type as a sequence or holding all the keys at once?
Forgive my typos, it's either 2 in the morning or I'm wired out of my mind.
-
March 29th, 2012, 06:03 PM #333Registered User
postsTyping as a sequence so....
f pressed CHECK
r pressed CHECK
a pressed CHECK
..................
e pressed CHECK, START... GotoAndStop(2)
-
March 29th, 2012, 06:11 PM #4
some psudocode
there are other ... probably better ways to do it. But this is simple to understand.Code:var typeseq:Number; if(key.isDown(yourkeycode)){ typeseq = 1 } if(typeseq == 1){ if(key.isDown(yourkeycode)){ typeseq = 2 } } if(typeseq == 2){ if(key.isDown(yourkeycode)){ typeseq = 3 } } //...so on //Last edited by GabeLaneG; March 29th, 2012 at 06:13 PM.
Forgive my typos, it's either 2 in the morning or I'm wired out of my mind.
-
March 29th, 2012, 06:18 PM #533Registered User
postsArh nice but how would i Implement the gotoAndStop(2) into the script ?
-
March 29th, 2012, 06:24 PM #6
After the end of the sequence, reset typeseq to 0 and add your gotoAndStop after that line..
Code:if(typeseq == 5){ if(key.isDown(yourkeycode)){ typeseq = 0 _root.gotoAndStop(frame) } }
Forgive my typos, it's either 2 in the morning or I'm wired out of my mind.
-
March 29th, 2012, 06:35 PM #733Registered User
postsSo the code in full would look like this :
var typeseq:0;
if(key.isDown(70)){
typeseq = 1
}
if(typeseq == 1){
if(key.isDown(71)){
typeseq = 2
}
}
if(typeseq == 2){
if(key.isDown(72)){
typeseq = 3
}
}
if(typeseq == 3){
if(key.isDown(73)){
typeseq = 4
}
}
if(typeseq == 4){
if(key.isDown(74)){
typeseq = 5
}
}
if(typeseq == 5){
if(key.isDown(75)){
typeseq = 0
_root.gotoAndStop(2)
}
}
-
March 29th, 2012, 06:39 PM #8
yeah, around that. but I wouldn't set typeseq to 0 every frame at the start like that, it probably won't work.
Forgive my typos, it's either 2 in the morning or I'm wired out of my mind.
-
March 29th, 2012, 06:45 PM #933Registered User
postsNope doesnt work i tryed different numbers instead of 0 aswel ohwell thanks for the help!
i went with this
var typeseq; 11;
if(key.isDown(70)){
typeseq = 1
}
if(typeseq == 1){
if(key.isDown(71)){
typeseq = 2
}
}
if(typeseq == 2){
if(key.isDown(72)){
typeseq = 3
}
}
if(typeseq == 3){
if(key.isDown(73)){
typeseq = 4
}
}
if(typeseq == 4){
if(key.isDown(74)){
typeseq = 5
}
}
if(typeseq == 5){
if(key.isDown(75)){
typeseq = 11
_root.gotoAndStop(2)
}
}
stop();Last edited by MAGG0T; March 29th, 2012 at 06:49 PM.
-
March 29th, 2012, 07:05 PM #1033Registered User
postsheres the fla for anyone to have a go
-
March 29th, 2012, 11:28 PM #11
Change " var typeseq; 11;" to "var typeseq:Number;".
Don't actually set Number to a number ...
Forgive my typos, it's either 2 in the morning or I'm wired out of my mind.
-
March 29th, 2012, 11:58 PM #121,391Registered User
postsfrom the other thread
Code:var record:String = ""; var codes:Array = [ "frame2","frame3","frame4" ]; var keyboard:Object = new Object(); keyboard.onKeyDown = checkCodes; Key.addListener( keyboard ); function checkCodes():Void { record += String.fromCharCode(Key.getCode()).toLowerCase(); for( var c:int=0; c<codes.length; c++ ) { if( record.indexOf( codes[c] ) == -1 ) continue; gotoAndStop( c+1 ); record=""; break; } if( record.length > 100 ) record = record.slice(0,100); }
-
April 22nd, 2012, 01:48 PM #1359Registered User
postshi cbeech, how can i try out your code. is there a fla that comes with this code so that i may try it. i am using flash 8. i simply copied and pasted the code in a blank file and tried running it but got an error message. how can the record string be displayed so that we may see what keys were pressed or are being pressed.
Thanks.Last edited by ajoo; April 22nd, 2012 at 01:58 PM.
-
April 22nd, 2012, 02:00 PM #1459Registered User
postshi cbeech, how can i try out your code. is there a fla that comes with this code so that i may try it. i am using flash 8. i simply copied and pasted the code in a blank file and tried running it but got an error message. how can the record string be displayed so that we may see what keys were pressed or are being pressed.
Thanks.
-
April 22nd, 2012, 07:43 PM #152Registered User
postshi you just write _root.gotoAndPlay(2); but u are at the currect level so you don`t need to go to _root
Just at the end write gotoAndPlay(2); or use this code:
stop();
var typeseq:Number = new Number;
keyListener = new Object();
keyListener.onKeyDown = function() {
if(Key.getCode()==70){
typeseq = 1
}
if(typeseq == 1){
if(Key.getCode()==71){
typeseq = 2
}
}
if(typeseq == 2){
if(Key.getCode()==72){
typeseq = 3
}
}
if(typeseq == 3){
if(Key.getCode()==73){
typeseq = 4
}
}
if(typeseq == 4){
if(Key.getCode()==74){
typeseq = 5
}
}
if(typeseq == 5){
if(Key.getCode()==75){
typeseq = 6
gotoAndStop(2)
}
}
}
Key.addListener(keyListener);

Reply With Quote


Bookmarks