12

When using Flash with a microphone or camera, the user is prompted to allow access to those devices. This is done through the built in security settings panel.

Is there a way to be notified by an event handler when the user clicks on the close button of the security settings panel? This does not seem to be possible...

For the microphone, it is possible to receive a status event when the user changes the settings in the security panel, but this event is triggered while the user still has the panel open.

J. Volkya
  • 993
  • 3
  • 14
  • 33
  • Why do you need that? I am just curious - I have implemented multiple camera+microphone Flash Player applications using ActionScript 3 and never had a dire need for what you're asking. Perhaps if you'd explain what is it you're trying to accomplish, I could be of more help. There are some useful events fired by `Camera`, `Microphone` and other related class objects, which you could make good use of instead. – Armen Michaeli Aug 04 '11 at 17:13
  • 2
    A simple example: I want to initialize my microphone recording code after the user has closed the security panel. Sure I can do it by responding to the mic status event, but this event is triggered every time the user clicks on "Allow" or "Deny" while still inside the panel. It can be quite useful to know that the panel has been closed and start doing a certain task. – J. Volkya Aug 04 '11 at 17:34
  • Moreover, since the security panel asking to allow or deny the use of the microphone can be popped open without my knowledge, I need to be alerted about it and also be alerted when it has been closed so I can take the appropriate actions depending on what the user has chosen to allow. For example, if the user denies access to his mic, I need to tell them that they will not be able to use the application. – J. Volkya Aug 04 '11 at 17:43
  • As far as I know (and remember), there is nothing like that in Flash Player. Your best bet is to respond to events from Camera and Microphone, that way you also don't have to worry what or who has caused the Settings dialog to pop up. You won't miss anything, besides when one clicks Allow or Deny, the dialog usually closes. There is a bug however that prevents this from happening on occasion, and even crashes the player too. – Armen Michaeli Aug 04 '11 at 20:13
  • @amn: In FP 10.3 at least, when clicking on Allow or Deny, the dialog does not close. However it sends a EventStatus to the microphone instance. This event is the only one we have to check if the access was granted or not. If you read the comments posted in the Adobe bug tracker (link below) you will see why this can be important to know when that panel is being displayed and when it has been closed. Of course you can just ignore the panel but in a complex application, it can be hard to manage the side effects caused by it, since you never know when a user will open it and what will be done. – J. Volkya Aug 04 '11 at 20:25
  • maybe a focus event on the swf? – The_asMan Aug 04 '11 at 21:49
  • 1
    @John Ok I see where this is heading. I haven't got 10.3 here, so I will have to sleep on all this and check back later. I can say one thing now though - if the dialog no longer closes on Allow or Deny, that in my eyes would be where the problem is, because that's just silly :/ – Armen Michaeli Aug 05 '11 at 08:59

4 Answers4

13

I stumbled on this when attempting to search for a solution.

Flash Player bug report WITH WORKAROUND

I haven't tested the workaround, but it should still work? Good luck.

Edit:

For anyone who can't/won't access the Adobe bug tracker, here is the workaround originally posted by Philippe Piernot:

var closed:Boolean = true;
var dummy:BitmapData;
dummy = new BitmapData(1, 1);

try
{
    // Try to capture the stage: triggers a Security error when the settings dialog box is open
    dummy.draw(stage);
}
catch (error:Error)
{
    closed = false;
}

dummy.dispose();
dummy = null; 
shanethehat
  • 15,460
  • 11
  • 57
  • 87
Sam DeHaan
  • 10,246
  • 2
  • 40
  • 48
  • 1
    Nice find, although as noted in the bug tracker, false positives can be obtained when remotely loaded video (or any other capture-restricted content) is present on the stage. – shanethehat Aug 04 '11 at 18:32
  • Wish I could +1 an edit. Didn't even think of actually posting the workaround. /facepalm, @shanethehat. Thanks. – Sam DeHaan Aug 04 '11 at 18:32
  • 1
    Another workaround suggested in that Adobe bug tracker is to count the number of children on the stage. If you know exactly how many there should be, then when there is one more, you know it is the settings panel being showed. You put the logic in a timer to periodically check. – J. Volkya Aug 04 '11 at 19:19
  • 4
    I'll be downvoted for this, but as someone who has been programming Flash Player since the days of Macromedia Flash 4, using AS 1, 2, 3 and now using haXe, I hope some will heed to my little advice: don't do things like the thing I think you want to do. There is so much wrong about it - your code may break with future FP versions, timers tax the player (and thus your users), and I haven't heard of any use cases where people hold the Settings dialog up intentionally and click and click Allow and Deny buttons just to annoy the developers. Bug report aside, stick to the API. With all due respect. – Armen Michaeli Aug 04 '11 at 20:17
  • 3
    Why would you be downvoted for telling us to stick to the API? You're completely correct. The API is the way to go. The API is just annoyingly lacking in this case, and if the OP wants a workaround, I'll provide him the means to shoot himself in the foot. I don't plan on using it myself. – Sam DeHaan Aug 04 '11 at 20:20
  • 1
    @amn: I'm not the only one requesting this feature, but maybe we are all wrong and we don't need such a thing. I don't seriously plan on using the suggested workarounds but I may if I don't find a better way to solve my problem. I would be interested in knowing how you manage access to the microphone in Flash. As far as I know, all we can do is "try" to use the microphone, where it may pop the security settings dialog or not. It would be useful to be able to react to the dialog being opened in order to stop recording for example. – J. Volkya Aug 04 '11 at 21:01
  • For the sake of explaining some other use cases: in the application I'm working on, we can potentially have many iframes in our flash application and if the user opens the settings panel it can appear behind the iframes unintentionally. I'm probably going to wind up hooking a right-click listener on my main stage so that I can hide the iframes when that happens. – buddyp450 Oct 10 '14 at 12:20
12

call security panel ( like ns.addStream(mic))

            // WHEN PRIVACY PANEL IS ON MOUSE EVENTS ARE DISABLED
            stage.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
            function onMouseOver(e:Event):void { 
                trace("privacy panel closed");
                //REMOVE THE LISTENER ON FIRST TIME
                stage.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
                //doStuff
            }
csomakk
  • 5,369
  • 1
  • 29
  • 34
  • I've used the `BitmapData.draw()` hack above. If this works, it's a great, clean (no dirty feeling) solution! I almost want to try it now, so I can give you the plus 1! – Sunil D. Jul 04 '12 at 11:40
  • 1
    This solution worked for me except that I had to add one conditional check in the mouse move handler. Flash was sending mouse move events from coordinates that were outside the stage when I was moving the mouse out of the player. This helped: `if (e.stageX >= 0 && e.stageX < stage.stageWidth && e.stageY >= 0 && e.stageY < stage.stageHeight) ...` – Adam Wróbel Oct 20 '12 at 18:24
  • Adam, thats probably browser dependent. Thanks for noticing! – csomakk Nov 04 '12 at 13:58
  • 2
    Also, please note that you should use an event to make sure the element was added to the stage before trying to set the mouse event listener, or you'll get the dreaded 1009 - null reference error. See http://stackoverflow.com/questions/4552210/stage-addeventlistener-inside-a-package for an example of this. – MontyThreeCard Dec 03 '12 at 17:31
  • Are you sure about that? I think you don't NEED to add it to stage before setting a mouse listener, but it uses more resources that way for sure. – csomakk Dec 03 '12 at 20:26
  • This is not a solution to the problem. The `doStuff` will be executed only after the user moves the mouse after closing the Security Panel. So while this workaround may work most of the times, it will sometimes execute `doStuff` much later than expected. – Borek Bernard Jul 27 '13 at 17:33
  • 2
    @Borek is right, however you can use the MOUSE_OVER event instead of the MOUSE_MOVE event. This will trigger as soon as the dialog disappears. – David Verhasselt Sep 12 '13 at 16:45
  • What about mobile devices? e.g. IE11 in Modern UI (Windows 8)? I guess MOUSE_OVER event is not triggered on touch screen. – Terite Jul 08 '14 at 15:08
  • when I answered this, touch devices weren't mainstream. Nothing comes to mind for that scenario at the moment, but I'll keep thinking. – csomakk Jul 13 '14 at 09:35
6

I have resolved this issue in the next way:

private function showPrivacyDialog():void {
    var spr:Sprite = new Sprite();
    stage.focus = spr;
    spr.addEventListener( FocusEvent.FOCUS_OUT, handleFocusEvent );
    spr.addEventListener( FocusEvent.FOCUS_IN, handleFocusEvent );
    Security.showSettings( SecurityPanel.PRIVACY );
}

private function handleFocusEvent( event:Event ):void {
    event.target.removeEventListener( event.type, handleFocusEvent );
    const closed:Boolean = (event.type == FocusEvent.FOCUS_IN);
    trace( "Security Panel just", closed ? "closed!" : "shown!" );
    if (closed) {
        stage.focus = null; // or it can be restored to the previous value
    }
}

Check my full util class SecurityPanelUtil that shows settings dialog and then handle it close and notifies via callbacks immediately.

Enhancer
  • 61
  • 1
  • 3
0

The panel is secretly rendered using Flash's own display engine. To do this they secretly add the panel to the display list of the stage.

You can detect this by checking if stage.getChildAt(stage.numChildren-1) equals null. That's an otherwise impossible scenario that reveals the existence of the panel.

henke37
  • 19
  • 6
  • Hi, i am interested in this solution. I am trying to handle detection that someone opens the settings menu so that i can hide an Iframe. Any idea how i could do that? – Vince Lowe Mar 25 '15 at 14:56