简体   繁体   中英

Flash Microphone Event Resize

I have been recently studying and learning Flash AC3 and my intention was to make a small voice recorder for my website. I have been using google and the search engines and get different answers here and there but still it is not exactly working properly.

The problem I am having is, the flash plugin is 215x50 pixels. I know that unless it is 215x138 pixels, the flash player security panel will automatically NOT open.

I devised a work around which is that if and when the security is being called to open, I would resize the DIV the flash object is in using a javascript function called ResizeFlash to a size of 215x138 and then back again to 215x50 after the user makes a choice whether or not they allow the microphone.

Now I have been scratching my head for a few days because I DO get the following code to work and it does resize the DIV, but it does not resize the DIV back. I think I might have the call to ResizeFlash in the wrong place (???). I am not familiar enough to know where it might be wrong.

I keep rearranging the code to see if that would work and I would get times where it does resize to 215x138, open the Security Panel, then resize back to 215x50 but then the recording would not begin, as if I were stuck somewhere in a loop.

I hope that someone can please take some time and just take a glance at this code and show me the right way to handle this. Thank you very much!

Here is the code:

public function Main():void
{
    recButton.stop();
    submitButton.enabled = false;  // These reset everything, maybe in wrong place?? 
    activity.stop(); 
    addListeners();

        mic = Microphone.getMicrophone();

        if (mic == null)
        {
            // no camera is installed
        }
        else if (mic.muted)
        {
            // user has disabled the access in security settings
            mic.addEventListener(StatusEvent.STATUS, onMicStatus, false, 0, true); // listen out for their new decision
            Security.showSettings('2'); // show security settings window to allow them to change security settings
        }
        else
        {
            // you have access
            mic.setUseEchoSuppression(true); //... also this might be in wrong place?
            // .. I would like this to always be on
        }
    }

    private function addListeners():void
    {
        recButton.addEventListener(MouseEvent.MOUSE_UP, startRecording);
        submitButton.addEventListener(MouseEvent.MOUSE_UP, onSend);
        recorder.addEventListener(RecordingEvent.RECORDING, recording);
        recorder.addEventListener(Event.COMPLETE, recordComplete);
        activity.addEventListener(Event.ENTER_FRAME, updateMeter);

    }

    function onMicStatus(event:StatusEvent):void 
    {   
        if (event.code == "Microphone.Unmuted") 
        { 
            mic.removeEventListener(StatusEvent.STATUS, onMicStatus);
            ExternalInterface.call('ResizeFlash', '215', '50'); // When the user presses allow, resize the div back to 215x50
        }
    }

    private function startRecording(e:MouseEvent):void
    {
        recorder.record();
        e.target.gotoAndStop(2);

        recButton.removeEventListener(MouseEvent.MOUSE_UP, startRecording);
        recButton.addEventListener(MouseEvent.MOUSE_UP, stopRecording);

    }

    private function stopRecording(e:MouseEvent):void
    {
        recorder.stop();

        e.target.gotoAndStop(1);

        recButton.removeEventListener(MouseEvent.MOUSE_UP, stopRecording);
        recButton.addEventListener(MouseEvent.MOUSE_UP, startRecording);
    }

I know that I have something in there in the wrong order..! I appreciate any comments.

Resizing the app back to 215x50 in the Microphone's status event handler may be too soon, as you have suggested.

Just a hunch, but that status event is dispatched immediately when the user clicks the "Allow" radio button in the Flash security panel. The panel is still open. In fact, if you leave it open and click between allow/deny it will get dispatched each time...

When the security panel is up, there are some things you cannot do. I wonder if using ExternalInterface (to resize the app) is falling into this bucket.

I would suggest the following:

  1. Test your resize functionality without the security panel in the mix. Make sure this code successfully resizes the app in both directions.
  2. Then have a look at this question about how to detect when the user actually closes the security panel. There are two approaches there, one is very hacky (the BitmapData.draw() hack) but I know it works. I suggest trying the second one, and commenting/upvoting there if it does work (I will too). It's a more elegant way to detect when the user closes the dialog, but I haven't had a chance to try it.
  3. When you detect the dialog is closed, resize the app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM