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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1015
  • Last Modified:

Flash keyUp Listener

I'm having pull your hair out in fustration flash listener issues.  I am trying to make a listener to catch the enter key for two buttons and a textfield.  The main problem I'm having is that the listener is unreliable.  It works when it wants to.  It's difficult to describe exactly what it does because everytime it works different.  For example it will sometimes execute 3 times instead of once.  I am almost positive this is an issue with flash's listener object so I'm looking for a workaround.  I beleive this issue only occurs when the movie is loaded into another swf.

Here is the code for the listener:

/****************************
 *
 * keyUp listener
 *
 ***************************/

var keyUpListenerObject:Object = new Object();
keyUpListenerObject.keyUp = function(eventObject):Void {
      focused = _level0.focusManager.getFocus();
      if (eventObject.target._name == focused._name) {
            if (Key.getCode() == Key.ENTER) {
                  if ((focused._name == "form_pidm") || (focused._name == "form_submit")) {
                        trace("test1");
                        //formSubmit();
                  }
                  else if (focused._name == "form_modify") {
                        trace("test2");
                        //formModify();
                  }
            }
      }
}
this.form_pidm.addEventListener("keyUp", this.keyUpListenerObject);
this.form_submit.addEventListener("keyUp", this.keyUpListenerObject);
this.form_modify.addEventListener("keyUp", this.keyUpListenerObject);  
0
gmailrules
Asked:
gmailrules
  • 2
  • 2
1 Solution
 
gmailrulesAuthor Commented:
I think the setFocus(); method is invoking my listener twice for some reason...
0
 
BillystyxCommented:
I don't nesting ifs too much - I would try this, at a glance
instead of:
if (eventObject.target._name == focused._name) {
          if (Key.getCode() == Key.ENTER) {
 try this:

if (eventObject.target._name == focused._name && Key.isDown(Key.ENTER)) {
         

Billystyx

0
 
gmailrulesAuthor Commented:
Thanks but I fixed the problem.  It's definitly a bug within setFocus()   It was calling my listener or invoking an enter keypress...  i fixed the problem by removing the listener before calling setFocus and then adding it once the textfield was focused

Thanks! :D
0
 
BillystyxCommented:
interesting - and good debugging!
good luck
Billystyx
0
 
DarthModCommented:
PAQed with points (500) refunded

DarthMod
Community Support Moderator
0

Featured Post

Technology Partners: 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!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now