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

flash on 2011-9-13

Get Adobe Flash player
by mii 13 Sep 2011
    Embed
/**
 * Copyright mii ( http://wonderfl.net/user/mii )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fGO6
 */

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 bmp1:Bitmap = Bitmap( evt.target.content );
        if(evt.target.content){
            var bmp1:Bitmap = Bitmap( evt.target.content );
        
            bmp1.y = 100;
            if((bmp1.width >imgMax)||(bmp1.height >imgMax)){
                if( bmp1.width > bmp1.height){
                    var wRatio:Number = imgMax / bmp1.width;
                    bmp1.width = imgMax;
                    bmp1.height *= wRatio;
                } else {
                    var hRatio:Number = imgMax / bmp1.height;
                    bmp1.height = imgMax;
                    bmp1.height *= hRatio;
                }
            }
            imgSprite.addEventListener( MouseEvent.MOUSE_DOWN, imgDrag)
            imgSprite.buttonMode = true;
            imgSprite.addChild( bmp1 );
            addChild( imgSprite );
        }

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