※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!
wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)
選んだファイルを圧縮してから Base64 エンコードする ByteArray.compress()とByteArray.deflate()のサイズ差を検証
- // forked from nemu90kWw's 選んだファイルを圧縮してから Base64 エンコードする
- // forked from hikipuro's 2009-3-14 選んだファイルを Base64 エンコードする
- package
- {
- import flash.display.Loader;
- import flash.display.SimpleButton;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.net.FileFilter;
- import flash.net.FileReference;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.utils.ByteArray;
- import mx.utils.Base64Encoder;
- import flash.system.System;
- public class Main extends Sprite
- {
- private var fileReference:FileReference;
- private var textField:TextField;
- private var button1:SimpleButton;
- private var loader:Loader;
- private var bytes_source:ByteArray;
- private var bytes_zlib:ByteArray;
- private var bytes_deflate:ByteArray;
- /**
- * コンストラクタ
- */
- public function Main():void
- {
- if (stage) init();
- else addEventListener(Event.ADDED_TO_STAGE, init);
- }
- /**
- * 初期化メソッド
- * @param e
- */
- private function init(e:Event = null):void
- {
- removeEventListener(Event.ADDED_TO_STAGE, init);
- // entry point
- // ファイルの選択ボタンの作成
- button1 = new SimpleButton();
- button1.upState = makeButton(0xDDDDDD, 100, 20, 10, "ファイルの選択");
- button1.overState = makeButton(0xEEEEEE, 100, 20, 10, "ファイルの選択");
- button1.downState = makeButton(0xCCCCCC, 100, 20, 10, "ファイルの選択");
- button1.hitTestState = button1.upState;
- button1.addEventListener(MouseEvent.MOUSE_DOWN, onSelectButtonDown);
- button1.x = 5;
- button1.y = 5;
- addChild(button1);
- // テキストフィールドの準備
- textField = new TextField();
- textField.selectable = false;
- textField.autoSize = TextFieldAutoSize.LEFT;
- textField.x = 0;
- textField.y = 30;
- textField.text = "";
- addChild(textField);
- // イベントの登録
- fileReference = new FileReference();
- fileReference.addEventListener(Event.SELECT, onSelect);
- fileReference.addEventListener(Event.COMPLETE, onComplete);
- // ローダーの準備
- loader = new Loader();
- loader.y = 80;
- addChild(loader);
- }
- /**
- * ファイルの選択ボタンが押された時
- * @param event
- */
- private function onSelectButtonDown(event:MouseEvent):void
- {
- // ファイル選択ダイアログを表示する
- fileReference.browse();
- }
- /**
- * ファイル選択イベント
- * @param event
- */
- private function onSelect(event:Event):void
- {
- fileReference.load();
- }
- /**
- * 読み込み完了イベント
- * @param event
- */
- private function onComplete(event:Event):void
- {
- bytes_source = fileReference.data;
- loader.loadBytes(fileReference.data);
- loader.scaleX = 0.5;
- loader.scaleY = 0.5;
- bytes_source.position = 0;
- bytes_zlib = new ByteArray();
- bytes_source.readBytes(bytes_zlib);
- bytes_zlib.compress();
- bytes_source.position = 0;
- bytes_deflate = new ByteArray();
- bytes_source.readBytes(bytes_deflate);
- bytes_deflate.deflate();
- textField.text = "source : "+bytes_source.length+"\ncompress : "+bytes_zlib.length+"\ndeflate : "+bytes_deflate.length;
- }
- /**
- * ボタンを作って返す
- * @param color 色
- * @param width 幅
- * @param height 高さ
- * @param round 角丸の大きさ
- * @param text ボタンのテキスト
- * @return ボタン
- */
- private function makeButton(color:uint, width:int, height:int, round:int, text:String):Sprite
- {
- var t:TextField = new TextField();
- var s:Sprite = new Sprite();
- s.graphics.lineStyle(2);
- s.graphics.beginFill(color);
- s.graphics.drawRoundRect(0, 0, width, height, round);
- s.graphics.endFill();
- t.text = text;
- t.selectable = false;
- t.width = width;
- t.autoSize = TextFieldAutoSize.CENTER;
- s.addChild(t);
- return s;
- }
- }
- }
notice:



