简体   繁体   English

Flash麦克风事件调整大小

[英]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. 我最近一直在学习和学习Flash AC3,目的是为我的网站制作一个小型录音机。 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. 我遇到的问题是,Flash插件为215x50像素。 I know that unless it is 215x138 pixels, the flash player security panel will automatically NOT open. 我知道除非它是215x138像素,否则Flash Player安全面板将不会自动打开。

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. 我设计了一种解决方法,即如果调用安全性时以及打开安全性时,我将调整Flash对象的DIV大小,即使用名为ResizeFlash的javascript函数,将其大小调整为215x138,然后在用户输入选择是否允许使用麦克风。

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. 现在,我已经花了几天的时间挠头,因为我确实获得了下面的代码,并且确实调整了DIV的大小,但没有调整DIV的大小。 I think I might have the call to ResizeFlash in the wrong place (???). 我想我可能在错误的地方致电了ResizeFlash(???)。 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. 我一直在重新排列代码,看是否行得通,我会得到一些时间,它的确调整为215x138,打开“安全面板”,然后调整为215x50,但是录制却无法开始,就好像我陷入了循环中。

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. 如您所建议的那样,在麦克风的状态事件处理程序中将应用重新调整为215x50的大小可能为时过早。

Just a hunch, but that status event is dispatched immediately when the user clicks the "Allow" radio button in the Flash security panel. 只是预感,但是当用户单击Flash安全性面板中的“允许”单选按钮时,将立即调度该状态事件。 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. 我想知道是否使用ExternalInterface (调整应用程序大小)是否属于这个范围。

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. 那里有两种方法,一种非常hacky(BitmapData.draw()hack),但我知道它是可行的。 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. 当您检测到对话框关闭时,请调整应用大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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