在flex中如何设置TextInput的焦点,使得页面启动时,该TextInput就能获取焦点并且光标在TextInput框里显示(前提是不点击鼠标,一启动就能光标闪动)。
代码:
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
public function initApp():void
{
nameInput.setFocus();
}
]]>
</mx:Script>
<mx:Label x="10" y="10" text="name"/>
<mx:Label x="10" y="36" text="password"/>
<mx:TextInput x="74" y="32" id="passwordInput"/>
<mx:TextInput x="74" y="8" id="nameInput"/>
<mx:Button x="178" y="62" label="Login"/>
</mx:Application>
这样只有点击,或者直接打开你的swf才会出现光标,要想程序一开始就获得激活的光标
你还需要在你的html中,在AC_FL_RunContent这个函数的下面,也可理解为</script>前加上
加上document.getElementById("test").focus(); ,test为你swf的id,··到此就ok了,注意这
里如果你直接是在相对应的html文件中把document.getElementById("test").focus();加上,
当你重新编译的时候,在html中这句代码自动消失,最可取的做法是在index.template.html中
增加这句代码,就最保险了。