/ Published in: JavaScript
Convert Symbol to Bitmap in Current Layer
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
fl.trace("========================================START") var mQuality = prompt('輸入壓縮å“質數值(0~100, default:80) : '); if (mQuality == null || mQuality == "") { mQuality = 80; } else { mQuality = parseInt(mQuality); } var lib = fl.getDocumentDOM().library; var mTimeline = fl.getDocumentDOM().getTimeline(); // get index of current layer var layerIdx = mTimeline.currentLayer; var framesArray = mTimeline.layers[layerIdx].frames; if (framesArray.length > 0) { var keyframesArray = []; // get key frames in current layer for (i=0; i<framesArray.length; i++) { if (i==framesArray[i].startFrame) { keyframesArray.push(framesArray[i]); } } fl.trace("Bitmap compression : " + mQuality.toString()); fl.trace("Get " + keyframesArray.length.toString() + " keyframes at Layer : " + mTimeline.layers[layerIdx].name) var mElement; for (i=0; i<keyframesArray.length; i++) { // in keyframe if (keyframesArray[i].elements.length > 0) { for (j=0; j<keyframesArray[i].elements.length; j++) { // in element mElement = keyframesArray[i].elements[j]; if (mElement.instanceType == "symbol") { // is a symbol element // set current frame mTimeline.currentFrame = keyframesArray[i].startFrame; // set selection to current element fl.getDocumentDOM().selection = [mElement]; fl.trace("At frame " + keyframesArray[i].startFrame + ", Item name : " + mElement.libraryItem.name + ", Select elements : " + document.selection.length.toString() ); if(document.selection.length>0){ document.convertSelectionToBitmap(); fl.trace(" Convert to Bitmap ... " + keyframesArray[i].elements[j].libraryItem.name); libItemIdx = lib.findItemIndex(keyframesArray[i].elements[j].libraryItem.name); item = lib.items[libItemIdx]; if(item.itemType == "bitmap" && item.name.substr(0,3)=="點陣圖"){ item.compressionType = "photo"; item.quality = mQuality; fl.trace(" Set compression to " + mQuality.toString()); } } } } } } } alert("Done.") fl.trace("========================================END")