PageRenderTime 2156ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tool/libraryItemInspector/LibraryItemInspector.as

http://tcodes.googlecode.com/
ActionScript | 370 lines | 272 code | 51 blank | 47 comment | 49 complexity | cd8395133f4abfa7c833a50ae533c43f MD5 | raw file
  1. package {
  2. import flash.display.Shape;
  3. import flash.text.TextField;
  4. import flash.text.TextFormat;
  5. import flash.ui.Mouse;
  6. import fl.managers.StyleManager;
  7. import flash.events.MouseEvent;
  8. import adobe.utils.MMExecute;
  9. import fl.controls.Button;
  10. import fl.controls.CheckBox;
  11. import fl.controls.ComboBox;
  12. import fl.controls.TextInput;
  13. import flash.display.Sprite;
  14. import flash.events.Event;
  15. import flash.external.ExternalInterface;
  16. import flash.utils.describeType;
  17. /**
  18. * TODO:?????????????.
  19. * @author tamt
  20. */
  21. public class LibraryItemInspector extends Sprite {
  22. //????
  23. public var confirm_btn : Button;
  24. //????
  25. public var cancel_btn:Button;
  26. //????
  27. public var apply_btn:Button;
  28. //??
  29. public var name_tf : TextInput;
  30. //??combobox
  31. public var type_cb : ComboBox;
  32. //9???
  33. public var scale9grid_cb : CheckBox;
  34. //??AS
  35. public var exportAS_cb : CheckBox;
  36. //???????.
  37. public var exportAt1Frame_cb : CheckBox;
  38. //??
  39. public var className_tf:TextInput;
  40. //???
  41. public var baseClassName_tf:TextInput;
  42. //??
  43. public var findit_btn:Button;
  44. //???????LibraryItem
  45. private var item:LibraryItem;
  46. //
  47. public var debug_tf:TextField;
  48. public function LibraryItemInspector() {
  49. super();
  50. addEventListener(Event.ADDED_TO_STAGE, onAdded);
  51. //?jsfl?????
  52. ExternalInterface.addCallback('showLibrayItemInfo', showLibrayItemInfo);
  53. ExternalInterface.addCallback('disablePanel', disablePanel);
  54. }
  55. private function onChangeType(evt:Event):void {
  56. item.symbolType = ['movie clip', 'button', 'graphic'][type_cb.selectedIndex];
  57. this.updateView();
  58. }
  59. private function onChangeExportAS(evt:Event):void {
  60. item.linkageExportForAS = exportAS_cb.selected;
  61. if (item.linkageExportForAS) {
  62. if (item.linkageClassName == 'undefined') {
  63. item.linkageClassName = item.name;
  64. }
  65. if (item.linkageBaseClass == 'undefined') {
  66. item.linkageBaseClass = LibraryItem.getBaseClassNameByType(item.symbolType);;
  67. }
  68. item.linkageExportInFirstFrame = true;
  69. }
  70. this.updateView();
  71. }
  72. private function initJSFL():String {
  73. var xml:XML = <jsfl>
  74. <![CDATA[
  75. var panelName = 'Library Item Inspector';
  76. function showLibrayItemInfo(arg)
  77. {
  78. if(fl.swfPanels.length > 0){
  79. for(x = 0; x < fl.swfPanels.length; x++){
  80. // look for a SWF panel of the specified name, then call the specified AS3 function
  81. // in this example, the panel is named "test" and the AS3 callback is "callMySWF"
  82. if(fl.swfPanels[x].name == panelName) // name busted?
  83. {
  84. fl.swfPanels[x].call("showLibrayItemInfo",arg);
  85. break;
  86. }
  87. }
  88. }
  89. }
  90. /**
  91. * ?Inspector panel????????
  92. */
  93. function disablePanel() {
  94. if(fl.swfPanels.length > 0){
  95. for(x = 0; x < fl.swfPanels.length; x++){
  96. if(fl.swfPanels[x].name == panelName) // name busted?
  97. {
  98. fl.swfPanels[x].call("disablePanel");
  99. break;
  100. }
  101. }
  102. }
  103. }
  104. var item;
  105. if(fl.getDocumentDOM().selection.length>0){
  106. var ele = fl.getDocumentDOM().selection[0];
  107. if (ele.libraryItem) {
  108. inspectSelection(ele.libraryItem);
  109. }else {
  110. disablePanel();
  111. }
  112. }else {
  113. disablePanel();
  114. }
  115. function inspectSelection(libraryItem){
  116. item = libraryItem;
  117. var name = item.name.substring(item.name.lastIndexOf('/') + 1, item.name.length);
  118. var arg = '';
  119. for(var prop in item){
  120. arg += prop + ':' + item[prop] + '|';
  121. }
  122. showLibrayItemInfo(arg);
  123. }
  124. fl.addEventListener("mouseMove", onMouseMove);
  125. function onMouseMove(){
  126. var ele = fl.getDocumentDOM().selection[0];
  127. if(ele.libraryItem){
  128. if(ele.libraryItem.name != item.name)inspectSelection(ele.libraryItem);
  129. }else {
  130. disablePanel();
  131. }
  132. }
  133. //?????????????.
  134. //??selectItem(item)?flash cs4 10.0.2???
  135. function findIt(){
  136. var lbItem = item;
  137. if(lbItem){
  138. if(lbItem.name.lastIndexOf('/')>0){
  139. var pathNames = lbItem.name.split('/');
  140. var path = '';
  141. for(var j=0; j<pathNames.length; j++){
  142. path += (j==0?'':'/') + pathNames[j];
  143. fl.getDocumentDOM().library.expandFolder(true, false, path);
  144. }
  145. }
  146. fl.getDocumentDOM().library.selectItem(lbItem.name);
  147. }
  148. }
  149. //??SWFPanel????
  150. function apply(arg) {
  151. alert(arg);
  152. var args = arg.split('|');
  153. for(var i = 0; i<args.length; i++){
  154. var t = args[i].indexOf(':');
  155. var prop = args[i].substring(0, t);
  156. var value = args[i].substring(t + 1);
  157. for (var str in item) {
  158. if (str == prop) {
  159. if(prop == 'scalingGrid' || prop == 'linkageExportForAS' || prop == 'linkageExportForRS' || prop == 'linkageExportInFirstFrame') {
  160. item[prop] = (value == 'true');
  161. }else{
  162. item[prop] = value;
  163. }
  164. fl.trace('?????' + prop + '-' + value);
  165. fl.getDocumentDOM().library.updateItem(item.name);
  166. }
  167. }
  168. }
  169. }
  170. ]]>
  171. </jsfl>;
  172. return xml.toString();
  173. }
  174. private function onAdded(evt:Event):void{
  175. //this.findit_btn.addEventListener(MouseEvent.CLICK, onClickFindIt);
  176. //this.confirm_btn.addEventListener(MouseEvent.CLICK, onClickCfm);
  177. this.apply_btn.addEventListener(MouseEvent.CLICK, onClickApply);
  178. //??????
  179. var tfm : TextFormat = new TextFormat('Trebuchet MS', 12);
  180. tfm.color = 0xffffff;
  181. StyleManager.setStyle('textFormat', tfm);
  182. exportAS_cb.addEventListener(Event.CHANGE, onChangeExportAS);
  183. type_cb.addEventListener(Event.CHANGE, onChangeType);
  184. //??JSFL??
  185. MMExecute(initJSFL());
  186. }
  187. //?????
  188. private function onClickApply(evt:MouseEvent):void {
  189. item.name = name_tf.text;
  190. item.symbolType = ['movie clip', 'button', 'graphic'][type_cb.selectedIndex];
  191. item.linkageClassName = className_tf.text;
  192. item.linkageBaseClass = baseClassName_tf.text
  193. item.linkageExportForAS = exportAS_cb.selected;
  194. item.linkageExportInFirstFrame = exportAt1Frame_cb.selected;
  195. item.scalingGrid = scale9grid_cb.selected;
  196. var pro:String = itemToString(item);
  197. MMExecute('apply("' + pro + '")');
  198. }
  199. private function onClickFindIt(evt:MouseEvent):void {
  200. MMExecute('findIt();');
  201. }
  202. private var freezeShape:Sprite;
  203. private function disablePanel():void {
  204. this.visible = false;
  205. if (freezeShape == null) {
  206. freezeShape = new Sprite();
  207. freezeShape.graphics.beginFill(0, .2);
  208. freezeShape.graphics.drawRect(0, 0, this.stage.stageWidth, this.stage.stageHeight);
  209. }
  210. //addChild(freezeShape);
  211. }
  212. private function enablePanel():void {
  213. this.visible = true;
  214. if (freezeShape) {
  215. if (freezeShape.parent) freezeShape.parent.removeChild(freezeShape);
  216. }
  217. }
  218. private function showLibrayItemInfo(arg:String):void {
  219. enablePanel();
  220. //name:?? 2|type:movie clip|className:??2
  221. var args:Array = arg.split('|');
  222. var obj:Object = {};
  223. for(var i:int = 0; i<args.length; i++){
  224. var t:int = args[i].indexOf(':');
  225. var prop:String = args[i].substring(0, t);
  226. var value:String = args[i].substring(t + 1);
  227. obj[prop] = value;
  228. }
  229. item = new LibraryItem(obj);
  230. updateView();
  231. }
  232. private function itemToString(item:LibraryItem):String {
  233. var str:String = '';
  234. var prop:XML;
  235. for each(prop in (describeType(LibraryItem)..variable.@name)) {
  236. str += prop.toString() + ':' + item[prop.toString()] + '|';
  237. }
  238. return str;
  239. }
  240. private function log(str:String):void {
  241. debug_tf.text = str;
  242. }
  243. private function updateView():void {
  244. name_tf.text = item.name;
  245. type_cb.selectedIndex = ['movie clip', 'button', 'graphic'].indexOf(item.symbolType);
  246. if (item.symbolType == 'movie clip') {
  247. scale9grid_cb.enabled = true;
  248. }else {
  249. scale9grid_cb.enabled = false;
  250. }
  251. if (item.symbolType == 'graphic') {
  252. exportAS_cb.enabled = false;
  253. exportAt1Frame_cb.enabled = className_tf.enabled = baseClassName_tf.enabled = false;
  254. return;
  255. }else {
  256. exportAS_cb.enabled = true;
  257. }
  258. className_tf.text = item.linkageClassName;
  259. baseClassName_tf.text = item.linkageBaseClass;
  260. exportAS_cb.selected = item.linkageExportForAS;
  261. exportAt1Frame_cb.selected = item.linkageExportInFirstFrame;
  262. scale9grid_cb.selected = item.scalingGrid;
  263. if (!item.linkageExportForAS) {
  264. exportAt1Frame_cb.enabled = className_tf.enabled = baseClassName_tf.enabled = false;
  265. }else {
  266. exportAt1Frame_cb.enabled = className_tf.enabled = baseClassName_tf.enabled = true;
  267. }
  268. }
  269. }
  270. }
  271. import flash.geom.Rectangle;
  272. dynamic class LibraryItem{
  273. //public var timeline:String;
  274. public var symbolType:String;
  275. //public var sourceFilePath:String;
  276. //public var sourceLibraryName:String;
  277. //public var sourceAutoUpdate:Boolean;
  278. public var scalingGrid:Boolean;
  279. //public var scalingGridRect:Rectangle;
  280. public var itemType:String;
  281. public var name:String;
  282. public var linkageExportForAS:Boolean;
  283. //public var linkageExportForRS:Boolean;
  284. public var linkageExportInFirstFrame:Boolean;
  285. public var linkageIdentifier:String;
  286. public var linkageClassName:String;
  287. public var linkageBaseClass:String;
  288. //public var linkageURL:String;
  289. public function LibraryItem(obj:*):void{
  290. //timeline = obj.timeline;
  291. symbolType = obj.symbolType;
  292. //sourceFilePath = encodeURI(obj.sourceFilePath);
  293. //sourceLibraryName = obj.sourceLibraryName;
  294. //sourceAutoUpdate = (obj.sourceAutoUpdate == 'true');
  295. scalingGrid = (obj.scalingGrid == 'true');
  296. // scalingGridRect = obj.scalingGridRect;
  297. itemType = obj.itemType;
  298. name = obj.name;
  299. linkageExportForAS = (obj.linkageExportForAS == 'true');
  300. //linkageExportForRS = (obj.linkageExportForRS == 'true');
  301. linkageExportInFirstFrame = (obj.linkageExportInFirstFrame == 'true');
  302. linkageIdentifier = obj.linkageIdentifier;
  303. linkageClassName = obj.linkageClassName;
  304. linkageBaseClass = obj.linkageBaseClass;
  305. //linkageURL = obj.linkageURL;
  306. }
  307. public static function getBaseClassNameByType(type:String):String {
  308. var str:String;
  309. switch(type) {
  310. case 'movie clip':
  311. str = 'flash.display.MovieClip';
  312. break;
  313. case 'button':
  314. str = 'flash.display.SimpleButton';
  315. break;
  316. }
  317. return str;
  318. }
  319. }