Posted By

janusoo on 09/05/14


Tagged

flash jsfl


Versions (?)

[Flash] JSFL - Convert Symbol to Bitmap in Current Layer


 / Published in: JavaScript
 

Convert Symbol to Bitmap in Current Layer

  1. fl.trace("========================================START")
  2.  
  3. var mQuality = prompt('輸入壓縮品質數值(0~100, default:80) : ');
  4. if (mQuality == null || mQuality == "") {
  5. mQuality = 80;
  6. } else {
  7. mQuality = parseInt(mQuality);
  8. }
  9.  
  10. var lib = fl.getDocumentDOM().library;
  11. var mTimeline = fl.getDocumentDOM().getTimeline();
  12. // get index of current layer
  13. var layerIdx = mTimeline.currentLayer;
  14. var framesArray = mTimeline.layers[layerIdx].frames;
  15. if (framesArray.length > 0) {
  16. var keyframesArray = [];
  17. // get key frames in current layer
  18. for (i=0; i<framesArray.length; i++) {
  19. if (i==framesArray[i].startFrame) {
  20. keyframesArray.push(framesArray[i]);
  21. }
  22. }
  23. fl.trace("Bitmap compression : " + mQuality.toString());
  24. fl.trace("Get " + keyframesArray.length.toString() + " keyframes at Layer : " + mTimeline.layers[layerIdx].name)
  25.  
  26. var mElement;
  27.  
  28. for (i=0; i<keyframesArray.length; i++) {
  29. // in keyframe
  30. if (keyframesArray[i].elements.length > 0) {
  31. for (j=0; j<keyframesArray[i].elements.length; j++) {
  32. // in element
  33. mElement = keyframesArray[i].elements[j];
  34.  
  35. if (mElement.instanceType == "symbol") {
  36. // is a symbol element
  37.  
  38. // set current frame
  39. mTimeline.currentFrame = keyframesArray[i].startFrame;
  40. // set selection to current element
  41. fl.getDocumentDOM().selection = [mElement];
  42. fl.trace("At frame " + keyframesArray[i].startFrame + ", Item name : " + mElement.libraryItem.name + ", Select elements : " + document.selection.length.toString() );
  43.  
  44. if(document.selection.length>0){
  45. document.convertSelectionToBitmap();
  46. fl.trace(" Convert to Bitmap ... " + keyframesArray[i].elements[j].libraryItem.name);
  47.  
  48. libItemIdx = lib.findItemIndex(keyframesArray[i].elements[j].libraryItem.name);
  49.  
  50. item = lib.items[libItemIdx];
  51.  
  52. if(item.itemType == "bitmap" && item.name.substr(0,3)=="點陣圖"){
  53. item.compressionType = "photo";
  54. item.quality = mQuality;
  55. fl.trace(" Set compression to " + mQuality.toString());
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
  63. alert("Done.")
  64. fl.trace("========================================END")

Report this snippet  

You need to login to post a comment.