flex textInput 怎麼在程式開始執行後就獲得游標?
在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中
增加這句程式碼,就最保險了。