Link to home
Start Free TrialLog in
Avatar of dmehran
dmehranFlag for United States of America

asked on

problem with textInput component keyDown and keyUp events in Flash 8

Hi, I have created a simple flash form as a test with a textInput component that has an instance name of 'myText'. I also have other textInput instances as well. I am trying to capture the keyDown event on this 'myText' textInput so I wrote the following code which includes a listener to capture the event.


var myListener:Object = new Object();
      
myListener.keyUp = function(){
     trace("key pressed ...");
}
      
myText.addEventListener("keyUp",myListener);


However, when I click and type in on anywhere on the swf form or even type in other text fields in the form, the listener captures the event . How can I make it so that the listener only works with 'myText' and not listen to keyUp on anywhere else?

thanks
ASKER CERTIFIED SOLUTION
Avatar of Ramy_atef
Ramy_atef

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi, that's odd, your code is perfect.
l've just tested your code as well, and it's working fine on just that one textinput component and not any others.
are you sure you have the instance name only for that 1 component and there aren't any conflicts?

Avatar of dmehran

ASKER

thanks for answers to my question so far. blue-genie, I also think that my code should work but it doesn't. Here is a link to the sample .fla code that I created so you can test it for yourself: (http://66.36.169.161/textListen.fla). Please look at this and let me know what you think, if I am making a mistake I just don't know where it is! Meanwhile Ill try Ramy's solution and get back to you guys. (BTW, I am using Flash 8 and not Flash MX 2004, I am not sure if that makes a difference in this case)

thanks
Avatar of dmehran

ASKER

Ramy, your solution worked and I find it very neat. I also like to know why it is that the listener function I wrote is not just listening to 'myText' and it listens to other textInput components as well. I wait till I hear from blue-genie or someone with an explanation on that before giving points for the given solutions.

thanks
Avatar of Ramy_atef
Ramy_atef

Hi
Well the lsitener listen to that event , any key stroke will be count as an event, so what i did is to check the foucs, is it the text box, if so then do whatever you like

 if (getFocus() == eval(this+".label")) {
          trace("key pressed ...");
     }

Hope this is clear enough :)
Regards,
Ramy
dmehran , what version of Flash are you using?
I've downloaded your file and running it in Flash 8 and it's working perfectly. it definately only traces when key up on the myText box.

using listeners definately better practice then getFocus() - but if all else fails i'd guess you can use whatever alternatives you have, however, not being able to recreate the error is a problem.

i'll have a look somemore later but i don't see anything,.
Avatar of dmehran

ASKER

OK, thanks  for trying, I am using Flash 8 pro and I am puzzled as why it doesn't work. I like to use the Listener method, but it is giving me problem.

thanks