views:

125

answers:

2

I know I can detect flash gaining and losing focus with these callbacks:

stg.addEventListener( Event.DEACTIVATE, deactivateCb, false, 0, true );
stg.addEventListener( Event.ACTIVATE, activateCb, false, 0, true );

But is there anyway to directly query flash if it has focus or not?

(Trying to figure out if flash has focus when starting up...)

+1  A: 

I don't think you can get this information with the ActionScript API.

I think it would work if you assign an ID to the Flash embed element, track the focus to the ID with JavaScript, and query whether the embed has focus using ExternalInterface.

<object ...>
    ...
    <embed id="flash_player" type="application/x-shockwave-flash" ...></embed>
</object>
<script language="JavaScript">
    var flash_has_focus = false;
    var fp = document.getElementById('flash_player');

    fp.onfocus = function (e) {
        flash_has_focus = true;
    };
    fp.onblur = function (e) {
        flash_has_focus = false;
    };

    function is_focused() {
        return flash_has_focus;
    }
</script>

And in the Flash...

var focused:Boolean = ExternalInterface.call('is_focused');

Edited to add - apparently this doesn't work in Internet Explorer.

Tmdean
+2  A: 

I'm pretty sure flash never has focus when starting up. It has to be clicked on to gain focus. From there you can store the focus changes and work with them however you like.

greg