Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-07-12
2
Medium Priority
?
634 Views
Last Modified: 2013-11-11
Hello,
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.
0
Comment
Question by:Ultrus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
TanLiHao earned 2000 total points
ID: 24838074
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.browse([fileFilter]);
file.addEventListener(Event.SELECT, loadFile);
file.addEventListener(Event.COMPLETE, completeHandler);
 
 
function loadFile(evt:Event):void {
	file.load();
}
 
function completeHandler(evt:Event):void {	
	byteArray = file.data;
	trace(byteArray.length);
}

Open in new window

0
 
LVL 10

Author Closing Comment

by:Ultrus
ID: 31602692
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! :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question