Advertisement
neirao

Untitled

Sep 17th, 2017
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.84 KB | None | 0 0
  1. /*+----------+----------+----------+----------+
  2. @neirao
  3. for Sprites Sheets multiresolution devices!
  4. [loop for movieclips in library and resize your all frames]
  5. +----------+----------+----------+----------+
  6. updates:
  7. +----------+----------+----------+----------+
  8. -
  9. -
  10. -17/09/2017
  11. +----------+----------+----------+----------+
  12. missing:
  13. +----------+----------+----------+----------+
  14. - select the position, top left, center etc.. in menu
  15. - jump not keyframes... same imagens on mcs frames
  16. +----------+----------+----------+----------+*/
  17.  
  18. fl.outputPanel.clear();
  19. fl.trace("initialize...");
  20. trace_line = "+----------+----------+----------+----------+";
  21. fl.trace(trace_line);
  22. //fl.trace("timeline: " + timeline + " - totalframes: " + frames); //timeline: [object Timeline] - totalframes: 1
  23.  
  24. var doc = fl.getDocumentDOM();
  25. if (doc == null || doc.getTimeline() == null) {
  26. alert("Please open or create a .fla file!");
  27. } else {
  28. var lib = doc.library;
  29. var sel = doc.selection;
  30. var timeline = doc.getTimeline();
  31. var frames = timeline.frameCount;
  32. //+----------+----------+----------+----------+
  33. //@2
  34. var resize_stage = true; //se vai ou não redimeziona o stage e posicionar os elementos no palco!!
  35. var mcs_on_stage = 0; //conta se tem ou não MovieClip elementos no palco!
  36. var mcs_on_library = 0; //conta se tem ou não MovieClip elementos na library!
  37. //+----------+----------+----------+----------+
  38. var percent=null;
  39. //+----------+----------+----------+----------+
  40.  
  41. enterPercent();
  42. //resizeMovieClipsOnStage();
  43. }
  44.  
  45. function enterPercent(){
  46. //@2
  47. //+----------+----------+----------+----------+
  48. var ret = prompt("Enter a percent number, (like 0.5 || 2.0):");
  49. //var percent = prompt("percent(like 0.5 || 2.0 etc... ):", '');//direto
  50. if (ret != null) {
  51. //var percent = parseFloat(ret);
  52. percent = parseFloat(ret);//para ser global
  53.  
  54. if (isNaN(percent)) {
  55. alert("the percent no is a Number valid... try again...");
  56. return;
  57. }
  58. } else {
  59. alert("type some value... try again...");
  60. return;
  61. }
  62. //all ok, continue
  63.  
  64. //if (ret != null && !isNaN(percent)) {
  65. resizeMovieClipsOnStage();
  66. //}
  67. }
  68.  
  69. function resizeMovieClipsOnStage() {
  70. fl.trace("resizeMovieClips...on stage..");
  71. fl.trace(trace_line);
  72. //[loop layers]
  73. fl.trace("timeline.layers.length: " + timeline.layers.length); //2
  74. fl.trace("timeline.layerCount: " + timeline.layerCount); //2
  75. fl.trace(trace_line);
  76. //+----------+----------+----------+----------+
  77. for (var i = 0; i < timeline.layers.length; i++) {
  78. var layer = timeline.layers[i];
  79. fl.trace(layer.name + " - " + layer.layerType);
  80. //fl.trace("layer: "+layer);//layer: [object Layer]
  81. //fl.trace("layer.frames.length: "+layer.frames.length);//layer.frames.length: 1
  82. /*
  83. layer.layerType: mask
  84. layer.layerType: guide
  85. layer.layerType: normal
  86. layer.layerType: normal */
  87.  
  88. if (layer.layerType == "normal") {
  89. //[loop frames]
  90. for (var j = 0; j < layer.frames.length; j++) {
  91. var frame = layer.frames[j];
  92. //fl.trace("frame: "+frame);//[object Frame]
  93. //[loop elements]
  94. for (var k = 0; k < frame.elements.length; k++) {
  95. var element = frame.elements[k];
  96. fl.trace("element: " + element + " - elementType: " + element.elementType);
  97. fl.trace(trace_line);
  98. /*
  99. element: [object SymbolInstance] - elementType: instance = [MovieClip / Button / Graphic] <<<
  100. element: [object Shape] - elementType: shape
  101. element: [object Text] - elementType: text */
  102.  
  103. //if is [MovieClip / Button / Graphic] //=="button"
  104. if (element.elementType == "instance") {
  105. if (element.libraryItem.itemType == "movie clip") {
  106. //@2 conta se tem elementos no palco!
  107. mcs_on_stage++;
  108. var item_lib_name = element.libraryItem.name;
  109. fl.trace("item_lib_name: " + item_lib_name);
  110. //# [MISSING]
  111. //CRIAR AQUI para reduzir somente se tiver keyframe "."
  112. //#
  113. fl.trace("indexOf: " + item_lib_name.indexOf("Export/")); //0 ou -1
  114.  
  115. if (item_lib_name.indexOf("Export/") != -1) {
  116. fl.trace("o item '" + item_lib_name + "' está na pasta EXPORT!!!");
  117. } else {
  118. fl.trace("o item '" + item_lib_name + "' NÃO está na pasta EXPORT!!!");
  119. }
  120. /*
  121. //+----------+----------+----------+----------+
  122. //temp OK
  123. /*lib.selectAll(true);//ok
  124. var selectedItems = lib.getSelectedItems().slice();
  125. fl.trace("selectedItems: " + selectedItems);//[object SymbolItem],[object SymbolItem],[object SymbolItem],[object SymbolItem]
  126. fl.trace("selectedItems.length: "+selectedItems.length);//selectedItems.length: 4*/
  127. //+----------+----------+----------+----------+
  128. //lib.selectItem(item_lib_name);//ok seleciona 1 por 1
  129.  
  130. fl.trace("element.libraryItem: " + element.libraryItem); //element.libraryItem: [object SymbolItem]
  131. //lib.editItem(item_lib_name);
  132. //doc.selectAll();
  133. //+----------+----------+----------+----------+
  134. //do timeline_reader.jsfl...
  135. var frames_in_element = element.libraryItem.timeline.frameCount;
  136. for (x = 0; x < frames_in_element; x++) {
  137. fl.trace("x: " + x);
  138. element.libraryItem.timeline.currentFrame = x;
  139. //# [MISSING]
  140. //CRIAR AQUI para reduzir somente se tiver keyframe "."
  141. //#
  142. lib.editItem(item_lib_name);
  143. doc.selectAll();
  144. //doc.scaleSelection(0.50, 0.50, "top left");//ok direto
  145. //@2
  146. doc.scaleSelection(percent, percent, "top left");
  147. //doc.transformSelection(100,100,100,100);//zica
  148. }
  149. //fl.trace("item_lib_name: " + item_lib_name + " - frames: " + frames);
  150. doc.exitEditMode();
  151. //@2 OKKKKKKKKKKK
  152. //tem que ser APOS FECHAR O EDIT MODE!! OKKK
  153. //fl.trace("element.x ("+item_lib_name+")"+element.x);
  154. //fl.trace("element.y ("+item_lib_name+")"+element.y);
  155. if (resize_stage) {
  156. element.x *= percent;
  157. element.y *= percent;
  158. //centraliza o point!!
  159. //MISSING..ERRO..
  160. var px=(element.x-element.width)*percent;//element.x;//-(element.width/2);
  161. var py=(element.y-element.height)*percent;//element.y;//-(element.height/2);
  162. doc.setTransformationPoint({x:px, y:py});
  163. }
  164. }
  165. }
  166. }
  167. }
  168. }
  169. }
  170. doc.exitEditMode();
  171. fl.trace(trace_line);
  172. fl.trace("movieclips no stage: " + mcs_on_stage);
  173. if (mcs_on_stage > 0) {
  174. fl.trace(trace_line);
  175. if (resize_stage) {
  176. doc.width = doc.width * percent;
  177. doc.height = doc.height * percent;
  178. }
  179. fl.trace("movieclips and stage resized * " + percent * 100 + "%");
  180. fl.trace(trace_line);
  181. fl.trace("the end...STAGE MODE");
  182. }
  183. if (mcs_on_stage <= 0) {
  184. fl.trace("no theres movieclips on stage!!\n We will try in Library 'Export folder...'");
  185. resizeMovieClipsOnLibrary();
  186. }
  187. }
  188.  
  189. //# [MISSING]
  190. //CRIAR AQUI para reduzir somente se tiver keyframe "."
  191. //#
  192. function resizeMovieClipsOnLibrary() {
  193. fl.trace(trace_line);
  194. fl.trace(trace_line);
  195. fl.trace("search Movieclips ...on Library... only on [Export/]folder!");
  196. fl.trace("selectLibraryItems");
  197. fl.trace(trace_line);
  198. fl.trace(trace_line);
  199. lib.selectAll(); //okk
  200. //lib.selectItem("Export");//ok só folder
  201.  
  202. items = lib.getSelectedItems();
  203. fl.trace(items.length + " items selecionados na library: " + items);
  204. if (items.length <= 0) {
  205. alert("Sem itens para selecionar na Library!!");
  206. return;
  207. } else {
  208. for (var i = 0; i < items.length; i++) {
  209. var element = items[i]
  210. fl.trace("element: " + element);
  211. fl.trace("element.itemType: " + element.itemType);
  212. fl.trace(trace_line);
  213. //no stage movieclip.. "element.libraryItem.name"
  214. //if (element.libraryItem.itemType == "movie clip") {
  215. if (element.itemType == "movie clip") {
  216. //
  217. var item_lib_name = element.name;
  218. fl.trace("item_lib_name: " + item_lib_name);
  219. //# [MISSING]
  220. //CRIAR AQUI para reduzir somente se tiver keyframe "."
  221. //#
  222. //fl.trace("indexOf: " + item_lib_name.indexOf("Export/")); //0 ou -1
  223. //fl.trace("element.libraryItem: " + element.libraryItem); //aqui erro(element.libraryItem: undefined) element.libraryItem: [object SymbolItem]
  224. //aqui é..
  225. fl.trace("element.libraryItem: " + element); //ok element.libraryItem: [object SymbolItem]
  226.  
  227. if (item_lib_name.indexOf("Export/") != -1) {
  228. fl.trace("o item '" + item_lib_name + "' está na pasta EXPORT!!!");
  229. mcs_on_library++;
  230.  
  231. //var frames_in_element = element.libraryItem.timeline.frameCount;
  232. var frames_in_element = element.timeline.frameCount;
  233. for (x = 0; x < frames_in_element; x++) {
  234. fl.trace("x: " + x);
  235. element.timeline.currentFrame = x;
  236. //# [MISSING]
  237. //CRIAR AQUI para reduzir somente se tiver keyframe "."
  238. //#
  239. lib.editItem(item_lib_name);
  240. doc.selectAll();
  241. //doc.scaleSelection(0.50, 0.50, "top left");//ok direto
  242. //@2
  243. doc.scaleSelection(percent, percent, "top left");
  244. }
  245. //fl.trace("item_lib_name: " + item_lib_name + " - frames: " + frames);
  246. doc.exitEditMode();
  247. //aqui não usa o .X E .Y!! só no Stage!!
  248.  
  249. } else {
  250. fl.trace("o item '" + item_lib_name + "' NÃO está na pasta EXPORT!!!");
  251. }
  252. }
  253. }
  254. }
  255. doc.exitEditMode();
  256. fl.trace(trace_line);
  257. fl.trace("Total movieclips no library: " + mcs_on_library);
  258. if (mcs_on_library > 0) {
  259. fl.trace(trace_line);
  260. if (resize_stage) {
  261. doc.width = doc.width * percent;
  262. doc.height = doc.height * percent;
  263. }
  264. fl.trace("movieclips and stage resized * " + percent * 100 + "%");
  265. }
  266. if (mcs_on_library <= 0) {
  267. fl.trace("no theres movieclips on stage!!\n We will try in Library 'Export folder...'");
  268. alert("NO THERES MOVIECLIPs on stage or in library!! Please create!!");
  269. return;
  270. }
  271. fl.trace(trace_line);
  272. fl.trace("the end...LIBRARY MODE!");
  273.  
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement