📄 as2htmlformat.as
字号:
class AS2HTMLFormat {
public static var ERROR : Number = 1;
public static var WARING : Number = 2;
public static var TRACE : Number = 4;
public static var INFO : Number = 3;
public static var KEY : Number = 5;
public static var SPAN : Number = 6;
public static var VALUE : Number = 7;
public static var TYPE : Number = 8;
public static var KH : Number = 9;
public static var MC:Number = 10;
public static var TAB : String = " ";
private var styles : Array = null;
public function AS2HTMLFormat() {
styles = [];
setErrorStyle();
setWaringStyle();
setTraceStyle();
setInfoStyle();
setKeyStyle();
setKhStyle();
setSpanStyle();
setValueStyle();
setTypeStyle();
setDigMCInfoStyle();
}
public function setErrorStyle(font : String,size : Number,color : String ,strong : Boolean,cls : String) : Void {
font = font==null?"Courier New":font;
size = size==null?12:size;
color = color==null?"#ff0000":color;
strong = strong==null?true:strong;
setStyle(ERROR, font, size, color, strong, cls);
}
public function setWaringStyle(font : String ,size : Number,color : String ,strong : Boolean ,cls : String) : Void {
font = font==null?"Courier New":font;
size = size==null?12:size;
color = color==null?"#FFFF00":color;
strong = strong==null?true:strong;
setStyle(WARING, font, size, color, strong, cls);
}
public function setTraceStyle(font : String ,size : Number,color : String,strong : Boolean,cls : String) : Void {
font = font==null?"Courier New":font;
size = size==null?12:size;
color = color==null?"#3366FF":color;
strong = strong==null?true:strong;
setStyle(TRACE, font, size, color, strong, cls);
}
public function setInfoStyle(font : String ,size : Number,color : String ,strong : Boolean,cls : String ) : Void {
font = font==null?"Courier New":font;
size = size==null?12:size;
color = color==null?"#666666":color;
strong = strong==null?true:strong;
setStyle(INFO, font, size, color, strong, cls);
}
public function setKeyStyle(font : String ,size : Number,color : String ,strong : Boolean ,cls : String ) : Void {
font = font==null?"Courier New":font;
size = size==null?12:size;
color = color==null?"#ffff00":color;
strong = strong==null?false:strong;
setStyle(KEY, font, size, color, strong, cls);
}
public function setSpanStyle(font : String ,size : Number,color : String ,strong : Boolean ,cls : String) : Void {
font = font==null?"Courier New":font;
size = size==null?12:size;
color = color==null?"#ff0000":color;
strong = strong==null?false:strong;
setStyle(SPAN, font, size, color, strong, cls);
}
public function setValueStyle(font : String ,size : Number,color : String ,strong : Boolean ,cls : String ) : Void {
font = font==null?"Courier New":font;
size = size==null?12:size;
color = color==null?"#99ff00":color;
strong = strong==null?false:strong;
setStyle(VALUE, font, size, color, strong, cls);
}
public function setTypeStyle(font : String ,size :Number,color : String,strong : Boolean,cls : String) : Void {
font = font==null?"Courier New":font;
size = size==null?10:size;
color = color==null?"#999999":color;
strong = strong==null?false:strong;
setStyle(TYPE, font, size, color, strong, cls);
}
public function setDigMCInfoStyle(font : String ,size :Number,color : String,strong : Boolean,cls : String) : Void {
font = font==null?"Courier New":font;
size = size==null?12:size;
color = color==null?"#70D1BB":color;
strong = strong==null?false:strong;
setStyle(MC, font, size, color, strong, cls);
}
public function setKhStyle(font : String ,size :Number,color : String ,strong : Boolean ,cls : String) : Void {
font = font==null?"Courier New":font;
size = size==null?12:size;
color = color==null?"#0000FF":color;
strong = strong==null?true:strong;
setStyle(KH, font, size, color, strong, cls);
}
public function toHTML(level : Number,o,title : String) : String {
var s : String = styles[level][0] + title + styles[level][1] + "<br/>";
s += dig(o);
return s;
}
private function dig(o ,tab : String,key : String) : String {
tab = tab==null?"":tab;
key=key==null?"":key;
var s : String = tab + (key == "" ? key : styles[KEY][0]+ key + styles[KEY][1] + styles[SPAN][0] + " -> " + styles[SPAN][1]);
var type : String = getType(o);
switch(type) {
case "Object":
s += styles[TYPE][0] + "[" + type + "]" + styles[TYPE][1] + styles[KH][0] + "{" + styles[KH][1] + "<br/>";
for(var what:String in o) {
s += dig(o[what], tab + TAB, what);
}
s += tab + styles[KH][0]+ "{" + styles[KH][1] + "<br/>";
break;
case "Array":
s += styles[TYPE][0]+ "[" + type + "]" + styles[TYPE][1] + styles[KH][0] + "{" +styles[KH][1] + "<br/>";
var len:Number = o.length;
for(var i : Number = 0;i < len;i++) {
s += dig(o[i], tab + TAB, i + "");
}
s += tab + styles[KH][0] + "{" + styles[KH][1] + "<br/>";
break;
case "MovieClip":
s += styles[VALUE][0] + o + styles[VALUE][1]+styles[TYPE][0] + "[" + type + "]" + styles[TYPE][1] + styles[KH][0] + "{" + styles[KH][1] + "<br/>";
var por:Object = {name:o._name,depth:o.getDepth(),x:o._x,y:o._y,width:o._width,height:o._height,alpha:o._alpha,visible:o._visible,enabled:o.enabled,scaleX:o._xscale,scaleY:o._yscale,rotation:o._rotation};
for(var what in por){
s+=dig(por[what],tab+TAB,what);
}
s += tab + styles[KH][0]+ "{" + styles[KH][1] + "<br/>";
//s+=styles[VALUE][0]+o+styles[VALUE][1] + styles[TYPE][0] +" {name:"+o._name+",depth:"+o.getDepth()+",x:" +o._x+",y:"+o._y+",width:"+o._width+",height:"+o._height+",alpha:"+o._alpha+",xscale:"+o._xscale+",yscale:"+o._yscale+",rotation:"+o._rotation+"} [" + type + "]" +styles[TYPE][1]+ "<br/>"
break;
default:
s += styles[VALUE][0] + o + styles[VALUE][1] + styles[TYPE][0] + "[" + type + "]" +styles[TYPE][1]+ "<br/>";
break;
}
return s;
}
public function digMC(o:MovieClip,tab:String,key:String){
tab = tab==null?"":tab;
key = key==null?"":key;
var s:String = "";
var type:String = "MovieClip";
s += tab+styles[VALUE][0] + o + styles[VALUE][1]+styles[TYPE][0] + "[" + type + "]"+ styles[TYPE][1]+styles[MC][0]+"<br/>{ name : "+o._name+", depth : "+o.getDepth()+", x : " +o._x+", y : "+o._y+", width : "+o._width+", height : "+o._height+", alpha : "+o._alpha+", visible : "+o._visible+", enabled : "+o.enabled+", xscale : "+o._xscale+", yscale : "+o._yscale+", rotation : "+o._rotation+"}"+ styles[MC][1]+"<br/>";
for(var mc in o){
if(o[mc] instanceof MovieClip){
s+=digMC(o[mc],tab+TAB,mc);
}
}
return s;
}
private function setStyle(code : Number,font : String,size : Number,color : String,strong : Boolean,cls : String) : Void {
var s : String = "<font";
if(cls != null) {
s += " class='" + cls + "'>";
}else {
s += " face='" + font + "' size='" + size + "' color='" + color + "'>";
if(strong)s+="<b>";
}
styles[code] =[s,(strong?"</b></font>":"</font>")];
}
private function getType(o):String{
if(o instanceof Array){
return "Array";
}else if(o instanceof MovieClip){
return "MovieClip";
}else if(o instanceof String){
return "String";
}else if(o instanceof Number){
return "Number";
}else if(o instanceof Boolean){
return "Boolean";
}else if(o instanceof XML){
return "XML";
}else if(o instanceof Object){
return "Object";
}else {
return typeof(o);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -