Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/02/2011, 10:16
Derzz
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 9 meses
Puntos: 4
Respuesta: reprodct con url flash

Código Javascript:
Ver original
  1. //BUTTONS
  2. play_mc.addEventListener(MouseEvent.CLICK, playSong);
  3. play_mc.buttonMode = true;
  4. stop_mc.addEventListener(MouseEvent.CLICK, stopSong);
  5. stop_mc.buttonMode = true;
  6. update_mc.addEventListener(MouseEvent.CLICK, updateColors);
  7. update_mc.buttonMode = true;
  8.  
  9. //SOUND
  10. var songOne:Sound = new Sound(new URLRequest("beat.mp3"));
  11. var sc1:SoundChannel = new SoundChannel();
  12.  
  13. function playSong(e:Event):void
  14. {
  15.     sc1 = songOne.play(0,99);
  16.     play_mc.enabled = false;
  17. }
  18. function stopSong(e:Event):void
  19. {
  20.     sc1.stop();
  21.     play_mc.enabled = true;
  22. }
  23.  
  24. sc1 = songOne.play(0,99);
  25. play_mc.enabled = false;
  26.  
  27.  
  28. //VISUALIZER
  29. var lineAlpha:Number = 1.0;  //how visible the line in the center of the wave will be.  Values range from 0.0 - 1.0
  30. var lineColor:Number = 0xFF00FF;  //the initial line color, right now it's a pink color
  31. var lineThickness:Number = 2.0;  //how thick your line will be
  32. var red:String = red_txt.text;  //sets the red value to the initial value of red_txt
  33. var green:String = green_txt.text;  //sets the green value to the initial value of green_txt
  34. var blue:String = blue_txt.text;  //sets the blue value to the initial value of blue_txt
  35. var strength:Number = 1.0;  //how strong the glow is around the line
  36. var speedX:Number = 3.0;  //how fast the blur flows by on the X axis - to change direction, give a negative number
  37. var speedY:Number = 0.0;  //how fast the blur flows by on the Y axis - to change direction, give a negative number
  38.  
  39. //this function updates the colors when the "UPDATE" button is pressed
  40. function updateColors(e:MouseEvent):void
  41. {
  42.     red = red_txt.text;
  43.     blue = blue_txt.text;
  44.     green = green_txt.text;
  45.     lineColor = colorPicker.selectedColor;
  46.     visualizer();
  47. }
  48.  
  49. //this is the heart of the visualizer
  50. function visualizer()
  51. {
  52.     var ba:ByteArray = new ByteArray();
  53.     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
  54.     var bm:Bitmap = new Bitmap(bmd);
  55.     addChild(bm);
  56.     var sp:Sprite = new Sprite();
  57.     addChild(sp);
  58.     var blur:BlurFilter = new BlurFilter(5,5,3);  //the paramaters for the Blur Filter - ex:  BlurFilter(blurX, blurY, Quality);
  59.     //the ColorMatrix below I do not know much about.  I do know you basically only want to alter the values I am altering.
  60.     var colorMatrix:ColorMatrixFilter = new ColorMatrixFilter([
  61.      red, 0, 0, 0, 0,
  62.          0, green, 0, 0, 0,
  63.          0, 0, blue, 0, 0,
  64.          0, 0, 0, strength, 0
  65.     ]);
  66.     addEventListener(Event.ENTER_FRAME, loop);  //sets up the loop function to run every frame per second
  67.  
  68.     //the "loop" function below draws the center wave line based off of the sound spectrum of your audio
  69.     function loop(e:Event):void
  70.     {
  71.         sp.graphics.clear();
  72.         sp.graphics.lineStyle(lineThickness, lineColor);
  73.         sp.graphics.moveTo(-1, stage.height/2);
  74.         sp.alpha = lineAlpha;
  75.         SoundMixer.computeSpectrum(ba);
  76.         for (var i:uint=0; i<256; i++)
  77.         {
  78.             var num:Number = -ba.readFloat()*200 + stage.height/2;
  79.             sp.graphics.lineTo(i*2, num);
  80.         }
  81.         bmd.draw(sp);
  82.         bmd.applyFilter(bmd,bmd.rect,new Point(),blur);  //applies the Blur Filter
  83.         bmd.applyFilter(bmd,bmd.rect,new Point(),colorMatrix);  //applies the ColorMatrix Filter
  84.         bmd.scroll(speedX,speedY); //this is where "speed" sets how fast the 'flow' of the filters will be
  85.        
  86.     }
  87. }
  88. visualizer();