Flash CS4, JSFL: changing settings for exportPNG
I need to export FLA as a sequence of PNG images using JSFL.
The first problem I faced is that I cannot call document.importPublishProfileString to change current publish profile, it always fails (returns 0). Now I create a separate publish profile, removing it if already exists. I don't know why it's not mentioned in the documentation.
The second problem is more severe. Publish profile is ignored when I call document.exportPNG(). Width and height which I last used in the dialog "File > Export > Export movie" are used instead. The profile is created with correct settings, I can see them using UI. Now even publishing through UI (File > Publish) uses settings from movie export.
fl.outputPanel.clear();
var doc = fl.getDocumentDOM();
var profile = new XML(doc.exportPublishProfileString());
profile.@name = 'Game';
profile.PublishFormatProperties.png = 1;
profile.PublishFormatProperties.flash = 0;
profile.PublishFormatProperties.generator = 0;
profile.PublishFormatProper开发者_如何转开发ties.projectorWin = 0;
profile.PublishFormatProperties.projectorMac = 0;
profile.PublishFormatProperties.html = 0;
profile.PublishFormatProperties.gif = 0;
profile.PublishFormatProperties.jpeg = 0;
profile.PublishFormatProperties.qt = 0;
profile.PublishFormatProperties.rnwk = 0;
profile.PublishPNGProperties.@enabled = 'true';
profile.PublishPNGProperties.Width = 500;
profile.PublishPNGProperties.Height = 500;
profile.PublishPNGProperties.Interlace = 0;
profile.PublishPNGProperties.Transparent = 1;
profile.PublishPNGProperties.Smooth = 1;
profile.PublishPNGProperties.DitherSolids = 0;
profile.PublishPNGProperties.RemoveGradients = 0;
profile.PublishPNGProperties.MatchMovieDim = 0;
profile.PublishPNGProperties.DitherOption = 'None';
profile.PublishPNGProperties.FilterOption = 'None';
profile.PublishPNGProperties.MatchMovieDim = 0;
profile.PublishPNGProperties.BitDepth = '24-bit with Alpha';
fl.trace(profile);
if (doc.publishProfiles.indexOf('Game') != -1) {
doc.currentPublishProfile = 'Game';
doc.deletePublishProfile();
}
doc.addNewPublishProfile('Game');
fl.trace(doc.importPublishProfileString(profile));
var exportFileName = doc.pathURI.replace(/%20/g, " ").replace(doc.name, "1/" + doc.name.replace(/\.fla$/, "") + ".png"); // temporary hack
fl.trace(exportFileName);
doc.exportPNG(exportFileName, true, false);
Is there any way to make exportPNG respect settings from the profile?
I think the PNG publish settings actually refer to images inside the published SWF that are not JPG-compressed.
Alternatively, if you're launching the script from a SWF panel, you could use a publish setting to export a SWF, retrieve it, load it into your panel, then generate a PNG of each frame using something like AS3CoreLib. Since you're in CS4, Flash Player 10 should let you save to the local drive.
I just changed your script to turn off the MatchMovieDim first before trying to set the width and height and it works for me. I think the Width and Height settings are rejected until MatchMovieDim is off.
profile.PublishPNGProperties.MatchMovieDim = 0;
profile.PublishPNGProperties.Width = 500;
profile.PublishPNGProperties.Height = 500;
精彩评论