首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

[转]TextField设不伏焦点呢

2012-12-20 
[转]TextField设不起焦点呢?创了个sprite对象,sprite对象里面有个文本框public class Test extends Sprite

[转]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就可以了

热点排行