Flash – Music Spectrum

15 Mar

Hey guys, I made this a while back. It’s a flash sound spectrum. It’s pretty much a moving bar that measures sound. It’s actually really easy to make and even easier to customize. Take a peek at it here.

Here’s the code if you would like to use it in your own flash files. I think I’m going to make a music player with flash using the spectrum as some kind of visual effect. Well, see you around!

var s:Sound = new Sound(new URLRequest(“04 Wildcat.mp3“));

//loop
//s.play(0, 1000);

var ba:ByteArray = new ByteArray();

addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void
{
graphics.clear();
graphics.beginFill(0xFF00FF);
graphics.moveTo(-1, 150);
SoundMixer.computeSpectrum(ba);
for(var i:uint=0; i<256; i++)
{
var num:Number = -ba.readFloat()*200 + 150;
graphics.lineTo(i*2, num);
}
graphics.lineTo(512, 300);
graphics.lineTo(0, 300);
graphics.lineTo(-1, 150);
}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.