0
votes

I want to create a flash application that records audio through the user's microphone and then make an upload to the server, in order to do that I've found this code:

import flash.media.Microphone;
import flash.events;

const DELAY_LENGTH:int = 4000;
var mic:Microphone = Microphone.getMicrophone(); 
mic.setSilenceLevel(0, DELAY_LENGTH); 
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler); 

function micSampleDataHandler(event:SampleDataEvent):void { 
  while(event.data.bytesAvailable) { 
    var sample:Number = event.data.readFloat(); 
    soundBytes.writeFloat(sample); 
  } 
}

I couldn't test it yet, since it throws me this compiling error:

"1046:Couldn't find type or is not a constant during compiling time: SampleDataEvent"

After a research I've found that I have to update the Flash player version to compile to 10.0.0 in order to make it work, but I don't know how to do that. My IDE is the Adobe Flash CS3 Portable and most of the examples are for other IDEs like Flex, how can I do that?

1

1 Answers

0
votes

You are not importing flash.events.SampleDataEvent and soundBytes is not defined in the micSampleDataHandler handler.

import flash.media.Microphone;
import flash.events.SampleDataEvent;
import flash.utils.ByteArray;

const DELAY_LENGTH:int = 4000;
var mic:Microphone = Microphone.getMicrophone(); 
mic.setSilenceLevel(0, DELAY_LENGTH); 
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler); 

function micSampleDataHandler(event:SampleDataEvent):void { 
  var soundBytes:ByteArray = new ByteArray();
  while(event.data.bytesAvailable) { 
    var sample:Number = event.data.readFloat(); 
    soundBytes.writeFloat(sample); 
  } 
}