第一总方式 :在index.template.html 中 加入js
//添加获取焦点事件
function onFlexInitialized(){
document.getElementById('${application}').focus()
}
在flex application 初始化完成的时候掉用
Application.application.addEventListener(FlexEvent.APPLICATION_COMPLETE,onAppComplete);
protected function onAppComplete(e:FlexEvent):void
{
Application.application.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete); // Flex 3
if(ExternalInterface.available)
{
ExternalInterface.call("onFlexInitialized");
}
}
经测试 firefox ie 都可以
但模板不是很好,用ant编译的时候默认不好指定模板目录。
第二总方式:
所以利用flex document.insertScript 来写onFlexInitialized这个函数
private static var FUNCTION_SETFOCUS:String =
"document.insertScript = function () " +
"{"+
"onFlexInitialized = function()" +
"{"+
"document.getElementById('index').focus()"+
"}"+
"}";
然后在 application 初始化完成方法里边依次调用:
ExternalInterface.call(FUNCTION_SETFOCUS);
ExternalInterface.call("onFlexInitialized");
第三种 方式
body onload 事件调用onFlexInitialized 只有ie会生效 网上大部份是介绍这种方法