Skip to main content
Participant
February 14, 2024
質問

Export selected Movie Clips in library to PNGs and keep the name of the MC.

  • February 14, 2024
  • 返信数 1.
  • 259 ビュー

Hi I am trying to modify this script to export selected Movie Clips from library to PNGs and keep original name of the MC. I have the script that works well exporting selected bitamps from library, but I am trying yo modify it to export also Movie clips.

 

function exportLibraryImagesToFiles() {
	var doc = fl.getDocumentDOM();
	if (!doc) return;

	var selectedItems = doc.library.getSelectedItems();
	if (!selectedItems.length) return;

	var folder = fl.browseForFolderURL("Choose an output directory.");
	if (!folder) return;

	var i, t, sym, bmpName;
	var count = 0;

	for (i = 0; i < selectedItems.length; i++) {
		sym = selectedItems[i];
		if (sym.itemType != "bitmap") {
			continue;
		}
		bmpName = sym.name.split("/").pop();
		// strip original extension
		t = bmpName.lastIndexOf(".");
		if (t != -1 && ["jpg", "jpeg", "png", "gif", "bmp", "psd"].indexOf(bmpName.substr(t + 1).toLowerCase()) != -1) {
			bmpName = bmpName.substr(0, t);
		}
		// do the thing
		sym.exportToFile(folder + "/" + bmpName + "." + (sym.compressionType == "photo" ? "jpg" : "png"));
		count++;
	}
	alert(count + " image(s) exported.");
}

exportLibraryImagesToFiles();
    このトピックへの返信は締め切られました。

    返信数 1

    kglad
    Community Expert
    Community Expert
    February 15, 2024

    did you change itemType to "movie clip"?

    eryk_stanko作成者
    Participant
    February 19, 2024

    Hi. Yes I tried to change it itemType for movie clip, but script does not work. Here is modified code.

    function exportLibraryMovieClipsToFiles() {
    	var doc = fl.getDocumentDOM();
    	if (!doc) return;
    
    	var selectedItems = doc.library.getSelectedItems();
    	if (!selectedItems.length) return;
    
    	var folder = fl.browseForFolderURL("Choose an output directory.");
    	if (!folder) return;
    
    	var i, t, sym, mcName;
    	var count = 0;
    
    	for (i = 0; i < selectedItems.length; i++) {
    		sym = selectedItems[i];
    		if (sym.itemType != "movie clip") {
    			continue;
    		}
    		mcName = sym.name.split("/").pop();
    		// strip original extension
    		t = mcName.lastIndexOf(".");
    		if (t != -1 && ["jpg", "jpeg", "png", "gif", "bmp", "psd"].indexOf(mcName.substr(t + 1).toLowerCase()) != -1) {
    			mcName = mcName.substr(0, t);
    		}
    		// do the thing
    		sym.exportToFile(folder + "/" + mcName + "." + (sym.compressionType == "photo" ? "jpg" : "png"));
    		count++;
    	}
    	alert(count + " movie clip(s) exported.");
    }
    
    exportLibraryMovieClipsToFiles();
    kglad
    Community Expert
    Community Expert
    February 19, 2024

    you still have errors, but the bottom line is the movieclip has no exportToFile method.  ie, you'll need to convert it to a bitmap, first.