赞
踩
http://www.daylyn.org/post/101.html
- var selectedItems = fl.getDocumentDOM().selection; //获取文档所选对象数组
- var resultDesc = ""; //结果声明语句部分
- var resultAssignment = ""; //结果赋值语句部分
- var libitem; //库元件
-
- //循环选中的库元件
- var selItems = fl.getDocumentDOM().library.getSelectedItems();
- var childItem = selItems[0];
- fl.outputPanel.trace(childItem.name);
- fl.outputPanel.trace(childItem.linkageExportForAS); //linkageBaseClass.toString().split(".").pop());
- fl.outputPanel.trace(childItem.linkageClassName);
- fl.outputPanel.trace(childItem.linkageBaseClass); //默认基类 则是空串
- resultDesc = "private var _ui:" + "Sprite";
-
- for(var i = 0 ; i < selectedItems.length; i ++)
- {
- var item = selectedItems[i];
-
- if(item.libraryItem)
- {
- libitem = item.libraryItem;
- if(isComponent(libitem.name))
- {
- resultDesc += "private var _"+item.name+":"+getClassOfComponent(item.libraryItem.name)+";\n";
- //resultAssignment += "_" + item.name + " = " + "_ui[" + item.name + "]"; //也可以用getChildByName方法
-
- }
- else if(libitem.linkageBaseClass)
- {
- resultDesc += "private var _"+item.name+":"+(libitem.linkageBaseClass.toString().split(".").pop())+";\n";
- //resultAssignment += "_" + item.name + " = " + "_ui[" + item.name + "]";
- }
- else if(item.name)
- {
- resultDesc += "private var _"+item.name+":MovieClip;\n";
- //resultAssignment += "_" + item.name + " = " + "_ui[" + item.name + "]";
- }
- resultAssignment += "_" + item.name + " = " + "_ui[\"" + item.name + "\"]" + ";\n";
-
- }
- else if(item.elementType == "text"&&item.name)
- {
- resultDesc += "private var _"+item.name+":TextField;\n";
- resultAssignment += "_" + item.name + " = " + "_ui[\"" + item.name + "\"]" + ";\n";
- }
-
-
- }
- /*
- 是否为组件
- */
- function isComponent(libItemName)
- {
- fl.outputPanel.trace(libItemName);
- return libItemName.match(/Components\//i);
- }
- /*
- 获取组件类名
- */
- function getClassOfComponent(libItemName)
- {
- return libItemName.match(/Components\/([a-zA-Z0-9_-]*)/i)[1];
- }
- fl.outputPanel.trace(resultDesc); //打印结果
- fl.outputPanel.trace(resultAssignment);
-
-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。