Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

problem with textInput component keyDown and keyUp events in Flash 8

Posted on 2006-06-05
7
Medium Priority
?
387 Views
Last Modified: 2008-03-10
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
0
Comment
Question by:dmehran
  • 3
  • 2
  • 2
7 Comments
 
LVL 7

Accepted Solution

by:
Ramy_atef earned 2000 total points
ID: 16841509
Hi

just add this code on the text box component

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

Regards,
Ramy
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 16851763
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?

0
 

Author Comment

by:dmehran
ID: 16854664
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:dmehran
ID: 16855058
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
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16855489
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
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 16859205
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,.
0
 

Author Comment

by:dmehran
ID: 16875393
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

571 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