The effect of the three-day music spectrum:
Includes five classes:
MusicControl class, which is used to control music, including the control of music loading and playback.
ID3Control class, used to extract information related to music files, display various information cyclically, and display garbled characters in extracted Chinese. Here, you can use a function to correct the information:
- Function EncodeUtf8 (str: String): String {
- Var oriByteArr: ByteArray = new ByteArray ();
- OriByteArr. writeUTFBytes (str );
- Var tempByteArr: ByteArray = new ByteArray ();
- For (var I = 0; I <oriByteArr. length; I ++ ){
- If (oriByteArr = 194 ){
- TempByteArr. writeByte (oriByteArr [I + 1]);
- I ++;
- } Else if (oriByteArr = 195 ){
- TempByteArr. writeByte (oriByteArr [I + 1] + 64 );
- I ++;
- } Else {
- TempByteArr. writeByte (oriByteArr );
- }
- }
- TempByteArr. position = 0;
- Return tempByteArr. readMultiByte (tempByteArr. bytesAvailable, "chinese ");
- }
Spectrum class, which manages and displays the Spectrum. The Spectrum information is retrieved from the MusicControl class.
- SoundMixer. computeSpectrum (_ spectrumArray, true );
The second parameter "true" indicates that the spectrum is extracted, and "false" indicates that the waveform is obtained.
- /*
- Class function: displays the spectrum.
- */
- Package net. cdipan. spectrum {
- Import flash. display. Sprite;
- Import flash. utils. ByteArray;
- Import flash. text. TextField;
- Import flash. events. MouseEvent;
- Import flash.net. navigateToURL;
- Import flash.net. URLRequest;
- Public class spectrum extends sprite {
- // Records the array of Spectrum
- Private VaR _ spectrum: array;
- // Record display type
- Private VaR _ type: int;
- // The sprite object used to display the spectrum
- Private VaR _ showspectrum: SPRITE;
- // The sprite object used to display the columnar Spectrum
- Private VaR _ show1: SPRITE;
- // The sprite object used to display the wave spectrum
- Private VaR _ show2: SPRITE;
- // The sprite object used to display the waveform Spectrum
- Private VaR _ show3: SPRITE;
- // Column object
- Private VaR _ column: column;
- // Waveform object
- Private VaR _ waveform: waveform;
- Public Function spectrum (): void {
- _ Spectrum = new array (512 );
- _ ShowSpectrum = new Sprite ();
- _ ShowSpectrum. x = 22;
- _ ShowSpectrum. y = 18;
- _ Show1 = new Sprite ();
- _ Show2 = new Sprite ();
- _ Show3 = new Sprite ();
- This. addChild (_ showSpectrum );
- // Create a columnar Spectrum
- CreateColumn (64,3, 1, _ show1 );
- CreateColumn (256, 1, 0, _ show2 );
- // Create a waveform Spectrum
- _ Waveform = new Waveform ();
- _ Show3.addChild (_ waveform );
- _ ShowSpectrum. addChild (_ show1 );
- }
- // Obtain the Spectrum Array
- Public function getSpectrum (byteArray: ByteArray): void {
- For (var I: int = 0; I <512; I ++ ){
- _ Spectrum = byteArray. readFloat ();
- }
- // Send the spectrum data to the column and wave sprite instances
- For (var j: int = 0; j <64; j ++ ){
- Var temp1: Column = _ show1.getChildByName ("column _" + j. toString () as Column;
- Temp1.getSpectrum (_ spectrum [j * 4] + _ spectrum [j * 4 + 1] + _ spectrum [j * 4 + 2] + _ spectrum [j * 4 + 3] + _ spectrum [j * 4 + 256] + _ spectrum [j * 4 + 257] + _ spectrum [j * 4 + 258] + _ spectrum [j * 4 + 259]) * 12.5 );
- }
- For (var m: int = 0; m <256; m ++ ){
- Var temp2: Column = _ show2.getChildByName ("column _" + m. toString () as Column;
- Temp2.getSpectrum (_ spectrum [m] + _ spectrum [m + 256]) * 50 );
- }
- // Send the spectrum data to the waveform's genie instance
- _ Waveform. getSpectrum (_ spectrum );
- }
- // Create a column sprite object
- Private function createColumn (f_num: int, f_width: int, f_space: int, target: Sprite): void {
- For (var I: int = 0; I <f_num; I ++ ){
- _ Column = new Column ();
- _ Column. name = "column _" + I. toString ();
- _ Column. width = f_width;
- _ Column. x = I * (f_width + f_space );
- Target. addChild (_ column );
- }
- }
- // Change the style (when the type is 0, the bar is displayed. When the value is 1, the wave is displayed. When the value is 2, the waveform is displayed)
- Public function changeType (type: int): void {
- Switch (type ){
- Case 0:
- If (_ showSpectrum. contains (_ show1 )){
- _ ShowSpectrum. removeChild (_ show1 );
- }
- If (_ showSpectrum. contains (_ show2 )){
- _ ShowSpectrum. removeChild (_ show2 );
- }
- If (_ showSpectrum. contains (_ show3 )){
- _ ShowSpectrum. removeChild (_ show3 );
- }
- _ ShowSpectrum. addChild (_ show1 );
- Break;
- Case 1:
- If (_ showSpectrum. contains (_ show1 )){
- _ ShowSpectrum. removeChild (_ show1 );
- }
- If (_ showSpectrum. contains (_ show2 )){
- _ ShowSpectrum. removeChild (_ show2 );
- }
- If (_ showSpectrum. contains (_ show3 )){
- _ ShowSpectrum. removeChild (_ show3 );
- }
- _ ShowSpectrum. addChild (_ show2 );
- Break;
- Case 2:
- If (_ showSpectrum. contains (_ show1 )){
- _ ShowSpectrum. removeChild (_ show1 );
- }
- If (_ showSpectrum. contains (_ show2 )){
- _ ShowSpectrum. removeChild (_ show2 );
- }
- If (_ showSpectrum. contains (_ show3 )){
- _ ShowSpectrum. removeChild (_ show3 );
- }
- _ ShowSpectrum. addChild (_ show3 );
- Break;
- }
- }
- }
- }
Column class, a stripe Spectrum class. In the Spectrum class, 64 columnar styles are created, and 256 are created in the wave style.
- /*
- Class function: columnar spectrum.
- */
- Package net. cdipan. spectrum {
- Import flash. display .*;
- Import flash. geom .*;
- Import flash. events. Event;
- Import flash. utils. Timer;
- Import flash. events. TimerEvent;
- Public class Column extends Sprite {
- // Color of the small square on the top
- Private const square_color: uint = 0 xffffff;
- // Top color
- Private const top_color: uint = 0 xffffff;
- // Intermediate color
- Private const middle_color: uint = 0x8cdcff;
- // Bottom color
- Private const bottom_color: uint = 0x07f7ff;
- // Background genie object
- Private var BG_Sp: Sprite;
- // Mask genie object
- Private var mask_Sp: Sprite;
- // Small box genie object
- Private var square_Sp: Sprite;
- // Record the value of the last spectrum. If it is higher than this time, it will be reduced by one. Otherwise, this value will be set to this value.
- Private var oldNum: Number;
- // Timer object
- Private var myTimer: Timer;
- // Record whether small blocks can fall
- Private var canDrop: Boolean;
- Public function Column (): void {
- BG_Sp = new Sprite ();
- DrawGradualRect ();
- AddChild (BG_Sp );
- Mask_Sp = new Sprite ();
- Drawmaskrect ();
- Addchild (mask_sp );
- Square_sp = new sprite ();
- Drawsquarerect ();
- Square_sp.y = 99;
- Square_sp.addeventlistener (event. enter_frame, _ enterframe );
- Addchild (square_sp );
- // Sets the mask.
- Bg_sp.mask = mask_sp;
- Oldnum = 0;
- Mytimer = new timer (200, 1 );
- Mytimer. addeventlistener ("timer", ontimer );
- Candrop = false;
- }
- // Drop the small square
- Private function _ enterframe (E: Event): void {
- If (candrop ){
- Square_sp.y + = 4;
- }
- If (square_Sp.y> 99 ){
- Square_Sp.y = 99;
- }
- If (square_Sp.y <-1 ){
- Square_Sp.y =-1;
- }
- }
- // Draw a gradient chart
- Private function drawGradualRect (): void {
- Var fillType: String = GradientType. RADIAL;
- Var colors: Array = [top_color, middle_color, bottom_color];
- Var alphas: Array = [1, 1, 1];
- Var ratios: Array = [0x00, 0x7f, 0xff];
- BG_Sp.graphics.beginGradientFill (fillType, colors, alphas, ratios );
- BG_Sp.graphics.drawRect (0,-1,100, 1 );
- BG_Sp.rotation = 90;
- }
- // Draw a mask image
- Private function drawmaskrect (): void {
- Mask_sp.graphics.linestyle ();
- Mask_sp.graphics.beginfill (0 );
- Mask_sp.graphics.drawrect (0,-100, 1 );
- Mask_sp.graphics.endfill ();
- Mask_sp.y = 100;
- }
- // Draw small blocks
- Private function drawsquarerect (): void {
- Square_sp.graphics.linestyle ();
- Square_sp.graphics.beginfill (square_color );
- Square_sp.graphics.drawrect (0, 0, 1, 1 );
- Square_sp.graphics.endfill ();
- }
- // Receives spectrum data
- Public Function getspectrum (Num: Number): void {
- If (oldnum> num ){
- Oldnum-= 7;
- } Else {
- Oldnum = num;
- If (oldnum! = 0 ){
- // Call the small block motion function
- Squaremove (oldnum );
- }
- }
- If (oldnum <0 ){
- Oldnum = 0;
- }
- Mask_sp.height = oldnum;
- }
- // Function for controlling the movement of small blocks
- Private function squaremove (Num: Number): void {
- If (square_sp.y> 99-oldnum ){
- Square_sp.y = 99-num;
- Candrop = false;
- Mytimer. Reset ();
- Mytimer. Start ();
- }
- }
- Public function onTimer (e: TimerEvent): void {
- CanDrop = true;
- }
- }
- }
Waveform class, Waveform class, drawn using a line, adding the effect of gradually disappearing tracks.
- /*
- Class function: waveform.
- */
- Package net. cdipan. spectrum {
- Import flash. display .*;
- Import flash. filters .*;
- Import flash. geom .*;
- Public class Waveform extends Sprite {
- // Line color
- Private const line_color: uint = 0x07f7ff;
- // Create a line sprite object
- Private var Line: Sprite;
- // Bitmap object used for gradually disappearing tracks
- Private var BMP data: BitmapData;
- Private var bmp: Bitmap;
- // Filter parameters
- Private var colorM: ColorMatrixFilter;
- Private var blur: BlurFilter;
- Private var r: Rectangle;
- Private var point;
- // Use a number to make filter processing slow
- Private var num: int;
- Public function Waveform (): void {
- Line = new Sprite ();
- Bmp data = new BitmapData (256,100, true, 0 );
- Bmp = new Bitmap (bmp data );
- ColorM = new ColorMatrixFilter ([. 98,0,. 98,0,., 0,]);
- Blur = new BlurFilter (7,7, BitmapFilterQuality. LOW );
- R = new Rectangle (0, 0, 256,100 );
- P = new Point (0, 0 );
- // Add a display object
- This. blendMode = BlendMode. ADD;
- This. addChild (bmp );
- This. addchild (line );
- }
- // Receives spectrum data
- Public Function getspectrum (array: array): void {
- If (Num % 2 = 0 ){
- VaR M: Number = 0;
- For (var j = 0; j <256; j + = 2 ){
- M + = array [J];
- }
- If (M! = 0 ){
- // When the playback is stopped, no image is drawn, and only a straight line is displayed.
- BMP data. Draw (this );
- }
- BMP data. applyfilter (BMP data, R, P, colorm );
- BMP data. applyfilter (BMP data, R, P, blur );
- }
- Num ++;
- Line. Graphics. Clear ();
- Line. Graphics. linestyle (1, line_color, 100 );
- For (VAR I = 0; I <256; I + = 2 ){
- VaR N: Number = array * 50;
- If (I! = 0 ){
- Line. Graphics. lineto (I, 50-n );
- } Else {
- Line. Graphics. moveTo (0, 50, N );
- }
- }
- }
- }
- }
Source File Download:
Flash music spectrum production .rar
From: http://www.68design.net/Web-Guide/Flash/45403-1.html