In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

MP3 UPLOAD

Get Adobe Flash player
by christian 07 Mar 2012
/**
 * Copyright christian ( http://wonderfl.net/user/christian )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xeOP
 */

package
{
    import flash.net.*;
    import flash.media.*;    
    import flash.events.*;
    import flash.display.*;
    import flash.utils.ByteArray;

    import com.bit101.components.*;

    /**  @author SPANVEGA // CHRISTIAN  **/

    [SWF(backgroundColor = '0xFFFFFF', width = '465', height = '465', frameRate = '25')]

    public class MP3_UPLOAD extends Sprite 
    {
        private var W : uint = stage.stageWidth, H : uint = stage.stageHeight;

        private var file : FileReference = new FileReference ();
        private var output : TextArea;

        private var channel : SoundChannel;
        private var sound : Sound;

        private var bytes : ByteArray = new ByteArray ();
        private var value : Number;
        private var spec  : Sprite;


        public function MP3_UPLOAD ()
        {
            Wonderfl.disable_capture ();

            var btn : PushButton = new PushButton (this, 10, 10, 'UPLOAD MP3',browse);

            output = new TextArea (this, 10, 40);
            output.setSize (W - 20, H / 2);
            output.draw ();

            //

            addChild (spec = new Sprite ());        
            spec.y = W - 80;
            spec.x = 10;

            //

            file.addEventListener (Event.SELECT, select);
            file.addEventListener (Event.COMPLETE, complete);

            stage.addEventListener (Event.ENTER_FRAME, frame);
        }

        private function browse (e : MouseEvent) : void 
        {
            file.browse ( [new FileFilter ('Music File (*.mp3)', '*.mp3;')] ); 
        }

        private function select (e : Event) : void 
        {
            file.load (); 
        }

        private function complete (e : Event) : void 
        {
            if (channel) channel.stop ();

            sound = new Sound ();
            sound.addEventListener (Event.ID3, id3);
            sound.loadCompressedDataFromByteArray (file.data, file.data.length); 

            channel = sound.play (); 
        }

        private function id3 (e : Event) : void
        {
            output.text = 'ID3 TAGS\n----------\n';
            
            for (var s : String in sound.id3)
            
            output.text += s + '  :  ' + sound.id3[s] + '\n';
        }

        private function frame (e : Event) : void
        {
            SoundMixer.computeSpectrum (bytes, false, 0);

            //

            spec.graphics.clear ();
            spec.graphics.lineStyle (1, 0x333333);

            for (var i : int = 0; i < 256; i+= 2)
            {
                value = bytes.readFloat () * 75;

                spec.graphics.moveTo (i * 1.75, 0);
                spec.graphics.lineTo (i * 1.75, -value);

                bytes.position += 4;
            }
        }
    }
}