当用户登录表单到来时如何将光标放在文本输入中。我想将光标放在用户名文本输入中。 。任何帮助是极大的赞赏!
答案 0 :(得分:1)
您无法手动移动鼠标光标,但是,您可以在表单完成后始终将焦点设置在TextInput上:
<mx:Canvas creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
private function onCreationComplete():void
{
input.setFocus();
}
]]>
</mx:Script>
<mx:TextInput id="input" />
</mx:Canvas>
答案 1 :(得分:1)
与J_A_X的答案一致,如果您在应用程序首次加载时尝试将重点放在组件上,则还需要use some javascript to set the focus on your SWF。
以下是该文章的示例代码:
Javascript:
<script type="text/javascript">
function onFlexInitialized()
{
//alert("onFlexInitialized");
<!-- Force the browser to set flex app with focus -->
document.getElementById("${application}").focus();
}
</script>
ActionScript:
/**
* Constructor.
*/
public function AppController()
{
FlexGlobals.topLevelApplication.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 4
//Application.application.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 3
}
/**
* Handles the application complete event.
*/
protected function onAppComplete(e:FlexEvent):void
{
FlexGlobals.topLevelApplication.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 4
//Application.application.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 3
if(ExternalInterface.available)
{
ExternalInterface.call("onFlexInitialized");
}
}
答案 2 :(得分:1)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Label id="laa" x="264" y="118" width="160"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
[Bindable]
private var tempArr:Array;
private function myFunc(event:TextEvent):void{
tempArr=new Array();
for(var i:int=0, j:int=0;i<myarr.length;i++){
if(myarr[i].names.toString().match(textinput.text)){
tempArr[j]=myarr[i];
j++;
}else{
}
}
ls.dataProvider=tempArr;
ls.visible=true;
}
]]>
</mx:Script>
<mx:Array id="myarr">
<mx:Object names="Subudhi"/>
<mx:Object names="Subbu"/>
<mx:Object names="Harish"/>
<mx:Object names="Hari"/>
<mx:Object names="Subramanyam"/>
<mx:Object names="Suresh"/>
<mx:Object names="Surya"/>
<mx:Object names="Harsha"/>
<mx:Object names="Geetha"/>
<mx:Object names="Gentle"/>
<mx:Object names="gentleman"/>
<mx:Object names="sunny"/>
<mx:Object names="sunday"/>
</mx:Array>
<mx:TextInput id="textinput" x="264" y="10" textInput="myFunc(event)" focusOut="ls.visible=false"/>
<mx:List id="ls" x="264" y="31" height="66" visible="false" labelField="names" width="160" backgroundColor="#F3EBEB"></mx:List>
</mx:Application>
enter code here
答案 3 :(得分:0)
navigateToURL(new URLRequest("javascript: document.getElementById('XXX').focus();"), "_self");
userNameInput.setFocus();
其中XXX是swf文件的名称。
答案 4 :(得分:-1)