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

Online MD5 checksum verifier

Get Adobe Flash player
by esabear 03 Jan 2011
    Embed
/**
 * Copyright esabear ( http://wonderfl.net/user/esabear )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8mY2
 */

package {
    import com.adobe.crypto.MD5;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.ProgressEvent;
    import flash.events.IOErrorEvent;
    import flash.errors.MemoryError;
    import flash.net.URLRequest;
    import flash.net.URLLoaderDataFormat;
    import flash.net.FileReference;
    import flash.text.TextField;
    import flash.utils.ByteArray;
    
    public class FlashTest extends Sprite {
        private var _infoTxt:TextField;
        private var _file:FileReference;
        
        public function FlashTest() {
            // UI
            var sp:Sprite = new Sprite();
                sp.graphics.lineStyle(1, 0x0, 0.6);
                sp.graphics.beginFill(0xCCFFDD);
                sp.graphics.drawEllipse(0, 0, 130, 50);
                sp.graphics.endFill();
                sp.x = (stage.stageWidth - sp.width) * .5;
                sp.y = (stage.stageHeight - sp.height) * .5;
                sp.buttonMode = true;
            var txt:TextField = new TextField();
                txt.text = "Browse file";
                txt.x = (sp.width - txt.textWidth) * .5;
                txt.y = (sp.height - txt.textHeight) * .5;
                txt.mouseEnabled = false;
            sp.addChild(txt);
            addChild(sp);
            
            // UI for result
            _infoTxt = new TextField();
            _infoTxt.x = 10;
            _infoTxt.y = sp.y + sp.height + 10;
            _infoTxt.width = stage.stageWidth;
            _infoTxt.text = "Suggested file size < 100 MB.";
            addChild(_infoTxt);
            
            // uploader
            _file = new FileReference();
            
            // Event
            sp.addEventListener(MouseEvent.CLICK, clickButtonHandler);
        }
        
        private function clickButtonHandler(e:Event):void {
            _file.addEventListener(Event.SELECT, selectFileHandler);
            _file.browse();
        }
        private function selectFileHandler(e:Event):void {
            _infoTxt.text = "Loading...";
            if (_file.size > 100 * 1024 * 1024)
                _infoTxt.appendText("\nWarnning: suggested file size < 100 MB.");
            _file.removeEventListener(Event.SELECT, selectFileHandler);
            _file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            _file.addEventListener(Event.COMPLETE, completeLoadHandler);
            try {
                _file.load();
            } catch (e:MemoryError) {
                _infoTxt.text = e.toString();
            }

        }
        private function progressHandler(e:ProgressEvent):void {
            _infoTxt.text = "Loading..." + Math.round(100 * e.bytesLoaded / e.bytesTotal) + "%";
        }

        private function completeLoadHandler(e:Event):void {
            _file.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
            _file.removeEventListener(Event.COMPLETE, completeLoadHandler);
            try {
                _infoTxt.text = "File = " + _file.name + "\nMD5 Checksum = " + MD5.hashBinary(_file.data);
            } catch (e:Error) {
                _infoTxt.text = e.toString();
            }
        }
    }
}