Flex中有些页面,如果不控制光标定位,用起来不那么方便。今天早上,我也上网查了查如何去定位,总结一下:
首先,
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
public function initApp():void
{
this.focusManager.setFocus(userName);
userName.focusManager.activate();
}
]]>
</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文件,是可以看到效果的了,但是如何要用网页的形式去访问,则看不到效果!这时需要找到这个Application对应的.html文件
上面这个的文件是index.swf,在同目录下,可以找到一个index.html文件。
这时,在index.html文件里面添加
document.getElementById("index").focus(); 这样一句js。
保存,运行!掂!
本文介绍了一种在Flex应用中实现光标定位的方法。通过在创建完成时设置focus到特定元素,确保页面加载后光标位于指定输入框。此外,还提供了解决网页访问时效果缺失的问题方案。
7725

被折叠的 条评论
为什么被折叠?



