当前位置:   article > 正文

使用JSFL自动生成元件AS3代码声明和赋值语句_fl.getdocumentdom() 将图层中的帧依次转为元件

fl.getdocumentdom() 将图层中的帧依次转为元件

http://www.daylyn.org/post/101.html

  1. var selectedItems = fl.getDocumentDOM().selection; //获取文档所选对象数组
  2. var resultDesc = ""; //结果声明语句部分
  3. var resultAssignment = ""; //结果赋值语句部分
  4. var libitem; //库元件
  5. //循环选中的库元件
  6. var selItems = fl.getDocumentDOM().library.getSelectedItems();
  7. var childItem = selItems[0];
  8. fl.outputPanel.trace(childItem.name);
  9. fl.outputPanel.trace(childItem.linkageExportForAS); //linkageBaseClass.toString().split(".").pop());
  10. fl.outputPanel.trace(childItem.linkageClassName);
  11. fl.outputPanel.trace(childItem.linkageBaseClass); //默认基类 则是空串
  12. resultDesc = "private var _ui:" + "Sprite";
  13. for(var i = 0 ; i < selectedItems.length; i ++)
  14. {
  15. var item = selectedItems[i];
  16. if(item.libraryItem)
  17. {
  18. libitem = item.libraryItem;
  19. if(isComponent(libitem.name))
  20. {
  21. resultDesc += "private var _"+item.name+":"+getClassOfComponent(item.libraryItem.name)+";\n";
  22. //resultAssignment += "_" + item.name + " = " + "_ui[" + item.name + "]"; //也可以用getChildByName方法
  23. }
  24. else if(libitem.linkageBaseClass)
  25. {
  26. resultDesc += "private var _"+item.name+":"+(libitem.linkageBaseClass.toString().split(".").pop())+";\n";
  27. //resultAssignment += "_" + item.name + " = " + "_ui[" + item.name + "]";
  28. }
  29. else if(item.name)
  30. {
  31. resultDesc += "private var _"+item.name+":MovieClip;\n";
  32. //resultAssignment += "_" + item.name + " = " + "_ui[" + item.name + "]";
  33. }
  34. resultAssignment += "_" + item.name + " = " + "_ui[\"" + item.name + "\"]" + ";\n";
  35. }
  36. else if(item.elementType == "text"&&item.name)
  37. {
  38. resultDesc += "private var _"+item.name+":TextField;\n";
  39. resultAssignment += "_" + item.name + " = " + "_ui[\"" + item.name + "\"]" + ";\n";
  40. }
  41. }
  42. /*
  43. 是否为组件
  44. */
  45. function isComponent(libItemName)
  46. {
  47. fl.outputPanel.trace(libItemName);
  48. return libItemName.match(/Components\//i);
  49. }
  50. /*
  51. 获取组件类名
  52. */
  53. function getClassOfComponent(libItemName)
  54. {
  55. return libItemName.match(/Components\/([a-zA-Z0-9_-]*)/i)[1];
  56. }
  57. fl.outputPanel.trace(resultDesc); //打印结果
  58. fl.outputPanel.trace(resultAssignment);



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/399863
推荐阅读
相关标签
  

闽ICP备14008679号