AS3 Upload a file
dani3lthomas Dec 2, 2014 10:35 AMI'm new to AS3 and coding in general, but I followed a tutorial on how to create an audio recorder that I am using in a Captivate eLearning.
the default AS3 had the recorder start and stop on a mouse click. However, for my Captivate file, I needed the recorder to start on slide enter, and stop after a predetermined time. I was able to customize the code to accomplish that, but I need one last thing to happen. Right now, after the predetermined time is up, the user is prompted to save the file to their local computer. I need the code to direct the user to save the file to a web server instead of the local computer. Below is my code. Any assistance will help-
package
{
import flash.display.Sprite;
import flash.media.Microphone;
import flash.system.Security;
import org.bytearray.micrecorder.*;
import org.bytearray.micrecorder.events.RecordingEvent;
import org.bytearray.micrecorder.encoder.WaveEncoder;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.ActivityEvent;
import fl.transitions.Tween;
import fl.transitions.easing.Strong;
import flash.net.FileReference;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Main3 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();
private var minuteTimer:Timer = new Timer(1000, 118);
public function Main3():void
{
recButton.stop();
activity.stop();
mic = Microphone.getMicrophone();
mic.setSilenceLevel(0);
mic.gain = 100;
mic.setUseEchoSuppression(true);
Security.showSettings("2");
addListeners();
}
private function addListeners():void
{
recButton.addEventListener(Event.ENTER_FRAME, startRecording);
recButton.addEventListener(TimerEvent.TIMER_COMPLE TE, stopRecording)
recorder.addEventListener(RecordingEvent.RECORDING , recording);
recorder.addEventListener(Event.COMPLETE, recordComplete);
activity.addEventListener(Event.ENTER_FRAME, updateMeter);
minuteTimer.addEventListener(TimerEvent.TIMER_COMP LETE, onTimerComplete);
minuteTimer.addEventListener(TimerEvent.TIMER_COMP LETE, stopRecording)
}
private function startRecording(e:Event):void
{
if (mic != null)
{
minuteTimer.start();
recorder.record();
e.target.gotoAndStop(2);
recButton.removeEventListener(Event.ENTER_FRAME, startRecording);
recButton.addEventListener(TimerEvent.TIMER_COMPLE TE, stopRecording)
addChild(recBar);
tween = new Tween(recBar,"y",Strong.easeOut, - recBar.height,0,1,true);
}
}
public function onTimerComplete(event:TimerEvent):void
{
trace("Time's Up!");
}
private function stopRecording(e:Event):void
{
recorder.stop();
mic.setLoopBack(false);
e.target.gotoAndStop(1);
recButton.addEventListener(TimerEvent.TIMER_COMPLE TE, stopRecording);
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, "Name_Q1.wav");
}
}
}


