0

This code works properly when published by Flash CS 5.5 as .swf (it prompts to browse where to save the file). However, when it is published to HTML, it doesn't work (doesn't prompt to browse the destination). Is it security issue or other problem?

import flash.display.Sprite;
import flash.media.Microphone;
import flash.system.SecurityDomain;
import org.bytearray.micrecorder.*;
import org.bytearray.micrecorder.events.RecordingEvent;
import org.bytearray.micrecorder.encoder.WaveEncoder;
import flash.events.Event;
import flash.net.FileReference;
import flash.utils.setTimeout;

var mic:Microphone;
var waveEncoder:WaveEncoder = new WaveEncoder();
var recorder:MicRecorder = new MicRecorder(waveEncoder);
var fileReference:FileReference = new FileReference();

mic = Microphone.getMicrophone();
mic.setSilenceLevel(0);
mic.gain = 100;
mic.setLoopBack(true);
mic.setUseEchoSuppression(true);
Security.showSettings("2");
addListeners();


function addListeners():void
{
    setTimeout(startIntroTime,3000);
    function startIntroTime():void
    {
        startRecording();
        setTimeout(stopRecording,5000);
    }
    recorder.addEventListener(Event.COMPLETE, recordComplete);
}

function startRecording():void
{
    if (mic != null)
    {
        recorder.record();
    }
}

function stopRecording():void
{
    recorder.stop();
    mic.setLoopBack(false);
}

function recordComplete(e:Event):void
{
    fileReference.save(recorder.output, "recording.wav");
}
4

1 回答 1

2

查看文档:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#save()

它说 :

在 Flash Player 中,您只能成功调用此方法以响应用户事件(例如,在鼠标单击或按键事件的事件处理程序中)。否则,调用此方法会导致 Flash Player 引发错误异常。此限制不适用于应用程序沙箱中的 AIR 内容。

所以这是不可能的,可能是安全的事情。

于 2013-08-03T14:32:19.433 回答