Return to Snippet

Revision: 67298
at September 5, 2014 19:10 by janusoo


Updated Code
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")

Revision: 67297
at September 5, 2014 17:48 by janusoo


Initial Code
var mTimeline = fl.getDocumentDOM().getTimeline();
// get index of current layer
var layerIdx = mTimeline.currentLayer
var framesArray = mTimeline.layers[layerIdx].frames
var keyframesArray = [];
// get key frames in current layer
for (i=0; i<framesArray.length; i++) { 
    if (i==framesArray[i].startFrame) { 
        keyframesArray.push(framesArray[i])
    } 
}
alert("Get " + keyframesArray.length.toString() + " keyframes at Layer : " + mTimeline.layers[layerIdx].name)

var mElement;

for (i=0; i<keyframesArray.length; i++) {
	// in keyframe
	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 + ", select elements : " + document.selection.length.toString() );
			
			if(document.selection.length>0){
				document.convertSelectionToBitmap();
				fl.trace("Convert to Bitmap");
			}
		}
	}
}

Initial URL

                                

Initial Description
Convert Symbol to Bitmap in Current Layer

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

Initial Tags
flash

Initial Language
JavaScript