月度存档: 11 月 2013

As3生成photoshop扩展程序

神一样的xx公司要求把一堆psd文件转成jpg文件,而且要求转出的图片高清,我本来想把psd批量导入flash,然后用air保存,但是清晰度没有用photoshop直接导出的图像高,所以,只好写个ps扩展了,查了下有个同道已经探索过了,链接地址:http://blog.csdn.net/hero82748274/article/details/8749158
运行方式上推荐adobe官方的教程 Running the Hello World Extension,简单点说就是
1.在extnsion build项目名称上右键,选择run as ->adobe photoshop extension,然后会打开本机的photoshop程序自动安装扩展了
2.安装好的扩展程序在 视窗->扩展程序下->你的项目名称,打开即可
as3:http://cssdk.s3-website-us-east-1.amazonaws.com/sdk/1.0/docs/WebHelp/references/csawlib/com/adobe/photoshop/package-detail.html
js:http://cssdk.s3-website-us-east-1.amazonaws.com/sdk/1.0/docs/WebHelp/app_notes/ps_scripting.htm

flashdevelop_as3帮助文档设置

在FD4中设置 Tools—>Settings—>AS3Context—>Documentation Command Line为
http://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/$(ItmTypPkgNamePath).html
按下f1可以完全访问到官方的最新帮助去,可以随时保持API最新。

TextField的文字混排

[code]
var style3:StyleSheet = new StyleSheet();
var heading1:Object = {“color”:”#ff0000″,”fontWeight”:”bold”,”fontFamily”:”microsoft yahei”,”fontSize”:”20″};
var heading2:Object = {“color”:”#000000″,”fontWeight”:”bold”,”fontFamily”:”microsoft yahei”,”fontSize”:”35″};
var heading3:Object = {“color”:”#000000″,”fontWeight”:”bold”,”fontFamily”:”microsoft yahei”,”fontSize”:”20″};
var body:Object = new Object();
body.textAlign = “center”;
style3.setStyle(“.heading1”, heading1);
style3.setStyle(“.heading2”, heading2);
style3.setStyle(“.heading3”, heading3);
style3.setStyle(“body”, body);
t3.styleSheet = style3;
t3.htmlText = “198/起“;
var style2:StyleSheet = new StyleSheet();
var heading5:Object = {“color”:”#000000″,”fontWeight”:”bold”,”fontFamily”:”microsoft yahei”,”fontSize”:”25″};
t2.styleSheet = style2;
style2.setStyle(“.heading5”, heading5);
style2.setStyle(“body”, body);
t2.htmlText = “天天低价
四星酒店“;
[/code]

解析头文件获取加载进来的swf的舞台宽高

[code]
var urlloader:URLLoader=new URLLoader();
urlloader.dataFormat = URLLoaderDataFormat.BINARY;
 urlloader.addEventListener(Event.COMPLETE,swf_loaded);
urlloader.load(new URLRequest(“file.swf”));
function swf_loaded(e:Event):void
                {
                        swfInfo = new swfHanderInfo(ByteArray(urlloader.data));
                        trace(“宽度:”+swfInfo.width+”\n高度:”+swfInfo.height);
//ExternalInterface.call(“getwh”,swfInfo.width,swfInfo.height);
                        loader.loadBytes(urlloader.data);
                }
[/code]
引用类:swfHanderInfo.as
[code]
package {
import flash.utils.*;
import flash.errors.IOError;
public class swfHanderInfo {
protected var w_h_ruleList:Array;
protected var _type:String;//标识
protected var _version:uint;//版本
protected var _size:uint;//文件大小
protected var _width:uint;//场景宽
protected var _height:uint;//场景高
protected var _fps:uint;//桢频
protected var _frames:uint;//场景上的桢数
public function swfHanderInfo(BA:ByteArray) {
setWHruleList();
parseByteArray(BA);
}

protected function parseByteArray(BA:ByteArray):void {
var binary:ByteArray=new ByteArray;
binary.endian=Endian.LITTLE_ENDIAN;
BA.readBytes(binary,0,8);//取前8个字节,包括了是否是swf,版本号,文件大小
_type=binary.readUTFBytes(3);//前3个字节是SWF文件头标志,FWS表示未压缩,CWS表示压缩的SWF文件
_version=binary[3];//第4个字节为版本号
_size=binary[7]<<24|binary[6]<<16|binary[5]<<8|binary[4];//文件大小按照8765字节的顺序排列的16进制 //trace(_size,":size"); //trace(_version,":version"); binary.position=8;//移到第9个字节位置,从这里开始就是swf 的控制码区和宽高数据区,宽高最多占用9个字节 var mainData:ByteArray=new ByteArray; BA.readBytes(mainData); if (_type == "CWS") {//未压缩的swf标识是FWS,压缩过的swf标识是CWS mainData.uncompress();//从第9个字节起用解压缩 } else if (_type != "FWS") { //trace("..."+_type+"...") throw new IOError("出错:不是swf文件!"); }//不是cws,也不是fws,表示不是swf文件,抛出错误! trace("test:", mainData.uncompress()); binary.writeBytes(mainData,0,13);//再写13个字节,这里包括了swf的桢速/桢数 //当前第8个字节位为控制码 var ctrlCode:String=binary[8].toString(16); trace(ctrlCode,":ctrlCode"); var w_h_plist:Array=getW_H_RulePosition(w_h_ruleList,ctrlCode); var len=w_h_plist[2]; //trace("宽高占用"+len+"个字节"); var s:String="";//存储宽高数据的相关字节码 for (var i=0; i < len; i++) { var _temp=binary[i + 9].toString(16); trace("_temp:",_temp); if (_temp.length ==1) { _temp="0" + _temp; } s+= _temp; } //trace(s); _width=new Number("0x" + s.substr(w_h_plist[0][0],4)) / w_h_plist[0][1]; _height=new Number("0x" + s.substr(w_h_plist[1][0],4)) / w_h_plist[1][1];//相应取值得到宽高 //trace(s,w_h_plist[0][0],s.substr(w_h_plist[0][0],4)); //trace(width,":width"); // trace(height,":height"); var pos=8+len; _fps=binary[pos+=2];//宽高数据区完跳一字节位置就是fps值 //trace(_fps,":fps"); _frames=binary[pos+2]<<8|binary[pos+1];//桢数占两个字节,由低位到高位组成,是不是说时间轴的最大桢数就为65535? //trace(_frames,":frames"); } protected function setWHruleList():void {//存储宽高的数据 w_h_ruleList=[]; w_h_ruleList[0]={ctrlCode:"50",position:[[0,10],[5,10],5]}; w_h_ruleList[1]={ctrlCode:"58",position:[[1,40],[6,10],6]}; w_h_ruleList[2]={ctrlCode:"60",position:[[1,10],[7,10],6]}; w_h_ruleList[3]={ctrlCode:"68",position:[[2,40],[8,10],7]}; w_h_ruleList[4]={ctrlCode:"70",position:[[2,10],[9,10],7]}; w_h_ruleList[5]={ctrlCode:"78",position:[[3,40],[10,10],8]}; w_h_ruleList[6]={ctrlCode:"80",position:[[3,10],[11,10],8]}; w_h_ruleList[7]={ctrlCode:"88",position:[[2,40],[12,10],9]}; } protected function getW_H_RulePosition(list:Array,str:String):Array { for (var i in list) { if (list[i].ctrlCode == str) { break; } } return list[i].position; } /** * Public methods */ public function toString():String { return "[type:" + _type + ",version:" + _version + ",size:" + _size + ",width:" + _width + ",height:" + _height + ",fps:" + _fps + ",frames:" + _frames + "]"; } /** * Public get methods */ public function get type():String { return _type; } public function get version():uint { return _version; } public function get size():uint { return _size; } public function get width():uint { return _width; } public function get height():uint { return _height; } public function get fps():uint { return _fps; } public function get frames():uint { return _frames; } } } [/code]

As3截图

[code]
var fileRef:FileReference=new FileReference();//用于保存文件
var _encoder:JPGEncoder=new JPGEncoder(80);//用于编码位图
var bitmapData:BitmapData=new BitmapData(ww,hh);
bitmapData.draw(mc);//得到位图
var Data:ByteArray=_encoder.encode(bitmapData);//二进制数据
fileRef.save(Data,defaultFileName);
[/code]
~~~~~~~
搞个函数封装下,hoho
[code]
import com.adobe.images.JPGEncoder;
import com.adobe.images.PNGEncoder;
function saveImg():void {
var saveFile:FileReference = new FileReference();
saveFile.save(image_binary(), “1.png” );
}

function image_binary() : ByteArray {
//tr.ace(‘Saving image :: image_binary()’);

var pngSource:BitmapData = new BitmapData(this.width, this.height);
pngSource.draw(this);

//var jpge:JPGEncoder = new JPGEncoder(100);
//return jpge.encode(pngSource);
return PNGEncoder.encode(pngSource);
}
[/code]

DataGrid样式设置

[code]
package {
//格子渲染
import fl.controls.listClasses.CellRenderer;
import fl.controls.listClasses.ICellRenderer;
import flash.text.TextFormat;
import flash.display.Sprite;

public class CellStyle1 extends CellRenderer implements ICellRenderer {

public function CellStyle1():void {
super();
}

override protected function drawBackground():void {
var format:TextFormat = new TextFormat();
switch (data.status) {
case “OK” :
format.color=0xFFFFFF;
format.size=12;
//format.align = “center”;
//其他属性自己设;
setStyle(“textFormat”,format);
break;
case “DANGER” :
format.color=0xFF0000;
format.size=12;
//format.align = “center”;
//其他属性自己设;
setStyle(“textFormat”,format);
break;
case “WARNING”:
format.color=0xFFFF00;
format.size=12;
// format.align = “center”;
setStyle(“textFormat”,format);
break;
default :
break;
}

var cLine2:Sprite = new Sprite();
cLine2.graphics.beginFill(0x000000);
cLine2.graphics.drawRect(0, 0, 100, 100);
setStyle(“upSkin”, cLine2);

super.drawBackground();
}
}
}
[/code]
~~~~~~~~~~~~~~~~~~~~
[code]
package {
//标题渲染
import fl.controls.dataGridClasses.HeaderRenderer;
import flash.text.TextFormat;
import flash.display.Sprite;
public class DatagridHeaderStyle extends HeaderRenderer {

public function DatagridHeaderStyle():void {
super();
}

override protected function drawBackground():void {
var format:TextFormat = new TextFormat();
format.font = “Arial”;//字体为宋体
format.bold = true;//加粗
format.size = 12;//大小为12
format.color = 0xffffff;//颜色
setStyle(“textFormat”,format);

var cLine2:Sprite = new Sprite();
cLine2.graphics.beginFill(0x333333);
cLine2.graphics.drawRect(0, 0, 100, 100);
setStyle(“upSkin”, cLine2);

super.drawBackground();
}
}
}
[/code]

使用:
[code]
dp.dataProvider = new DataProvider(“数据array”);

dp.setStyle(“cellRenderer”, CellStyle1);

dp.setStyle(“headerRenderer”, DatagridHeaderStyle);

dp.setSize(512,dp.rowHeight*dp.rowCount+5);
[/code]