package fwm.byte100.composeBmp { import com.sociodox.theminer.data.InternalEventEntry; import flash.display.Bitmap; import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.net.FileReference; import flash.utils.ByteArray; import flash.utils.Dictionary; import fwm.assist.bit101.components.PushButton; import fwm.assist.ziplib.fzip.FZip; import fwm.assist.ziplib.fzip.FZipFile; import fwm.byte100.gameMonitor.BaseMenu; import fwm.byte100.gameMonitor.MenuName; /* description: 合成zip 文件中的图片文件到一个大图里面,并生成数据文件 * author: fwm * date: 2013-10-30 下午9:28:22 * project: ByteGame100 * http://www.byte100.com * copyright 2013~2015 by lzn */ public class ComposeMenu extends BaseMenu { private var openZipBtn:PushButton; public function ComposeMenu() { super("合成图片"); name = MenuName.COMPOSEBMP_MENU; } override public function Active():void { super.Active(); openZipBtn = new PushButton(mainCanvas, 10, 40, "打开本地Zip文件", OpenZipfile); } override public function Dispose():void { super.Dispose(); mainCanvas.removeChild(openZipBtn); openZipBtn.removeEventListener(MouseEvent.MOUSE_DOWN, OpenZipfile); openZipBtn = null; } private function OpenZipfile(e:Event):void { var file:FileReference = new FileReference(); file.browse(); file.addEventListener(Event.SELECT, function(e:Event):void { file.load(); file.addEventListener(Event.COMPLETE, function(e:Event):void { var bytedata:ByteArray = e.target.data; var zip:FZip = new FZip(); var temp:Vector.<FZipFile> = new Vector.<FZipFile>(); zip.addEventListener(Event.COMPLETE, function(e:Event):void { for (var i:int = 0; i < zip.getFileCount(); i++){ var fileItem:FZipFile = zip.getFileAt(i); temp.push(fileItem); } LoadFZipfileAr(temp, 0); }); zip.loadBytes(bytedata); }); }); } var temp:Array = new Array(); private function LoadFZipfileAr(_ar:Vector.<FZipFile>,_index:int):void { var fzipItem:FZipFile = _ar[_index]; var l:Loader = new Loader(); l.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void { var bmp:Bitmap = l.content as Bitmap; //mainCanvas.addChild(bmp); temp.push(bmp); trace("l:", temp.length); trace(fzipItem.filename, ":", bmp.width, "×", bmp.height); if (_index < _ar.length - 1) { var index:int = _index + 1; LoadFZipfileAr(_ar, index); }else { //temp.sortOn(int, Array.DESCENDING); for (var i:int = 0; i < temp.length; i++) { trace((temp[i] as Bitmap).height, "×", (temp[i] as Bitmap).width); } temp.sortOn(["height", "width"], [Array.NUMERIC, Array.NUMERIC]); trace("-----------------------------------------------"); for (var j:int = 0; j < temp.length; j++) { trace((temp[j] as Bitmap).height, "×", (temp[j] as Bitmap).width); } var s:Sprite = Se(temp, 500) mainCanvas.addChild(s); s.y = 60; } }); l.loadBytes(fzipItem.content); } private function Se(_ar:Array,_maxW:int):Sprite { var sp:Sprite = new Sprite(); var h:int = 0; var xr:int = 0; var yr:int = 0; var tempW:int = 0; for (var i:int = 0; i < _ar.length ; i++) { tempW = (_ar[i].width + xr); if (tempW > _maxW) { trace("Width:",tempW); yr += _ar[i-1].height; xr = 0; tempW = 0; } sp.addChild(_ar[i]); _ar[i].x = xr; _ar[i].y = yr; xr += _ar[i].width; } return sp; } public var sr:Vector.<int> = new Vector.<int>(); private function ParseBmp(_arbmp:Vector.<Bitmap>):void { var dic:Dictionary = new Dictionary(); var wx:int; var hx:int; var id:int; for (var i:int = 0; i < _arbmp.length; i++) { dic[i] = _arbmp[i]; } for (var j:int = 0; j < _arbmp.length; j++) { trace(j); if (_arbmp[j].height > hx) { hx = _arbmp[j].height; id = j; trace(id); } } sr.push(id); var bmp:Bitmap = dic[id] as Bitmap; mainCanvas.addChild(bmp); } private function Temp(_dic:Dictionary):void { for each(var item:Bitmap in _dic) { } } } }