Set focus on Flash object hosted in a WebBrowser control
I've searched here and with Google but I can't find an answer to this. Our app uses the WebBrowser control to display SWF flash objects to users. This works fine with the mouse but some deployments only have a remote control with arrow keys. The problem is that when the Flash object loads
WebBrowser.Navigate("c:\mypath\myflashfile.swf");
the Flash object does not have focus so the arrow keys do not work. Pressing the Tab key on the keyboard gets the focus on the Flash object and then the keys work but this won't work with the remote control. Anybody any ideas on how to get the Flash file to acce开发者_开发技巧pt arrow key control once it is loaded?
Thanks.
I do not know Flash at all, but I would guess there is some kind of event that you could handle in Javascript that indicates that the Flash object has loaded. For example, in Silverlight you can provide a JavaScript "callback" that is called once the Silverlight control is loaded.
Here is some code from my blog that shows what I mean in the case of Silverlight, hope you can translate this to a Flash equiv.
1- Give the element in the web page an ID
2- Pass the ‘onLoad’ parameter on the Silverlight application assigning a JavaScript function that will focus to application in the browser.
<object id="silverlightControl" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/DragSnapDemo.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="onLoad" value="silverlightControlHost_Load" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>
3- Finally write the JavaScript function that is called when the Silverlight application has be loaded
function silverlightControlHost_Load(sender, args)
{
var control = document.getElementById("silverlightControl");
control.focus();
}
Update: Found the following links that might be helpful
http://kb2.adobe.com/cps/155/tn_15586.html
http://www.actionscript.org/forums/archive/index.php3/t-120307.html
精彩评论