ローカルファイルの読み込み・保存

by TheCoolMuseum
♥0 | Line 54 | Modified 2009-12-09 20:56:01 | MIT License
play

ActionScript3 source code

/**
 * Copyright TheCoolMuseum ( http://wonderfl.net/user/TheCoolMuseum )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ro1s
 */

package {
    import flash.display.Sprite;
    import flash.display.Loader;
    
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.net.FileReference;
    import flash.net.FileFilter;
    
    public class FlashTest extends Sprite {
        private var fileLoader:FileReference;
        private var fileSaver:FileReference;
        private var imageLoader:Loader;
        
        public function makeBtn(name:String):TextField{
           var btn:TextField = new TextField();
            btn.text = name;
            btn.autoSize = TextFieldAutoSize.LEFT;
            btn.border = true;
            btn.selectable = false;
            return btn;
        } 
        public function FlashTest() {
            var loadBtn:TextField = makeBtn("LOAD");
            addChild(loadBtn);
            loadBtn.addEventListener(MouseEvent.CLICK, onClickLoadBtn);
        }
        private function onClickLoadBtn(e:Event):void{
            load();
        }
        private function load():void{
            var fileFilter:FileFilter = new FileFilter("Images (.png .jpg .gif)", "*.png;*.jpg;*.gif");

           	fileLoader = new FileReference();
        	fileLoader.addEventListener(Event.SELECT, onSelectLoadFile);
        	fileLoader.addEventListener(Event.COMPLETE, onCompleteLoadFile);
        	
        	fileLoader.browse([fileFilter]);
        }
        private function onSelectLoadFile(e:Event):void{
            fileLoader.load();
        }
        private function onCompleteLoadFile(e:Event):void{
        	//imageLoader = new Loader();
          	//imageLoader.loadBytes(fileLoader.data);
        	//addChild(imageLoader);
            
            var saveBtn:TextField = makeBtn("SAVE");
            saveBtn.y = 32;
            addChild(saveBtn);
            saveBtn.addEventListener(MouseEvent.CLICK, onClickSaveBtn);
        }
        private function onClickSaveBtn(e:Event):void{
            save();
        }
        private function save():void{
        	//imageLoader = new Loader();
          	//imageLoader.loadBytes(fileLoader.data);
           	fileSaver = new FileReference();
           	fileSaver.save(fileLoader.data);
        }
    }
}

Forked