|
2 | 2 | <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
|
3 | 3 | xmlns:s="library://ns.adobe.com/flex/spark"
|
4 | 4 | xmlns:mx="library://ns.adobe.com/flex/mx"
|
5 |
| - width="654" height="700" creationComplete="windowedapplication1_creationCompleteHandler(event)"> |
| 5 | + width="654" height="700" addedToStage="windowedapplication1_creationCompleteHandler(event)"> |
6 | 6 |
|
7 | 7 | <fx:Script>
|
8 | 8 | <![CDATA[
|
|
22 | 22 | private var png:PNGEncoder = new PNGEncoder();
|
23 | 23 | private var fileStream:FileStream = new FileStream();
|
24 | 24 | private var _baseUrl:String = "";
|
| 25 | + private var swfs:Array = []; |
| 26 | + private var currentVO:FileVO; |
25 | 27 |
|
26 | 28 | protected function browseFile(event:MouseEvent):void
|
27 | 29 | {
|
28 | 30 | // TODO Auto-generated method stub
|
29 |
| - _file.browse(_fileFilter); |
| 31 | +// _file.browse(_fileFilter); |
| 32 | + _file.browseForDirectory("选择一个目录"); |
30 | 33 | _file.addEventListener(Event.SELECT, onSelect);
|
31 | 34 | }
|
32 | 35 |
|
33 | 36 | private function onSelect(event:Event):void
|
34 | 37 | {
|
| 38 | + _index = 0; |
| 39 | + swfs.length = 0; |
35 | 40 | _file.removeEventListener(Event.SELECT, onSelect);
|
36 |
| - _file.load(); |
37 |
| - _file.addEventListener(Event.COMPLETE, onComplete); |
| 41 | + createFiles(_file); |
| 42 | +// _file.load(); |
| 43 | +// _file.addEventListener(Event.COMPLETE, onComplete); |
| 44 | + if (swfs.length < 1) |
| 45 | + { |
| 46 | + Alert.show("目录下面没有swf文件"); |
| 47 | + return; |
| 48 | + } |
| 49 | + maskShape.visible = true; |
| 50 | + tips.text = "正在处理第"+(_index+1)+"/"+swfs.length+"个文件:"+swfs[_index].f.name; |
| 51 | + callLater(makeNewSwf); |
| 52 | + } |
| 53 | + |
| 54 | + private function createFiles(file:File):void |
| 55 | + { |
| 56 | + var files:Array = file.getDirectoryListing(); |
| 57 | + var f:File, vo:FileVO; |
| 58 | + for each (f in files) |
| 59 | + { |
| 60 | + if (f.isDirectory) |
| 61 | + { |
| 62 | + createFiles(f); |
| 63 | + }else if (f.extension.toLocaleLowerCase() == "swf") |
| 64 | + { |
| 65 | + vo = new FileVO(); |
| 66 | + vo.f = f; |
| 67 | + swfs.push(vo); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + private function makeNewSwf():void |
| 73 | + { |
| 74 | + if (swfs.length <= _index) |
| 75 | + { |
| 76 | + Alert.show("操作完毕"); |
| 77 | + maskShape.visible = false; |
| 78 | + return; |
| 79 | + } |
| 80 | + currentVO = swfs[_index]; |
| 81 | + currentVO.f.addEventListener(Event.COMPLETE, onComplete); |
| 82 | + currentVO.f.load(); |
38 | 83 | }
|
39 | 84 |
|
40 | 85 | private function onComplete(event:Event):void
|
41 | 86 | {
|
42 |
| - _file.removeEventListener(Event.COMPLETE, onComplete); |
| 87 | + event.currentTarget.removeEventListener(Event.COMPLETE, onComplete); |
43 | 88 | var byte:ByteArray = new ByteArray();
|
44 |
| - _file.data.readBytes(byte); |
45 |
| - _classDic = GetSwfAllPicture.getSWFImages(byte); |
46 |
| -// _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadSwfComplete); |
47 |
| -// _loaderContext = new LoaderContext(); |
48 |
| -// _loaderContext.allowCodeImport = true; |
49 |
| -// _loader.loadBytes(_file.data, _loaderContext); |
50 |
| - loadSwfComplete(null); |
| 89 | + currentVO.f.data.readBytes(byte); |
| 90 | +// currentVO.classes = SWFClassHelper.getSWFClasses(byte); |
| 91 | + _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadSwfComplete); |
| 92 | + _loaderContext = new LoaderContext(); |
| 93 | + _loaderContext.allowCodeImport = true; |
| 94 | + _loader.loadBytes(currentVO.f.data, _loaderContext); |
51 | 95 | }
|
52 | 96 |
|
53 | 97 | private function loadSwfComplete(event:Event):void
|
54 | 98 | {
|
55 |
| -// _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadSwfComplete); |
56 |
| - _listData.length = 0; |
57 |
| - var len:int = _classDic.length, i:int = 0, tempBitmap:BitmapData, tempIns:*; |
58 |
| - var trans:Boolean; |
59 |
| - for (;i<len;i++) |
| 99 | + _index++; |
| 100 | + _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadSwfComplete); |
| 101 | + var mainName:String = currentVO.f.name; |
| 102 | + currentVO.name = mainName = mainName.substring(0,mainName.lastIndexOf(".")); |
| 103 | + var cl:Class = _loader.contentLoaderInfo.applicationDomain.getDefinition(mainName) as Class; |
| 104 | + if (cl) |
| 105 | + { |
| 106 | + currentVO.xml = cl.X_M_L as XML; |
| 107 | + var ss:XMLList = currentVO.xml.s; |
| 108 | + var action:XML, avo:ActionVO; |
| 109 | + for each (action in ss) |
| 110 | + { |
| 111 | + avo = new ActionVO(); |
| 112 | + avo.name = action.@k; |
| 113 | + avo.xml = action; |
| 114 | + avo.directions = getDirections(action); |
| 115 | + currentVO.actions.push(avo); |
| 116 | + currentVO.actionStr += ("'"+avo.name+"'"+","); |
| 117 | + } |
| 118 | + if (currentVO.actionStr.length > 0) |
| 119 | + currentVO.actionStr = currentVO.actionStr.substr(0,currentVO.actionStr.length-1); |
| 120 | + } |
| 121 | + if (currentVO.actions.length > 0){ |
| 122 | + callLater(createActionsFile); |
| 123 | + }else{ |
| 124 | + if (swfs.length > _index) |
| 125 | + tips.text = "正在处理第"+(_index+1)+"/"+swfs.length+"个文件:"+swfs[_index].f.name; |
| 126 | + callLater(makeNewSwf); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + private function createActionsFile():void |
| 131 | + { |
| 132 | + var avo:ActionVO = currentVO.actions.shift(); |
| 133 | + var saveF:File = File.desktopDirectory; |
| 134 | + saveF = saveF.resolvePath("outcome2"); |
| 135 | + var bmd:BitmapData, dvo:DirectionVO; |
| 136 | + var i:int = 0, len:int, h:Number, dbmd:BitmapData; |
| 137 | + var actName:String = currentVO.name + "." + avo.name;; |
| 138 | + var cl:Class = _loader.contentLoaderInfo.applicationDomain.getDefinition(actName) as Class; |
| 139 | + if (cl) |
60 | 140 | {
|
61 |
| - if (_classDic[i].type == 36) |
62 |
| - trans = true; |
63 |
| - else |
64 |
| - trans = false; |
65 |
| - tempBitmap = new BitmapData(_classDic[i].width, _classDic[i].height, trans, 0x000000); |
66 |
| - setColor(tempBitmap, _classDic[i].data, _classDic[i].width, _classDic[i].height, _classDic[i].type); |
67 |
| - if (tempBitmap != null) |
| 141 | + bmd = new cl() as BitmapData; |
| 142 | + len = avo.directions.length; |
| 143 | + h = bmd.height / len; |
| 144 | + for (i=0;i<len;i++) |
68 | 145 | {
|
69 |
| - _listData.push(new ItemVO(tempBitmap, true, _classDic[i].type)); |
| 146 | + dbmd = new BitmapData(bmd.width, h,true,0); |
| 147 | + dbmd.copyPixels(bmd,new Rectangle(0,h*i,bmd.width,h),new Point()); |
| 148 | + dvo = new DirectionVO(); |
| 149 | + dvo.dir = avo.directions[i]; |
| 150 | + dvo.bmd = dbmd; |
| 151 | + avo.bitmapDatas.push(dvo); |
| 152 | + fileStream.open(new File(saveF.url+"/"+currentVO.name+"/"+avo.name+"/"+avo.name+dvo.dir+".png"),FileMode.WRITE); |
| 153 | + fileStream.writeBytes(png.encode(dbmd)); |
| 154 | + fileStream.close(); |
| 155 | + } |
| 156 | + var str:String = 'package ' + this.currentVO.name + |
| 157 | + '\n{'+ |
| 158 | + '\n import flash.display.MovieClip;'+ |
| 159 | + '\n import flash.system.Security;'+ |
| 160 | + '\n'+ |
| 161 | + '\n public class '+ avo.name +' extends MovieClip'+ |
| 162 | + '\n {'+ |
| 163 | + '\n public static const STATUS_LIST:Array = ['+currentVO.actionStr+'];'+ |
| 164 | + '\n public static const X_M_L:XML = '+avo.xml+';'+ |
| 165 | + '\n public function '+ avo.name +'()'+ |
| 166 | + '\n {'+ |
| 167 | + '\n addFrameScript(0, frame1);'+ |
| 168 | + '\n return;'+ |
| 169 | + '\n }'+ |
| 170 | + '\n'+ |
| 171 | + '\n function frame1()'+ |
| 172 | + '\n {'+ |
| 173 | + '\n try'+ |
| 174 | + '\n {'+ |
| 175 | + '\n Security.allowDomain("*");'+ |
| 176 | + '\n }'+ |
| 177 | + '\n catch (e:Error)'+ |
| 178 | + '\n {'+ |
| 179 | + '\n }'+ |
| 180 | + '\n return;'+ |
| 181 | + '\n }'+ |
| 182 | + '\n }'+ |
| 183 | + '\n}' ; |
| 184 | + fileStream.open(new File(saveF.url+"/"+currentVO.name+"/"+avo.name+".as"),FileMode.WRITE); |
| 185 | + fileStream.writeUTFBytes(str); |
| 186 | + fileStream.close(); |
| 187 | + } |
| 188 | + if (currentVO.actions.length > 0){ |
| 189 | + callLater(createActionsFile); |
| 190 | + }else{ |
| 191 | + if (swfs.length > _index) |
| 192 | + tips.text = "正在处理第"+(_index+1)+"/"+swfs.length+"个文件:"+swfs[_index].f.name; |
| 193 | + callLater(makeNewSwf); |
| 194 | + } |
| 195 | + } |
| 196 | + |
| 197 | + private function getDirections(xml:XML):Array |
| 198 | + { |
| 199 | + var ps:XMLList = xml.p, p:XML; |
| 200 | + var dirs:Array = []; |
| 201 | + for each (p in ps) |
| 202 | + { |
| 203 | + if (dirs.indexOf(int(p.@a)) < 0) |
| 204 | + { |
| 205 | + dirs.push(int(p.@a)); |
70 | 206 | }
|
71 | 207 | }
|
72 |
| - list.dataProvider = new ArrayCollection(_listData); |
| 208 | + return dirs; |
73 | 209 | }
|
74 | 210 |
|
| 211 | + |
75 | 212 | /** */
|
76 | 213 | private function setColor(bitmap:BitmapData, data:ByteArray, w:int, h:int, type:int):void
|
77 | 214 | {
|
|
166 | 303 | tips.y = (stage.stageHeight - tips.height) * 0.5;
|
167 | 304 | }
|
168 | 305 |
|
169 |
| - protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void |
| 306 | + protected function windowedapplication1_creationCompleteHandler(event:Event):void |
170 | 307 | {
|
171 | 308 | // TODO Auto-generated method stub
|
172 | 309 | maskShape_resizeHandler(null);
|
|
178 | 315 | <fx:Declarations>
|
179 | 316 | <!-- Place non-visual elements (e.g., services, value objects) here -->
|
180 | 317 | </fx:Declarations>
|
181 |
| - <s:Button x="21" y="20" label="浏览" toolTip="打开一个swf文件" click="browseFile(event)"/> |
| 318 | + <s:Button x="21" y="20" label="浏览" toolTip="打开swf文件目录" click="browseFile(event)"/> |
182 | 319 | <s:Group x="21" y="85" width="611" height="525">
|
183 | 320 | <mx:TileList x="10" y="10" width="579" height="505" itemRenderer="PictureItem" id="list" selectable="false" columnWidth="110" rowHeight="128">
|
184 | 321 | </mx:TileList>
|
|
187 | 324 | <s:Button x="98" y="59" label="全取消" click="selectAll(false)"/>
|
188 | 325 | <s:Button x="220" y="59" label="导出" click="export(event)"/>
|
189 | 326 | <s:Group width="100%" height="100%" id="maskShape" visible="false" resize="maskShape_resizeHandler(event)">
|
190 |
| - <s:Label text="保存中......" id="tips" width="60"/> |
| 327 | + <s:Label text="保存中......" id="tips" width="120"/> |
191 | 328 | </s:Group>
|
192 | 329 | </s:WindowedApplication>
|
0 commit comments