Handling focus events globally
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class Main extends Sprite {
public function Main ( ) {
var field1:TextField = new TextField( );
field1.width = 100;
field1.height = 30;
field1.border = true;
field1.background = true;
field1.type = TextFieldType.INPUT;
var field2:TextField = new TextField( );
field2.width = 100;
field2.height = 30;
field2.y = 50;
field2.border = true;
field2.background = true;
field2.type = TextFieldType.INPUT;
addChild(field1);
addChild(field2);
stage.addEventListener(FocusEvent.FOCUS_IN, focusInListener);
}
private function focusInListener (e:FocusEvent):void {
TextField(e.target).backgroundColor = 0xFF00FF00;
if (e.relatedObject is TextField) {
TextField(e.relatedObject).backgroundColor = 0xFFFFFFFF;
}
}
}
}
Related examples in the same category