?
Solved

Flash keyUp Listener

Posted on 2005-03-22
6
Medium Priority
?
1,007 Views
Last Modified: 2008-01-09
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
Comment
Question by:gmailrules
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 1

Author Comment

by:gmailrules
ID: 13605775
I think the setFocus(); method is invoking my listener twice for some reason...
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13605926
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
 
LVL 1

Author Comment

by:gmailrules
ID: 13606003
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
 
LVL 18

Expert Comment

by:Billystyx
ID: 13606299
interesting - and good debugging!
good luck
Billystyx
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 15659706
PAQed with points (500) refunded

DarthMod
Community Support Moderator
0

Featured Post

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.

Question has a verified solution.

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

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
Suggested Courses

800 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