Getting a SWF to Gain Focus in Browser

I have seen a few peeps out there trying to get Form Fields to gain focus in Flex and the blinking cursor to also display in the primary focus field.

Using form_text_field.setFocus(); will get you the halo surrounding the text field but the blinking cursor will not show within the text field as the SWF will not have focus in the browser window.

I achieve swf focus in the browser window in Flex by using oleg’s flex template and simply adding the below to the template:

1
2
3
4
5
<script language="Javascript">
          function Focal() {
              document.${swf}.focus();
              }
</script>
1
<body onLoad="Focal()">

Not tested in IE cos I am on mac FF works fine though.

Comments