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

FileReferenceViewLocalImg

Get Adobe Flash player
by Kazutaka 17 Jun 2009
package{  
// forked from Kazutaka's FileReferenceViewLocalImg
	import flash.display.Sprite;
    import flash.display.Shape;
    import flash.display.Loader;
    import flash.display.Bitmap; 
    import flash.text.TextField;  
    import flash.net.FileReference;
    import flash.net.URLLoader;
    import flash.events.Event;
    import flash.events.MouseEvent;
    [SWF(width = "700", height = "700", backgroundColor = 0xFFFFFF, frameRate = "30")]

    public class FlashTest extends Sprite {
        private var imgSprite:Sprite;
	private var myfile:FileReference;
        private var btnSprite:Sprite;
        private var imgMax:Number = 640;
        function FlashTest(){
            // write as3 code here..
            setView();
            initEvent();
        }
        private function setView():void{
            btnSprite = new Sprite();
			imgSprite = new Sprite();
            var myShape:Shape = new Shape();
            myShape.graphics.beginFill(0xcccccc);
            myShape.graphics.lineStyle(0);
            myShape.graphics.drawRoundRect( 10,10, 150,50,6,6); 
            var myText:TextField = new TextField();
            myText.appendText(" ローカル画像\n  表示ボタン");
            myText.x = 12;
            myText.y = 10;
            myText.selectable = false;
            myText.mouseEnabled = false;
            btnSprite.addChild( myShape );
            btnSprite.addChild( myText);
            addChild( btnSprite );
                  
        }
        private function initEvent():void{
             myfile = new FileReference();
             myfile.addEventListener( Event.SELECT , fileSelect );
			myfile.addEventListener( Event.COMPLETE, loadComplete );
             btnSprite.addEventListener(  MouseEvent.CLICK, fileBrowse );
			btnSprite.addEventListener(MouseEvent.ROLL_OVER, overFunc);
			btnSprite.addEventListener(MouseEvent.ROLL_OUT, outFunc);
            btnSprite.buttonMode = true;
        }
    	private function overFunc(evt:Event):void {
		evt.currentTarget.alpha = 0.5;
	}
	private function outFunc(evt:Event):void {
		evt.currentTarget.alpha = 1;
	}
        private function fileBrowse( evt:Event ):void {
			myfile.browse();	
	}
	private function fileSelect( evt:Event ):void {
			myfile.load();
	}
	private function loadComplete(evt:Event):void {
		var myLoader:Loader = new Loader();
		myLoader.loadBytes( myfile.data );
		myLoader.contentLoaderInfo.addEventListener( Event.INIT, initLoaded );
	}
	private function initLoaded(evt:Event):void{
		var bmp:Bitmap = Bitmap( evt.target.content );
		if(evt.target.content){
			var bmp:Bitmap = Bitmap( evt.target.content );
		
			bmp.y = 100;
			if((bmp.width >imgMax)||(bmp.height >imgMax)){
				if( bmp.width > bmp.height){
					var wRatio:Number = imgMax / bmp.width;
					bmp.width = imgMax;
					bmp.height *= wRatio;
				} else {
					var hRatio:Number = imgMax / bmp.height;
					bmp.height = imgMax;
					bmp.height *= hRatio;
				}
			}
			imgSprite.addEventListener( MouseEvent.MOUSE_DOWN, imgDrag)
			imgSprite.buttonMode = true;
			imgSprite.addChild( bmp );
			addChild( imgSprite );
		}

	}
	private function imgDrag(evt:MouseEvent):void{
		evt.currentTarget.startDrag();
	}
			
   }
 }