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

pv3dのライブラリを使ってzip解凍

重過ぎ
合計が1MB分の画像をつめたZIPがエラーになったので
量を減らしてみました(330KB)
Get Adobe Flash player
by zahir 27 Dec 2009

    Talk

    paq at 27 Dec 2009 01:13
    Error: distance is too far back in fixed or dynamic block at nochump.util.zip::Inflater/codes() at nochump.util.zip::Inflater/inflate() at nochump.util.zip::ZipFile/getInput() at Zip_test2/loadComplete() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete()
    zahir at 27 Dec 2009 09:48
    自分でやったのでは問題なく開けるんですが、こっちはなんかダメですね・・・ ライブラリの方では解凍アルゴリズムをわざわざ自作したものを使ってるので それが原因だとしたらどうしようもないですね。 そもそも同期モードの時点で・・・
    Embed
/**
 * Copyright zahir ( http://wonderfl.net/user/zahir )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mu2F
 */

//重過ぎ
//合計が1MB分の画像をつめたZIPがエラーになったので
//量を減らしてみました(330KB)
package{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.DropShadowFilter;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.system.Security;
	
	import nochump.util.zip.*;
	
	[SWF(backgroundColor="#999999", frameRate=30)]

	public class Zip_test2 extends Sprite{
		
		private const policy:String = "http://zahir.coresv.com/zahir/crossdomain.xml";
		private const url:String  = "http://zahir.coresv.com/zahir/img2.zip";
		private const IMG:Array = ["jpg","jpeg", "gif", "png"];
		
		private var data:Array = [];
		private var imgs:Array = [];
		
		private var zip:ZipFile;
		
		private var loader:URLLoader;
		private var l:Loader;
		private var num:int = 0;
		
		public function Zip_test2(){
			super();
			Security.loadPolicyFile( policy );
			
			loader = new URLLoader();
			loader.dataFormat = URLLoaderDataFormat.BINARY;  //クラスの名前長過ぎ
			
			loader.addEventListener(Event.COMPLETE, loadComplete);
			loader.load( new URLRequest( url ) );
		}
		public function loadComplete( e:Event ):void{
			loader.removeEventListener(Event.COMPLETE, loadComplete );
			
			zip = new ZipFile( loader.data );
			var entrys:Array = zip.entries;
			for(var i:int = 0, len:int = entrys.length; i<len; i++){
				if( check( entrys[i] ) )
					data[data.length] =  zip.getInput( zip.getEntry( entrys[i] ) );
			}
			
			load();
		}
		private function load():void{
			l = new Loader();
			l.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImg);
			l.loadBytes( data[num] );
		}
		private function loadImg( e:Event ):void{
			l.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImg);
			imgs[num] = l.content as Bitmap;
			
			num++;
			if( num < data.length) load();
			else addImgs();
		}
		private function addImgs():void{
			var size:int = 100;
			var lim:int = 4;
			var xx:int = 0;
			var yy:int = -1;
			for(var i:int = 0, len:int = imgs.length; i<len; i++){
				var img:Bitmap = imgs[i];
				if(img.width >= img.height){
					img.width = size, img.scaleY = img.scaleX;
				}else{
					img.height = size, img.scaleX = img.scaleY;
				}
				
				xx = i%lim;
				if( xx == 0){
					yy++;
				}
				img.x = xx*(size + 10) + 30;
				img.y = yy*(size + 10) + 30;
				img.filters = [new DropShadowFilter( 8, 45, 0x0, 0.6, 4,4, 2)  ];
				
				addChild( img );
			}
		}
		private function check( fileName:String ):Boolean{
			var len:int = IMG.length;
			for(var i:int = 0; i<len; i++){
				var extension:String = IMG[i];
				var target:String = fileName.substr(fileName.length - extension.length, fileName.length);
				if(new RegExp(extension, "i").test( target ) ) return true;
			}
			return false;
		}
	}
}