'How do you set focus in Flash ActionScript 3 (AS3)?'에 해당되는 글 1건

  1. 2013.09.11 How do you set focus in Flash ActionScript 3 (AS3)?
반응형

How do you set focus in Flash ActionScript 3 (AS3)?

Answer

Use the stage focus method:

stage.focus = object;

Source Code

import flash.text.TextField;
import flash.text.TextFieldType;
import fl.controls.Button;

var exampleTextField:TextField = new TextField();
exampleTextField.width = 100;
exampleTextField.height = 20;
exampleTextField.x = 50;
exampleTextField.y = 20;
exampleTextField.type = TextFieldType.INPUT;
exampleTextField.border = true;
addChild(exampleTextField);

var focusInButton:Button = new Button();
focusInButton.label = "Focus";
focusInButton.width = 80;
focusInButton.height = 20;
focusInButton.x = 10;
focusInButton.y = 70;
addChild(focusInButton);

var focusOutButton:Button = new Button();
focusOutButton.label = "Focus Out";
focusOutButton.width = 80;
focusOutButton.height = 20;
focusOutButton.x = 110;
focusOutButton.y = 70;
addChild(focusOutButton);

focusInButton.addEventListener(MouseEvent.MOUSE_UP, function(){ 
  stage.focus = exampleTextField;
});
focusOutButton.addEventListener(MouseEvent.MOUSE_UP, function(){ 
  stage.focus = null;
});
Posted by 1010