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.
To create this, use this (relative simple) AS 3.0 code.
barLeft.mask = maskLeft;
barRight.mask = maskRight;
var s:Sound = new Sound();
sc = s.play(0, 1000);
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.
|Audio Visualizer in Flash: ||
|Source code: || |
Tags: how to audio flash actionscript
Interested in this topic? You might enjoy another article I've written called
Spread the word and submit to: