[转]TextField设不起焦点呢?
创了个sprite对象,sprite对象里面有个文本框
public class Test extends Sprite{ private var _accountTxt:TextField; public function Test() { _accountTxt = new TextField(); _accountTxt .text = 'aaaaaaaaa'; this.addChild(_accountTxt ); } public function setFocus():void { this.stage.focus = _accountTxt; }}//加载舞台
var test:Test = new Test();
addChild(test);
test.setFocus(); //为什么不能让_accountTxt.得到焦点?
以上代码是简写,只是想说明我遇到的问题。我一直就觉得AS3设焦点不好用。
因为焦点是舞台传过来的,所以要确保已经加载到舞台上在设置焦点,具体做法是加Event.ADDED_TO_STAGE后再设置stage.focus=textfield就可以了