Skip to content

Commit 220ab13

Browse files
committed
批量替换旧资源
1 parent 139f64d commit 220ab13

File tree

6 files changed

+509
-40
lines changed

6 files changed

+509
-40
lines changed

ExportPictureTool/src/ActionVO.as

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package
2+
{
3+
public class ActionVO
4+
{
5+
public function ActionVO()
6+
{
7+
}
8+
9+
/**
10+
* 动作名
11+
*/
12+
public var name:String;
13+
14+
public var xml:XML;
15+
16+
/**
17+
* 方向数量
18+
*/
19+
public var directions:Array ;
20+
21+
/**
22+
* 单个方向的图片
23+
*/
24+
public var bitmapDatas:Array = [];
25+
}
26+
}

ExportPictureTool/src/DirectionVO.as

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package
2+
{
3+
import flash.display.BitmapData;
4+
5+
public class DirectionVO
6+
{
7+
public function DirectionVO()
8+
{
9+
}
10+
11+
/**
12+
* 方向
13+
*/
14+
public var dir:int = 0;
15+
16+
/**
17+
* 图片
18+
*/
19+
public var bmd:BitmapData;
20+
}
21+
}

ExportPictureTool/src/ExportPictureTool.mxml

+166-29
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
33
xmlns:s="library://ns.adobe.com/flex/spark"
44
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)">
66

77
<fx:Script>
88
<![CDATA[
@@ -22,56 +22,193 @@
2222
private var png:PNGEncoder = new PNGEncoder();
2323
private var fileStream:FileStream = new FileStream();
2424
private var _baseUrl:String = "";
25+
private var swfs:Array = [];
26+
private var currentVO:FileVO;
2527
2628
protected function browseFile(event:MouseEvent):void
2729
{
2830
// TODO Auto-generated method stub
29-
_file.browse(_fileFilter);
31+
// _file.browse(_fileFilter);
32+
_file.browseForDirectory("选择一个目录");
3033
_file.addEventListener(Event.SELECT, onSelect);
3134
}
3235
3336
private function onSelect(event:Event):void
3437
{
38+
_index = 0;
39+
swfs.length = 0;
3540
_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();
3883
}
3984
4085
private function onComplete(event:Event):void
4186
{
42-
_file.removeEventListener(Event.COMPLETE, onComplete);
87+
event.currentTarget.removeEventListener(Event.COMPLETE, onComplete);
4388
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);
5195
}
5296
5397
private function loadSwfComplete(event:Event):void
5498
{
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)
60140
{
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++)
68145
{
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));
70206
}
71207
}
72-
list.dataProvider = new ArrayCollection(_listData);
208+
return dirs;
73209
}
74210
211+
75212
/** */
76213
private function setColor(bitmap:BitmapData, data:ByteArray, w:int, h:int, type:int):void
77214
{
@@ -166,7 +303,7 @@
166303
tips.y = (stage.stageHeight - tips.height) * 0.5;
167304
}
168305
169-
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
306+
protected function windowedapplication1_creationCompleteHandler(event:Event):void
170307
{
171308
// TODO Auto-generated method stub
172309
maskShape_resizeHandler(null);
@@ -178,7 +315,7 @@
178315
<fx:Declarations>
179316
<!-- Place non-visual elements (e.g., services, value objects) here -->
180317
</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)"/>
182319
<s:Group x="21" y="85" width="611" height="525">
183320
<mx:TileList x="10" y="10" width="579" height="505" itemRenderer="PictureItem" id="list" selectable="false" columnWidth="110" rowHeight="128">
184321
</mx:TileList>
@@ -187,6 +324,6 @@
187324
<s:Button x="98" y="59" label="全取消" click="selectAll(false)"/>
188325
<s:Button x="220" y="59" label="导出" click="export(event)"/>
189326
<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"/>
191328
</s:Group>
192329
</s:WindowedApplication>

ExportPictureTool/src/FileVO.as

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package
2+
{
3+
import flash.filesystem.File;
4+
5+
public class FileVO
6+
{
7+
public function FileVO()
8+
{
9+
}
10+
11+
public var f:File;
12+
13+
public var classes:Array;
14+
15+
public var xml:XML;
16+
17+
/**
18+
* 资源名
19+
*/
20+
public var name:String;
21+
22+
/**
23+
*动作系列
24+
*/
25+
public var actions:Array = [];
26+
27+
public var actionStr:String = "";
28+
29+
30+
}
31+
}

0 commit comments

Comments
 (0)