dangquocthai / flash-videoio

Automatically exported from code.google.com/p/flash-videoio
0 stars 0 forks source link

We want to call the Security.showSettings window through JavaScript and to recieve an event that this window is closed. #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Could you please add such a feature.
We know that there is no a standard way to catch an event when the 
Security.showSettings dialog window is closed. Here's our way to catch it.

package
{
    import flash.display.Stage;
    import flash.events.Event;
    import flash.events.FocusEvent;
    import flash.system.Security;
    import flash.system.SecurityPanel;

    import mx.core.FlexGlobals;

    /**
     * 
     **/
    public class SecuritySettings
    {
        /**
         * 
         **/
        public static function show(param:String, onClosed:Function):void
        {
            var stage:Stage = FlexGlobals.topLevelApplication.stage;

            var delegate:Function = function(event:FocusEvent):void {
                stage.removeEventListener(FocusEvent.FOCUS_IN, delegate);
                onClosed();
            }

            stage.addEventListener(FocusEvent.FOCUS_IN, delegate);
            Security.showSettings(param);
        }
    }
}

Example: 

protected function init():void
{
SecuritySettings.show(SecurityPanel.PRIVACY, onClosed);
}

protected function onClosed():void
{
// ---- event
}

This is a very important feature for us, could you please add it. We hope it 
also will help other developers.

Original issue reported on code.google.com by a.v.ch...@gmail.com on 8 Aug 2011 at 1:16

GoogleCodeExporter commented 9 years ago
Hi,

Thanks for the suggestion. I am having tough time to reliably get focusIn event 
on stage in my test. It looks like the focusIn event fires immediately after 
Flash security panel is closed, only if use has clicked on some button earlier 
in the Flash application. To verify my understanding, I wrote a simple program 
which you can test too.

binary at: http://myprojectguide.org/p/flash-videoio/Test.swf
source at: http://myprojectguide.org/p/flash-videoio/Test.mxml.txt

To test, go to the binary URL, and click on the "show" button on top-right 
within 10 seconds. This shows the security panel. Click allow, and close, and 
then you will see an Alert box immediately saying "focusIn was received".

Now refresh the page, and wait for 10 seconds for the security panel to show 
*without* clicking on the "show" button. Click allow, and close, and you don't 
see any "focusIn ..." event. Now when you click on the show button, you see the 
focusIn event. So looks like the focusIn event is not quite reliable for 
detecting when the security panel is closed.

Note also that Alert.show doesn't work if done in focusIn handler so had to use 
a 0 ms timer.

If you are able to get focusIn reliably without a user click in the application 
buttons, please send me the sample source code based on my Test.mxml and I will 
incorporate those changes... Any other suggestions are welcome too. One option 
is to show a "close" button behind the security panel, which user must click 
after closing the security panel.

Original comment by kundan10 on 10 Aug 2011 at 6:26

GoogleCodeExporter commented 9 years ago
I used a different technique to detect that the Flash security settings is no 
longer active. I found three techniques (workarounds) and all these workarounds 
have their own limitations. The version 2.5 has the fix based on periodically 
checking the stage.numChildren value.

From developer point of view, first set "privacyEvent" property to true. This 
will cause "onShowingSettings" callback to be invoked whenever the Flash player 
security settings is about to be shown and after it is closed. The 
event.showing property is true or false, respectively. This is a non-backward 
compatible change in version 2.5, that onShowingSettings is invoked for show 
and close of the security panel instead of just on show in version 2.4.

function onShowingSettings(event) {
    log("onShowingSettings() " + event.showing);
}

To test this, use Flash Player 10.3 or later, and go to 
myprojectguide.org/p/flash-videoio/test.html then enable "privacyEvent" 
property. Now enable "live" property which will enable local camera view and 
show the security settings dialog box. It will also show the onShowingSettings 
callback with showing=true. After you close the settings dialog box it will 
show the onShowingSettings callback with showing=false.

To use this fix, download the version 2.5 or later of VideoIO and use the 
appropriate SWF from the zip archive in your application.

The rough sketch of the fix in actionscript is as follows:

        private var settingsTimer:Timer;
        private var stageChildren:int = 0;

        public function showSettings():void
        {
            if (privacyEvent) {
                // dispatch onShowingSettings with showing=true

                var stage:Stage = mx.core.FlexGlobals.topLevelApplication.stage;
                if (settingsTimer == null) {
                    stageChildren = stage.numChildren;
                    settingsTimer = new Timer(100, 0);
                    settingsTimer.addEventListener(TimerEvent.TIMER, settingsTimerHandler, false, 0, true);
                    settingsTimer.start();
                }
            }
            Security.showSettings(SecurityPanel.PRIVACY);
        }

        private function settingsTimerHandler(event:TimerEvent):void
        {
            var stage:Stage = mx.core.FlexGlobals.topLevelApplication.stage;
            if (settingsTimer != null && (stage.numChildren == stageChildren)) {
                settingsTimer.removeEventListener(TimerEvent.TIMER, settingsTimerHandler);
                settingsTimer.stop();
                settingsTimer = null;
                if (privacyEvent) {
                    // dispatch onShowingSettings with showing=false
                }
            }
        }

Original comment by kundan10 on 10 Aug 2011 at 10:26

GoogleCodeExporter commented 9 years ago
Re-opening this bug, because the stage.numChildren trick no longer works in the 
latest version of Flash Player. Deprecating the "privacyEvent" property until 
it can be fixed. The new behavior is that it dispatches the onShowingSettings 
with showing=false, and immediately after that again dispatches the 
onShowingSettings with showing=true.

Should explore other alternatives such as those listed in
http://stackoverflow.com/questions/6945055/flash-security-settings-panel-listeni
ng-for-close-event

Original comment by theinten...@gmail.com on 14 Oct 2012 at 4:41

GoogleCodeExporter commented 9 years ago
After the above comment, this is not merged with #27.

Original comment by theinten...@gmail.com on 14 Oct 2012 at 5:31