Código Javascript
:
Ver original//BUTTONS
play_mc.addEventListener(MouseEvent.CLICK, playSong);
play_mc.buttonMode = true;
stop_mc.addEventListener(MouseEvent.CLICK, stopSong);
stop_mc.buttonMode = true;
update_mc.addEventListener(MouseEvent.CLICK, updateColors);
update_mc.buttonMode = true;
//SOUND
var songOne:Sound = new Sound(new URLRequest("beat.mp3"));
var sc1:SoundChannel = new SoundChannel();
function playSong(e:Event):void
{
sc1 = songOne.play(0,99);
play_mc.enabled = false;
}
function stopSong(e:Event):void
{
sc1.stop();
play_mc.enabled = true;
}
sc1 = songOne.play(0,99);
play_mc.enabled = false;
//VISUALIZER
var lineAlpha:Number = 1.0; //how visible the line in the center of the wave will be. Values range from 0.0 - 1.0
var lineColor:Number = 0xFF00FF; //the initial line color, right now it's a pink color
var lineThickness:Number = 2.0; //how thick your line will be
var red:String = red_txt.text; //sets the red value to the initial value of red_txt
var green:String = green_txt.text; //sets the green value to the initial value of green_txt
var blue:String = blue_txt.text; //sets the blue value to the initial value of blue_txt
var strength:Number = 1.0; //how strong the glow is around the line
var speedX:Number = 3.0; //how fast the blur flows by on the X axis - to change direction, give a negative number
var speedY:Number = 0.0; //how fast the blur flows by on the Y axis - to change direction, give a negative number
//this function updates the colors when the "UPDATE" button is pressed
function updateColors(e:MouseEvent):void
{
red = red_txt.text;
blue = blue_txt.text;
green = green_txt.text;
lineColor = colorPicker.selectedColor;
visualizer();
}
//this is the heart of the visualizer
function visualizer()
{
var ba:ByteArray = new ByteArray();
var bmd:BitmapData = new BitmapData(512, 300, true, 0x000000); //IMPORTANT! - You want to make sure the first two parameters are your stage width and height respectively
var bm:Bitmap = new Bitmap(bmd);
addChild(bm);
var sp:Sprite = new Sprite();
addChild(sp);
var blur:BlurFilter = new BlurFilter(5,5,3); //the paramaters for the Blur Filter - ex: BlurFilter(blurX, blurY, Quality);
//the ColorMatrix below I do not know much about. I do know you basically only want to alter the values I am altering.
var colorMatrix:ColorMatrixFilter = new ColorMatrixFilter([
red, 0, 0, 0, 0,
0, green, 0, 0, 0,
0, 0, blue, 0, 0,
0, 0, 0, strength, 0
]);
addEventListener(Event.ENTER_FRAME, loop); //sets up the loop function to run every frame per second
//the "loop" function below draws the center wave line based off of the sound spectrum of your audio
function loop(e:Event):void
{
sp.graphics.clear();
sp.graphics.lineStyle(lineThickness, lineColor);
sp.graphics.moveTo(-1, stage.height/2);
sp.alpha = lineAlpha;
SoundMixer.computeSpectrum(ba);
for (var i:uint=0; i<256; i++)
{
var num:Number = -ba.readFloat()*200 + stage.height/2;
sp.graphics.lineTo(i*2, num);
}
bmd.draw(sp);
bmd.applyFilter(bmd,bmd.rect,new Point(),blur); //applies the Blur Filter
bmd.applyFilter(bmd,bmd.rect,new Point(),colorMatrix); //applies the ColorMatrix Filter
bmd.scroll(speedX,speedY); //this is where "speed" sets how fast the 'flow' of the filters will be
}
}
visualizer();