0 Replies - 276 Views - Last Post: 02 February 2006 - 12:29 AM

#1 pioSko   User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Enter Key 2.0

Posted 02 February 2006 - 12:29 AM

Description: 1. Paste in frame. 2. Name TextFields and MovieClips. 3. Modify Action() function to suit TextField/MovieClip names.Executes function after user presses Enter key. Determines which TextField or MovieClip is focused.
/* Updated version

* variable "hit" makes sure there are no double entries/executions.
* Script now in ActionScript 2.0
* Added Action() function which determines which TextField/MovieClip the listener is in.

*/

var hit:Boolean = true;

var keyListener:Object = new Object();
keyListener.onkeydown = function() {
     if (hit) {
          hit = false;
          
          var ref = Selection.getFocus();
          ref = eval(ref)._name;
          
          if (Key.isDown(Key.ENTER)) {
               Action(ref);
          }
     }
};

keyListener.onkeyup = function() {
     hit = true;
};
Key.addListener(keyListener);

function Action(ref:String) {
     switch (ref) {
     case "textField1" :
          trace("Pressed enter in textField1");
          break;
     case "textField2" :
          trace("Pressed enter not in textField1");
          break;
     }
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1