views:

337

answers:

2

I am pretty new to flex, so forgive me if this is an obvious question.

Is there a way to open the Security.showSettings (flash.system.Security) with a callback? or at least to detect if it is currently open or not?

My flex application is used for streaming audio, and is normally controlled by javascript, so I keep it hidden for normal use (via absolute positioning it off the page).

When I need microphone access I need to make the flash settings dialog visible, which works fine, I move it into view and open the dialog.

When the user closes it, I need to move it back off the screen so they don't see an empty flex app sitting there after they change their settings.

thanks :)

+2  A: 

If you do something like this, it will work in some situations:

var mic:Microphone = Microphone.getMicrophone();
mic.addEventListener(StatusEvent.STATUS, onMicStatus);

If you are just trying to use the microphone and relying on Flash to pop up the dialog to ask the user for permission, Flash will open a dialog with two buttons, Allow and Deny. When the user clicks one of the buttons the StatusEvent will fire, the dialog will close, and you can move the flex app out of the way.

If you are manually opening the settings panel (via Security.showSettings), you get the panel with Allow and Deny radio buttons, and the event will fire when the user clicks on the radio buttons, not when they close the panel, which is probably of less help to you.

Wesley Petrowski
does the flex app lose focus when the settings are open? maybe I can put something on the stage and bind to the focus event?
Jiaaro
another idea: is there an event fired when that security dialog is opened? so I can skip showing the flex app if the use has already given and "remembered" permission
Jiaaro
Once you have a Microphone object (using getMicrophone), you can check its `muted` property, which will be false if you have permission. In that case, you don't need to show the security dialog.I tested whether the application loses focus when the security dialog opens - it seems to, so that might work for you, although the FOCUS_OUT event will also fire when the browser window loses focus, which could be a problem.
Wesley Petrowski
I posted a potential answer... it is still a little finicky though what do you think?
Jiaaro
A: 

Update: flex 4 solution

So when I moved to the flex 4 and started compiling my mxml with adobe's open source mxmlc compiler, the solution below no longer worked because the alert doesn't lose focus when you're in the settings anymore.

As far as I could tell I had to move to a less elegant solution where the user must click "OK" on the alert box every time they are done with the settings.

Here is the new code:

private function setup_smart_hide():void {
    // Call this function whenever you make the flex app visible (or add it
    // to a show_flex() function if you have such a thing set up)
    alert = Alert.show('Click "OK" to continue.', 'Thanks!', Alert.OK, null, function(e:CloseEvent):void {

        // calls the external javascript to hide the flex app
        hide_self();

    });
}

OLD: (flex 3) Got this working...

private function setup_smart_hide():void {
    alert = Alert.show('Thanks');

    alert.addEventListener(FocusEvent.FOCUS_IN, function(event:FocusEvent):void {
            // javascript to hide the flex app
        ExternalInterface.call("SB.flex.hide");
    });
    alert.addEventListener(FocusEvent.FOCUS_OUT, function(event:FocusEvent):void {
            // javascript to show the flex app
        ExternalInterface.call("SB.flex.show");
    });

    alert.setFocus();
}

Which is run first thing in the init() function... the only problem is (like Wesley said), the focusOut event occurs when the flex app itself loses focus as well.

Jiaaro