1
votes

I want to save my recorded audio using flash player with a file name passed through javascript I have tried various ways like How to pass Object tag PARAM value into Flash? & How to read the param value from the object tag using javascript ,but none of them worked for me

I have a javascript which embeds .swf where AudioRecorder.swf is my flash recorder and the recordedFileName is assigned dynamically. (ref: http://code.google.com/p/swfobject/wiki/documentation)

swfobject.embedSWF("AudioRecorder.swf", "myAlternativeContent", "350px", "350px", "9.0.0", "expressInstall.swf", recordedFileName, "fileName", "");

HTML code:

<div id="myAlternativeContent">
  <a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash Players</a>
</div>

The AudioRecorder.swf code: (ref : http://dev.tutsplus.com/tutorials/create-a-useful-audio-recorder-app-in-actionscript-3--active-5836)

public class Main extends Sprite
{
    private var mic:Microphone;
    private var waveEncoder:WaveEncoder = new WaveEncoder();
    private var recorder:MicRecorder = new MicRecorder(waveEncoder);
    private var recBar:RecBar = new RecBar();
    private var tween:Tween;
    private var fileReference:FileReference = new FileReference();


    public var recordedFileName:String;

    public function Main():void
    {
        recordedFileName = this.loaderInfo.parameters.fileName;

        trace(recordedFileName);
        recButton.stop();
        activity.stop();

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

        addListeners();
    }

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

    private function startRecording(e:MouseEvent):void
    {
        if (mic != null)
        {
            recorder.record();
            e.target.gotoAndStop(2);

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

            addChild(recBar);

            tween = new Tween(recBar,"y",Strong.easeOut, -  recBar.height,0,1,true);
        }
    }

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

        mic.setLoopBack(false);
        e.target.gotoAndStop(1);

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

        tween = new Tween(recBar,"y",Strong.easeOut,0, -  recBar.height,1,true);
    }

    private function updateMeter(e:Event):void
    {
        activity.gotoAndPlay(100 - mic.activityLevel);
    }

    private function recording(e:RecordingEvent):void
    {
        var currentTime:int = Math.floor(e.time / 1000);

        recBar.counter.text = String(currentTime);

        if (String(currentTime).length == 1)
        {
            recBar.counter.text = "00:0" + currentTime;
        }
        else if (String(currentTime).length == 2)
        {
            recBar.counter.text = "00:" + currentTime;
        }
    }

    private function recordComplete(e:Event):void
    {
        fileReference.save(recorder.output, recordedFileName);
    }
}

but on saving,the file name is the name of the folder that contains the HTML file.

Any help will be appreciated.

1

1 Answers

0
votes

You did not set up the swfObject correctly.

var flashvars = { };
    flashvars.fileName= "FILENAME_I_WANT_TO_USE"; 

var params = {};
    params.allowscriptaccess = "always";

var attributes = {};
    attributes.id    = "flashContent";
    attributes.name  = "flashContent";
    attributes.align = "middle";

var tmp = "expressInstall.swf";
var version = "9.0.0";
var width = "350";
var height = "350";
var container = "myAlternativeContent"
var flashObj = "dev_LMP.swf?t=" + new Date().getTime()

swfobject.embedSWF(flashObj, container, width, height, version, tmp, flashvars, params, attributes);