Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-02-2009, 09:29 PM   #1
sheepfilms
Registered User
 
Join Date: Mar 2009
Posts: 2
Default Publish Each Layer With Layer Name

Hello all

I'm trying to create a JSFL that publishes all normal layers, not guide or mask layers, and using the layer name as the exported swf. I've found a script that's most of the way there, exporting PNGs from the layers but using an arbitrary name rather than the layer name. Found here BTW

Could anyone help me adapt it?

Code:
var doc = fl.getDocumentDOM();
var lyrs = doc.getTimeline().layers;

var len = lyrs.length;
var lyr;
var originalType;
var i;
var pngName;
var saveName;

// Get a save location.
var saveDir = fl.browseForFolderURL("Choose a folder in which to save your exported PNGs:");
if (saveDir) {
	// Get the Flash document's name, and strip off the final ".fla", and build a base name for the exported files.
	fl.outputPanel.clear();
	var docName = doc.name;
	var extensionIndex = docName.lastIndexOf(".fla");
	if (extensionIndex == docName.length - 4) {
		docName = docName.substring(0, extensionIndex);
	}
	saveName = saveDir + "/" + docName;
	
	// Acceptable values are "normal", "guide", "guided", "mask", "masked", and "folder".
	var originalTypes = new Array();
	
	// Grab all original layer types.  Need to do this before setting to guide, because otherwise a mask layer turned
	// to guide would would turn a masked layer into a normal layer.
	for (i=0; i < len; i++) {
		lyr = lyrs[i];
		originalTypes[i] = lyr.layerType;
	};
	
	// Guide all layers.
	for (i=0; i < len; i++) {
		lyr = lyrs[i];
		lyr.layerType = "guide";
	};

	// Save layers that were originally "normal" as PNGs, one-by-one.
	for (i=0; i < len; i++) {
		lyr = lyrs[i];
		originalType = originalTypes[i]
		if (originalType == "normal" || originalType == "guided") {
			lyr.layerType = "normal";
			exportPng(i);
			lyr.layerType = "guide";
		}
		
		// In this case, we need to loop backwards until we find the mask layer, then re-mask this layer, before we export.
		if (originalType == "masked") {
			for (var j=i; j >= 0; j--) {
				if (originalTypes[j] == "mask") {
					var maskLyrSearch = lyrs[j];
					maskLyrSearch.layerType = "mask";
					lyr.layerType = "masked";
					exportPng(i);
					maskLyrSearch.layerType = "guide";
					lyr.layerType = "guide";
					break;
				}
			};
		}
		
	};

	// Reset all layers to their original types.
	for (i=0; i < len; i++) {
		lyr = lyrs[i];
		lyr.layerType = originalTypes[i];
	};


}

function exportPng(i) {
	pngName = saveName + i + ".png";
	doc.exportPNG(pngName, true, true);
	fl.trace("Exported: " + pngName);
}
I've changed the end exportPNG funtion to create SWFs

Code:
function exportPng(i) {
	pngName = saveName + ".swf";
	doc.exportSWF(pngName, true, true);
	fl.trace("Exported: " + pngName);
}
It's just I can't get the layer name from this, even though I've tried using the doc.getTimeline().getLayerProperty('name'); command

Thanks!
sheepfilms is offline   Reply With Quote
Old 03-05-2009, 09:31 PM   #2
sheepfilms
Registered User
 
Join Date: Mar 2009
Posts: 2
Default Solution Found

I got in touch with the person who wrote the original script and was given the solution

Change line 45 from

Code:
exportPng(i);
to this:

Code:
exportPng(lyr.name);
I also altered the line

Code:
saveName = saveDir + "/" + docName;
To not include the docName. Job done!
sheepfilms is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
zindex, layer position. xainey ActionScript 3.0 1 12-04-2008 04:06 AM
question regarding layer jungyung ActionScript 1.0 (and below) 2 10-02-2006 10:57 AM
setMask & layer Mask's won't print easytarget ActionScript 2.0 1 11-23-2005 04:32 PM
dynamic changes in the mask (movie clip does not duplicate itself in the mask layer) enfant2soleil ActionScript 2.0 5 08-12-2005 04:50 PM
Adding different AS to each layer iKwak Simple Stuff (Newbies) 1 06-26-2004 05:59 AM


All times are GMT. The time now is 02:50 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.