• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

How do I load a .wav file into a byteArray in Flash CS3

While I know I can't load .wav files dynamically in Flash and play them, I did find a workaround solution. However, I can't quite figure out how to get started.

In my list of questions, here's the big one: How do I load a .wav file into a byteArray?

Once I get that far, I should be able to use popforge (http://code.google.com/p/popforge/) library to convert the byteArray into samples, and eventually a Sound object. Also, working in CS3 (not Flex), this page is handy for making it all work in CS3 in case you are curious: http://www.signar.se/blog/popforge-flash-workaround-fp-9/comment-page-1/#comment-42

I appreciate any help you could provide! Thank you much in advance.
1 Solution
OK this is easy.

There are essentially two ways I know of. One is URLLoader and the other is using FileReference.

FileReference allows the user to browse through explorer and select the file whereas URLLoader hardcodes the path, it can be changed but you should get what I mean.

I used frame code just for sample as it's easy,if you want I can convert it to a document class if you want.

If you need help with any of the code, just ask.

I divided the two code below in the code snippet.

~~~~~~URLLoader Method~~~~~~
var byteArray:ByteArray;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(new URLRequest("test.wav"));
loader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(evt:Event):void {
	byteArray = loader.data;	
~~~~~FileReference Method~~~~~
var byteArray:ByteArray;
var file:FileReference = new FileReference();
var fileFilter:FileFilter = new FileFilter("Wav Files (*.wav)", "*.wav");
file.addEventListener(Event.SELECT, loadFile);
file.addEventListener(Event.COMPLETE, completeHandler);
function loadFile(evt:Event):void {
function completeHandler(evt:Event):void {	
	byteArray = file.data;

Open in new window

UltrusAuthor Commented:
Ha! That was easy! I had everything in place except for the last line (in top example). However, I couldn't have done it with out you. Thanks for the assist! :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now