Key.getCode inconsistencies
I am having problems with an interactive module that I
created. It was built to work with the 6.0 player. Sometimes this
codes works and sometimes it does not - can someone see something
wrong with the way this is written?
Key.removeListener(userKeynm);
passwordz = "|";
Selection.setFocus("passwordz");
passwordz.tabEnabled;
passwordz.tabIndex= 1;
userKey = new Object();
userKey.onKeyDown = function(){
if (((Key.getCode() == Key.CONTROL) || (Key.getCode() ==
Key.ENTER)) && (passwordz == "LEARNINGFS" || passwordz ==
"learningfs")){
gotoAndPlay("pressf2");
} else {
if (((Key.getCode() == Key.CONTROL) || (Key.getCode() ==
Key.ENTER)) && !(passwordz == "LEARNINGFS" || passwordz ==
"learningfs")){
gotoAndPlay("wrongpass");
if ((Key.getCode() == Key.TAB) && !(passwordz ==
"LEARNINGFS" || passwordz == "learningfs")){
gotoAndPlay("wrongpass");
if ((Key.getCode() == Key.TAB) && (passwordz ==
"LEARNINGFS" || passwordz == "learningfs")){
gotoAndPlay("pressenter");
Key.addListener(UserKey);
stop();
After playing with this -- some more -- it seems like what is
happening is if the person types in the wrong thing and is sent
back to say "wrongpass" - I have to have it go to the frame before
in order to have the code process. It's like it will not
reset/process the code unless I have a frame before the destination
from.
Example: frame 10 - with code: gotoandPlay ("wrongpass")
frame 11 (code above)
I'm wondering if I don't have the listener keys figured out
right?? I'm putting them first in the code remove the last
listener.
Similar Messages
-
This code is not working consisently and I can't seem to
figure it out - help? The module was built in flash 6, actionscript
1.0. I'm basically trying to make sure that a user types "x" into a
text field and presses either the control or enter key:
Does this code make logical sense? It is not working
consistently. I am basically trying to make sure some one types "x"
in either upper or lower case in a text field and presses either
enter or control.
I think I must have my operators all messed up... any help
would be greatly appreciated.
Key.removeListener(signin);
passwrd = "";
Selection.setFocus("passwrd");
passwrd.tabEnabled;
passwrd.tabIndex = 2;
puserKey = new Object();
puserKey.onKeyDown = function() {
if ((Key.getCode() == Key.ENTER) && (passwrd == "x"
|| passwrd == "X")) {
gotoAndPlay("goodjob");
if ((Key.getCode() == Key.ENTER) && !(passwrd == "x"
|| passwrd == "X")) {
gotoAndPlay("pre_useEnter");
if ((Key.getCode() == Key.CONTROL) && (passwrd == "x"
|| passwrd == "X")) {
gotoAndPlay("goodjob");
if ((Key.getCode() == Key.CONTROL) && !(passwrd ==
"x" || passwrd == "X")) {
gotoAndPlay("pre_useEnter");
if ((Key.getCode() == Key.TAB) && !(passwrd == "x" ||
passwrd == "X")) {
gotoAndPlay("pre_useEnter");
if ((Key.getCode() == Key.TAB) && !(passwrd == "x" ||
passwrd == "X")) {
gotoAndPlay("pre_useEnter");
Key.addListener(puserKey);
stop();Can someone please make some suggestions to this - is it the
order of operation that is messed up? Should I use else if
statements? Am I using the wrong operators, a combination? Do I
need to use different brackets? -
Hi!
I have a kind of unusual problem... Im building a prototype for a UI wich you can navigate around in. And we use a mockup-prototype-model with a numeric keyboard built in and connected trough USB to fetch keypresses and use that as a joystick to navigate around and get a feeling how it would feel like to navigate around using a joystick in your hands.
The problem is that it sends kind of unusual keypresses from the joystick.
Everything works fine when I test the movie in Flash CS5 on a mac (cmd + enter). But not on a PC or in all of the published modes (.exe, .swf or .app).
The codes I use in my if statements to navigate that doesnt work is:
Key.getCode() == 188, Key.getCode() == 74 and Key.getCode() == 54
Today I use a double setup of keys so that I can use my keyboard on the computer as a backup to navigate around. And those keypresses works fine without problems. It is just those three (188, 74 and 54) that doesnt work.
example code:
keyListener.onKeyUp = function() {
trace("UP -> Code: "+Key.getCode()+"\tASCII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
if((freezeActive == true && Key.getCode() == 188) || (freezeActive == true && Key.getCode() == 72)){
freezeNavigateLeft();
Key.addListener(keyListener);
I have made sure that flash has focus when ive tried this. But it is so odd that it works when I test the movie but not when I run it on a PC or in any of the published applications...
Have any of you encountered that some keypresses doesnt work?
Best regards
JoelThink ive solved it!
It seems like the PC recieves different signals from the input device in published mode then on the mac... so I had to trace them out in debugmode one by one and got different signals. So now it works!
/Juhb -
Prevent Enter key from proceeding movie
I am using this code to get the user to enter the answer 16
in an input text field. It works but if the user hits the enterkey
after they've gotten the question right, the playhead starts and
moves to incorrect. This is not happening only in the testing
environment, the published file continues when Enter is pressed.
Can anyone help?
keyListener = new Object();
keyListener.onKeyUp = function() {
if (input_txt2.text == "16" and Key.getCode() == 13) {
//13 is key code for 'Enter'//
gotoAndPlay("1_3_13a");
_root.answer1 = "Correct!";
} else if (input_txt2.text != "16" and Key.getCode() == 13)
//13 is key code for 'Enter'//
_root.answer1 = "Incorrect.";
gotoAndPlay("1_3_13b");
Key.addListener(keyListener);I'm not following what "…activated when the enter key
is pressed even after the event has occurred." means. You mean that
even after this first entry you press enter and the value of
input_txt2.text != "16" so it is jumping to 1_3_13B?
I think I know what you mean, maybe. Notice how you are
setting up a listener? Well it keeps listening, it isn't a one time
deal. It listens for a keyUp until you tell it to stop. So just
because it works once why would you expect it to stop working? :)
What you need to do is either inside your conditionals or
perhaps just inside the onKeyUp function put a
Key.removeListener(keyListener); to tell it to stop listening. If
you are doing some kind of remediation at 1_3_13b and then want
them to have another try, perhaps you will want to leave the
listener or you might want to remove it and then add it back. I
don't know the exact structure of what you are doing, but I hope
this points you in the correct direction. -
Hi,
One more question, how do you get the keypress in the main
movie? I've tried on onClipEvent (keyDown) key.getCode etc but that
requires to be in a movie.there are a couple of ways to handle this. If you are looking
for a sepcific Key you can set up a Listener. or more like what
your trying here, but as in: -
Newbie: Soft Key Problem
Hey
Environment:
Flash Lite 2
ActionScript 2.0
When I run this code in the "Generic Phone" emulator, I
several times presses on the soft keys on the emulator... But the
words "LEFT" or "RIGHT" isn't written to the Output-window. I
wonder what in my code are causing this problem... Below is a copy
of my code...
// this ActionScript sets your content to be full screen
fscommand2("FullScreen", true);
gotoAndStop(1);
fscommand2("SetSoftKeys", "<<<", ">>>");
btn_1.onPress = function() {
gotoAndStop(5);
btn_2.onPress = function() {
gotoAndStop(10);
var myListener
bject = new Object();
myListener.onPress = function() {
if (Key.getCode() == ExtendedKey.SOFT1) {
trace("LEFT");
} else if (Key.getCode() == ExtendedKey.SOFT2) {
trace("RIGHT");
Key.addListener(myListener);Ciao
try
myListener.onKeyDown = function()
instead of
myListener.onPress = function() {
Alessandro -
Working with Enter Key - Reply ASAP pls
Hi all,
I'm working with Actionscript 2.0. I am applying the
following code
keyListener = new Object();
keyListener.onKeyUp = function() {
var keyCode = Key.getCode();
if (keyCode == 13) {
gotoAndPlay(1318);
}else {
gotoAndStop(1314);
Key.addListener(keyListener);
Problem I'm facing is that its not working with the enter key
, however if i'm giving any other key code then its working. Infact
if i'm giving the following code
keyListener = new Object();
keyListener.onKeyUp = function() {
var keyCode = Key.getCode();
if (keyCode == 13) {
gotoAndPlay(1318);
}else if (keyCode == 32) {
gotoAndPlay(1318);
}else{
gotoAndStop(1314);
Key.addListener(keyListener);
Then its working fine but only in the case of else if part (
key Code==32, space bar ), but not with the enter key.
Please help.disable keyboard shortcuts if you're testing in the test
environment. -
Soft key crashes program but works in Flash 8 emulator
I am developing for the Nokia E62 in Flashlite 2.1 using
Flash 8, The E62 is a Symbian S60 v 3 phone with a 320 x 240 pixel
screen. The Flashlite 2.1 standalone player works fine on it but
the phone comes only with a Flashlite 1.1 player. Flash 8 does not
have a Flashlite 2.1 device profile available for the Nokia E62, so
I am using teh generic Windows Mobile profile as it is the only one
with the proper screen size.
My program works on the emulator but when I test it on the
phone, pressing the soft key crashes the program (my program quits
but the standalone Flash 2,1 Player dos not die and I am returned
to its menu fo choosing a movie to run.) In a previous version of
the program, I was able to make the soft keys work fine on the
phone so I know that the phone supports remapping softkeys.
I am working in fullscreen mode so the Symbian system labels
for the softkeys are not visible. Nonetheless, my past experience
is that the program will crash if I do not use the fscommand2
command:
fscommand2("SetSoftKeys", "Menu", "Submit");
Anyway, here is the code to handle softkeys which crashes on
the phone when either soft key is pressed, but works on the
emulator:
fscommand2("SetSoftKeys", "Menu", "Submit");
var softListener = new Object();
softListener.onKeyDown = function() {
var code = Key.getCode();
switch(code) {
case ExtendedKey.SOFT1:
_root.gotoAndStop(3);
break;
case ExtendedKey.SOFT2:
submit();
break;
Key.addListener(softListener);
It appears that the phone crashes in the
softListener.onKeyDown routine and not later on in the submit
function.Thanks!
What is the difference in how soft keys are used between AS 1
and AS 2?
I was publishing in Actionscript 2, but you are right, my
code is AS1-style on the timeline, not AS2 using external class
files. I wanted to publish as AS 2 to use strict typing in order to
debug more easily.
Except that in the snippet I sent, I declared
var softLIstener = new Object() instead of
var softListener:Object = new Object()
and I did not do the type declarations in the function
definition...
So should I get rid of all the places where I did declare
types and publish as AS1? Or do the declarations consistently and
keep it AS2? If this is Flashlite 2.1, doesn't that mean I get
Flash 7 - style AS 1 and not Flash 5 style? AS 1 prior to Flash MX
is really limited and I don't remember it well. I thought AS 2 was
backward compatible with AS 1 so that my hybrid code should work as
AS 2. It does in the non-mobile versions of Flash... -
How can I close an Air app with a key ?
keyEnter = new Object();
keyEnter.onKeyDown = function() {
if (Key.getCode() == 69) // E,e = 69
//other coding
NativeWindow.close()
Key.addListener(keyEnter);
Does not work..Btw, I am using Adobe Flash CS4 AS2
-
hello all,
i'm seeing several posts on controlling video playback with
no replies... hope the following question isn't strange or
impossible: i want to have a video play forward (normally) while
the right arrow key is pressed. i want the video to play backwards
(like rewind, but not just rewind to zero) while the left arrow key
is pressed.
so far my video simply plays and keeps going if i hit right
arrow only once, and rewinds all the way to the beginning if i
press left arrow only once. how can i improve my controls? thanks
for any help you can offer.
best,
aya.
-------- the following code is on main timeline --------
stop();
//create the listener object
var keyListener:Object = new Object();
//create a function for handling the onKeyDown (or onKeyUp)
event.
keyListener.onKeyDown = function() {
//check to see if an arrow key was pressed
//right = 39, left = 37
if (Key.getCode() == 39){
movieWaves.play();
//want to try reverse playback here, but not there yet!
//if (Key.getCode() == 37){
// movieWaves.play(0);
Key.addListener(keyListener);Haha... Thanks, believe me, I have that, the message boards, and the help all open at the same time.
-
Key code problem , Reply ASAP pls
How should I compare 10 through keyCode
keyListener = new Object();
keyListener.onKeyUp = function() {
trace(Key.getCode());
var keyCode1 = Key.getCode();
var keyCode2 = Key.getCode();
if (keyCode1 == 97) {
keyCode2 = Key.getCode();
if (keyCode2 == 96) {
gotoAndStop(10);
} else {
gotoAndStop(11);
} else {
gotoAndStop(11);
Key.addListener(keyListener);
But its jumping to frame 11;
As per your suggestion I tried trace(key.getCode()), its also
giving me 2 values 97 and 96 which are for 1 and 0 respectively.
please help. -
Hi, i want to make flash to go to the next frame no matter of that what letter keyboard key you press. Is that possible? But i need only letter keys not others like Tab, Enter, Backspace or Space... Thanks for your help.
Key codes generally are grouped into sets, starting at one value thru another. So you can use a set of conditionals to test if the key code is within the range of the letter keys. Here's a link to a chart showing the key codes for Flash...
http://people.uncw.edu/tompkinsj/112/FlashActionScript/keyCodes.htm
Here is an example in AS2. Be sure to disable keyboard shortcuts in the player when testing locally.
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
var keyPressed= Key.getCode();
if (keyPressed > 64 && keyPressed < 91) {
trace("You're pressing a letter key");
Key.addListener(keyListener); -
Key.isDown / getAscii() problems
I'm having some trouble detecting keypresses.
Woking with the arrow keys works fine, but using getAscii() is having problems.
I tried using:
if (getAscii(100)) {//do stuff;};
but the issue is that once you press a key, getAscii() keeps returning the value of the last key pessed even after you stop pessing it.
I tied using a keyDown listener, instead of onEnteFame and couldn't get it to work at all.
I tried searching these foums, but some of the solutions had all the code deleted... odd.
How do I add the ability to add key detection for the other keyboard keys to this code?
xspeed = 0;
yspeed = 0;
this.onEnterFrame = function() {
if (Key.isDown(Key.LEFT)) {
xspeed += -3;
if (Key.isDown(Key.RIGHT)) {
xspeed += 3;
if (Key.isDown(Key.UP)) {
yspeed += -3;
if (Key.isDown(Key.DOWN)) {
yspeed += 3;
xspeed *= .8;
yspeed *= .8;
if (Math.abs(xspeed) < 1) {xspeed = 0;};
if (Math.abs(yspeed) < 1) {yspeed = 0;};
if (xspeed <> 0 or yspeed <> 0) {
_root.Map._x += xspeed;
_root.Map._y += yspeed;
(The code has a few exta lines to make the accelleration nice and smooth.)try this:
//////////********KEY LISTENER*************************
delete keyListener;
Key.removeListener(keyListener);
keyListener = new Object();
keyListener.onKeyDown = function() {
code.Key.getAscii();
trace(Key.getAscii());
if (Key.getAscii() == 97) {
trace("A hit");
///*************spacebar *********************
if (Key.isDown(32)) {
trace("space bar pressed");
////*********CONTROL J***********************
if (Key.isDown(Key.CONTROL) && Key.getCode() == 74) {
trace("CONTROL J");
////********* p ***********************
if (Key.isDown(112)) {
trace("p");
////********* q ***********************
if (Key.isDown(113)) {
trace("g");
////*********F1***********************
if (Key.getCode() == 112) {
trace("F1");
Key.addListener(keyListener);
Important:
Always remember to remove your listener before calling on it again.Most of the time I place it on a frame the user can NOT return to, because it will keep adding listeners and you can easly build up hundreds of them. So remeber to remove it before calling it again...just like the above code does already. -
How do you use the keyboard to play sound from a button?
I am building a site for a client who wants to be able to
press a keyboard button such as the "up" button and have it play an
instrument sound. I am fimiliar with html and css coding but i am
not that great at actionscript. It would be greatly appreciated if
someone could show me what I would have to do to achieve this
affect. I was looking around the web and saw something that said I
might need an eventlistner. I am com,pletely lost! All help
welcome. Thanks. Here is an example of exactly what I am trying to
achieve, the only difference is it doesnt need to be complicated
and I only need it to work for 3 buttons.
http://www.ababasoft.com/music/drums01.htm
http://www.kenbrashear.com/dasaimedia wrote:
> I am building a site for a client who wants to be able
to press a keyboard
> button such as the "up" button and have it play an
instrument sound. I am
> fimiliar with html and css coding but i am not that
great at actionscript. It
> would be greatly appreciated if someone could show me
what I would have to do
> to achieve this affect. I was looking around the web and
saw something that
> said I might need an eventlistner. I am com,pletely
lost! All help welcome.
> Thanks. Here is an example of exactly what I am trying
to achieve, the only
> difference is it doesnt need to be complicated and I
only need it to work for 3
> buttons.
http://www.ababasoft.com/music/drums01.htm
>
http://www.kenbrashear.com/
Many ways to achieves that. You can make a movie clip with
(for 4 sounds) 5 frames.
Frame 1 stop(); to prevent it from running. Frame 2 attach
your sound, frame 3 another
sound, frame 4 and 5 same. Give that movie clip instance name
"soundCLIP" Now all you
need is to add key listener to timeline frame so you can
capture the key and go to
corresponding frame of the movie clip to play your sound.
var keyListObj:Object = new Object();
keyListObj.onKeyDown = function() {
switch (Key.getCode()) {
case Key.LEFT :
soundCLIP.gotoAndStop(2);
break;
case Key.UP :
soundCLIP.gotoAndStop(3);
break;
case Key.RIGHT :
soundCLIP.gotoAndStop(4);
break;
case Key.DOWN :
soundCLIP.gotoAndStop(5);
break;
Key.addListener(keyListObj);
Best Regards
Urami
<urami>
If you want to mail me - DO NOT LAUGH AT MY ADDRESS
</urami> -
Resetting Cleared Intervals?
Basic problem. Testing methods of turning intervals on and off. I have an interval that works, and can be turned off, but the button to turn in back on is failing. Basically when this program is turned on, a bar rotates 5 degrees each second and a counter increases by +1. When the "a" button is pressed, the interval stops (good). When the "b" button is pressed, the interval doesn't restart (bad).
What am I doing wrong?
jim = 1;
var ticker;
ticker = setInterval( function(){bar_mc._rotation += 5;
casper.text = 0 + jim;
jim = jim +1;
}, 1000 );
keyListener = new Object();
keyListener.onKeyUp=function(){
var keyUsed = Key.getCode();
//a
if (keyUsed == 65){
//clearInterval;
//b
else if (keyUsed == 66){
//clearInterval;
keyListener.onKeyDown=function(){
var keyUsed = Key.getCode();
//a
if (keyUsed == 65){
clearInterval(ticker);
//b
else if (keyUsed == 66){
setInterval(ticker);
Key.addListener(keyListener);lol kinda yes. but think of it this way -
"the motions & counting are inside the counter function"
- yes these items are 'handled' by the the counter method.
"the counter is inside the the timer/set interval"
- not exactly 'inside', each time the iterval is fired it 'calls' the assigned method.
"the timer/set interval is inside the clear interval"
- not really, the setInterval method returns a 'number' that is used as an ID for that particular interval. the ID is 'stored' as a reference to the interval in the variable property as we have assigned it - in this case the property 'timer'. the clearInterval method 'stops' the currently operating interval that the reference is pointing to - so it uses the ID to target that particular interval, but the property and the 'setInterval' are not really 'inside' the method.
"the clear interval is inside the start timer & inside the stop timer"
- clearInterval is used when you want to cancel or stop a currently running interval, it is a best practice to call clearInterval previous to setting a 'new' interval so as to make certain that the current ID reference is 'not' running. so in the startTimer method it is called to assure that the interval is cleared, in the stopTimer method it is called simple to cancel/stop the interval.
"and the start & stop timers are inside the A & B key listeners?"
- key press 'triggers' or 'calls' the startTimer/stopTimer methods, but they do not reside 'inside' the listeners, they are only 'activated' by calling the method.
Maybe you are looking for
-
FINAL CUT PRO KEEPS QUITTING WHEN TRYING TO OPEN PROJECTS-PLEASE HELP!
I am finishing up two projects and ready to export them to quicktime and final cut pro will not let me open the projects as it quit on me and these projects will not re-open. Can someone please advise?1?! Thanks
-
Imac 17" core duo 1.83ghz broken display how to connect external display?
Hi there! I have a 2006 Imac 17" core duo and the screen broke by accident. The repair costs are extremely high and thus I was thinking about buying an external display and hooking it up to the imac. Firstly, would such a thing be possible, and if in
-
FM10: PDF output not including part of graphic in header
Here are my versions: (TCS3.0) FM 10.0.1.402 Acrobat 10.1.1 Distiller 10.1.133 I have a book recently created in FM10. I needed to add a very large table. I followed Barb Binder's instructions for setting up landscape master pages (from the IconLogic
-
Printing text in text area in so10(standard text)
Dear all, I need to print a text in text area.i mean i need a box in which i can fill text in standard text (tcode-so10).Using box command we will be doing in script. But is there any possibility that i can solve the issue in so10 itself as i am gene
-
Name field in FK01 vendor master creation/ table LFA1 lengths are different
Hi Experts, We have an issue with FK01 vendor master creation. The vendor Name field in FK01 has length of 40 char, however in Vendor Master table LFA1 field Name1 has length 35 char. So when the user inputs a name of 40 char in FK01 it does get trun