开发者

How to activate a flex application so the user doesn't have to click inside it to start getting keyboard events

My Flex application is heavily keyboard-oriented. It uses 100% of the browser window and I'd like the user to be able to start using it immediately - as soon as it loads.

However, it seems that the application is only first "activated" (i.e. the activate event fires开发者_Python百科) when the mouse clicks somewhere inside it, which is very inconvenient for my keyboard-heavy app.

Can I force an activation of my app at some point during/after it loads?

I hope I don't have to display some silly "click inside to activate" overlay every time the page loads...

Addendum

In certain browsers ([cough] Chrome [/cough]) the focus is lost whenever the user switches away from the browser (or even touches the address bar) and is not regained when switching back. So the solution has to take in consideration not just the first focus when the page loads but also "re-focusing".


AFAIK the problem occurs only in certain browsers like Firefox. You can change that behaviour with a little bit of JavaScript. Edit your index.template.html and add the following code snippet within the <head></head> tags:

<script type="text/javascript">
    function setFocusToSwf() {
        var swf = document.getElementById('${application}');
         if (swf) swf.focus();
    }
</script>

Flex Builder will replace the ${application} placeholder when it compiles your application.

Change the <body> tag so that your new function gets called when the browser finished loading the document:

<body onload="setFocusToSwf()">


Use it on creation to get it work in chrome:

ExternalInterface.call("function() { 
    var app = document.getElementById('App');
    if(app) {
        app.tabIndex = 0;
        app.focus();
    }
}");

Ravi Sankar Gonthina

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜