假日咖啡的博客

HolidayCoffee's Blog

Photosho cs5 面板插件开发笔记04

面板插件开发笔记04

一个写在文件最后的构造函数,居然是影响SWF与jsx通信的关键!看英文开发文档真是作孽啊,一直以为convertToXML()是系统自带的函数,没想到是人工写上去的,难怪官方API没这个函数!!

mxml文件端内嵌actionscript3.0代码:

   public function call03():void{
				var reqResult:SyncRequestResult = CSXSInterface.instance.evalScript("Communicate05");
				if(SyncRequestResult.COMPLETE == reqResult.status){
					box.text = reqResult.data.layerName;  /*p1*/
				}else{
				box.text="miss";
				}
         }

jsx文件端,XML对象关键构造代码(官方开发案例代码中被我一直以为是系统自带函数的那段):

function convertToXML(property, identifier){
	var type = typeof property;
	var xml = '<property id = "' + identifier + '" >';
	
	switch(type){
		case "number":
			xml += "<number>";
			xml += property.toString();
			xml += "</number>";
			break;
		case "boolean":
			xml += "<" + property.toString() + "/>";
			break;
		case "string":
			xml += "<string>";
			xml += property.toString();
			xml += "</string>";
			break;
		case "object":
			// Object case is currently not supported
			alert("Object case is currently not supported");
			//xml += "<object>";
			//for(var i in property)
			//	xml += convertToXML(property[i], 
			//xml += "</object>";
			break;
		case "undefined":
			xml += "<string>undefined</string>";
			break;
		default:
			alert("Type " + type + " is unknown.");
			return "";
	}
	xml += '</property>';
	return xml;
}


jsx调用上面的函数与SWF进行数据对接的例子:

function Communicate05(){
   
	var xml = "<object>";
	xml += convertToXML("pass", "layerName");
   xml += "</object>";
   return xml;
}