Placed in: Home viagra australia
viagra online
viagra sale
cialis online
cialis australia
Visualize audio bars by using amplitude in Flash

The new Actionscript 3.0 in Flash CS3 can be a bit tricky sometimes, especially when you're normally used to Actionscript 2.0. But there are a number of nice new functions in AS 3.0 which make it really attractive to just make it your coding standard for Flash.

Here I'll explain how to use the leftPeak and rightPeak properties of AS 3.0. With these, you can read the volume of both audio channels (left and right) seperately. With that value, you can create some nice Flash files, like this visual audio bar.

Visual Audio

To create this, use this (relative simple) AS 3.0 code.

barLeft.mask = maskLeft;
 barRight.mask = maskRight;
 
 var s:Sound = new Sound();
 s.load(new URLRequest("audiofile.mp3"));
 
 var sc:SoundChannel;
 sc = s.play(0, 1000);
 
 this.addEventListener(Event.ENTER_FRAME, showPeaks);
 
 function showPeaks(eventArgs:Event)
 {
   maskLeft.y = barLeft.height + sc.leftPeak * - barLeft.height;
   maskRight.y = barRight.height + sc.rightPeak * - barRight.height;
 }

Because of the Event.ENTER_FRAME, this code works best when you set the FPS from Flash to a minimum of 24.

Attached files:

Audio Visualizer in Flash: Audio Visualiser in Flash
Source code: Visulizer Source

Tags:  how to audio flash actionscript

Interested in this topic? You might enjoy another article I've written called

Did you like this article? Subscribe to my feed or email to keep updated on new articles.

Spread the word and submit to:
Digg!Reddit!Del.icio.us!Facebook!StumbleUpon!
 
< Prev
Subscribe

Subscribe to Marcofolio