Using JSFL to change publish settings
The code in this post is old. Please refer to my updated version:
http://www.stevensacks.net/2008/03/26/using-jsfl-to-change-publish-profile-settings-v2/
…
Recently, I needed to automate generating templates and discovered that there was no direct way of editing the publish settings of the document using JSFL. The way to accomplish it is to export the publish profile (it's XML), read it back in as a string, swap out the node values, save the file, import the publish profile, and then delete the file. Here's how I accomplished it.
function setPublishSettings(fileName:String)
{
var xml, from, to, snip;
var fPath = getRelativePath() + "PublishProfile.xml";
// export the profile and read it in
fl.getDocumentDOM().exportPublishProfile(fPath);
xml = FLfile.read(fPath);
// replace the publish paths
from = xml.indexOf("<flashFileName>");
to = xml.indexOf("</flashFileName>");
snip = xml.substring(from, to);
xml = xml.split(snip).join("../deploy/" + fileName);
var nodes = {};
nodes.generatorFileName = "swt";
nodes.projectorWinFileName = "exe";
nodes.projectorMacFileName = "hqx";
nodes.htmlFileName = "html";
nodes.gifFileName = "gif";
nodes.jpegFileName = "jpg";
nodes.pngFileName = "png";
nodes.qtFileName = "mov";
nodes.rnwkFileName = "smil";
for (var n in nodes) {
from = xml.indexOf("<" + n + ">");
to = xml.indexOf("");
snip = xml.substring(from, to);
xml = xml.split(snip).join("<" + n + ">" + fileName + "." + nodes[n]);
}
// write the file
FLfile.write(fPath, xml);
// import the altered profile
fl.getDocumentDOM().importPublishProfile(fPath);
// delete the altered profile
FLfile.remove(fPath);
// save flash file
fPath = getRelativePath() + fileName + ".fla";
fl.saveDocument(fl.getDocumentDOM(), fPath);
}
December 11th, 2006 at 8:13 pm
Is there a way to do this so that it pulls the default.xml publish profile and writes a new one? That would be cool!
December 11th, 2006 at 8:20 pm
That's what line 6 does. It writes the default publish profile to the path you specify. Unless I'm misunderstanding your question?
January 31st, 2007 at 4:44 pm
Flash MX 2004 and Flash 8 have a bug where the class path and AS version strings are not imported from the XML file that's created here. Are there any ways around this?
February 2nd, 2007 at 12:06 am
The way I get around that is to set up my initial FLA file with the proper class paths first and duplicate from that FLA. I haven't had an issue changing the publish version, though.
February 2nd, 2007 at 2:42 pm
Hmnm, that's fine if you know about the issue before you start, but I've just been given 100s of FLA files that were developed months/years ago to change. I spent an hour or two making a JSFL file that recursively searches through folders and applies changes to all the FLA files it finds, only to find that AS version and class path are lost due to a stupid bug! =/
Macromedia really sucks HARD sometimes.
Thanks for the help and the quick response.
October 24th, 2007 at 10:53 am
Thankfully, this bug has been fixed in Flash CS3, and I used this code in the Gaia framework for Adobe Flash.
December 19th, 2007 at 9:48 am
Oh, and did not know about it. Thanks for the information …
January 10th, 2008 at 8:23 am
Hi,
Very new to jsfl and i tried your script . However it failed as getRelativePath() wasnt recognised, i guess then thats a function yoiu declare somewhere else and not a native jsfl method?
January 10th, 2008 at 10:30 am
getRelativePath() simply uses the native JSFL property "fl.getDocumentDOM().path". It's in the JSFL documentation under "Document object".
"document.path returns the path of the document in a platform-specific format. If the document has never been saved, this property is undefined."
Check out the documentation for JSFL to read more about using the "document.path" property to get the relative path of the open document. Another option is to use the fl.browseForFolderURL() method to open a dialog to find the relative path.
Hope that helps! JSFL is an awesome way to automate tasks in Flash and save you time. It's definitely worth learning.
March 6th, 2008 at 4:46 pm
I would love to learn a little more about your function here. Do you have a full JSFL script which uses this function and has the supporting getRelativePath() function as well you could post?
Also, the "< – -" characters in your code are screwing up the display of your site
March 6th, 2008 at 5:04 pm
My Gaia Framework uses something similar to this in the JSFL that scaffolds pages. Install it and open the JSFL files it uses to see how it works.
March 18th, 2008 at 10:20 pm
Do you know where there is a list of the allowable xml tags in a xml profile?
March 18th, 2008 at 11:01 pm
Go into Flash, export a publish profile manually and look at the XML file it creates.
March 19th, 2008 at 4:10 pm
Thanks, I already did that, but I want to know what is actually allowed in the xml. you can also see that their are profiles for video encoding, flash lite, and projects. but is there any documentation on the publish xml file? attributes and tags…
March 19th, 2008 at 6:25 pm
Not that I know of. If you ask on Flashcoders or Flash_Tiger, you might get an answer from Adobe's technical writer Francis Cheng.
March 26th, 2008 at 1:39 pm
What is supposed to happen in the replace publish paths section? When I used the code (on a mac) the new publish path is put between every single character. Where in the xml file are the publish path changes supposed to go?
What is confusing me is the code:
xml.indexOf("");
What is that searching for?
March 26th, 2008 at 1:49 pm
The indexOf("") is WordPress stripping out characters it shouldn't be. I'll fix it.
August 15th, 2008 at 6:12 am
Hi Steve, thanks for your post, it's been a massive help, although i still can't quite believe that you can't access and edit publish settings directly through jsfl???
I was also wondering if you might be able to point me in the right direction with something else i'm stuck on. I've written a jsfl script that recurses through a directory structure, creates a new file for each .flv file that it finds, imports the flv (to embed it) and then outputs a swf. The only problem is that i can't find a way to automate the 'import video' dialog box that pops up when you import an flv into the fla? I've got to do this for 850 flv's so i'm hoping you might know a way to communicate with this dialog box through jsfl? Otherwise i'm looking at a serious RSI!
I noticed an earlier comment from Quince mentioning profiles for video encoding and have got my hopes up that this may be the ray of light of was looking for! Any ideas?
cheers.
October 1st, 2008 at 8:31 am
Hi, thanks for posting, it seems quite useful. When I run the command in flash tho, I get an error saying
Line 141 :A was expected.
Any idea ???
October 1st, 2008 at 8:32 am
Sorry about that, it removed a part of my post. Error is PublishProfileProperties element was expected