jsfl script Fixed path wihout need to browse

96 Views Asked by At

How can I set a fixed path so I don't need to select a folder everytime I run this script. So it's always the same path. So there's no popup window for select folder. Need to use this script for a batchfile to run several things.

png2swf();

function png2swf()
{
    var folderURI = fl.browseForFolderURL("Select a folder.");
    if (folderURI == null) { return; }
    var folderContents = FLfile.listFolder(folderURI);

    var doc = fl.createDocument();
    doc.backgroundColor = '#00FF00';
    
    var imported = 0;
        
    for(var i=0; i< folderContents.length; i++){
        
                    
        var pngURI = folderURI + "/" +folderContents[i];
        if (pngURI.substr(pngURI.length-4) != ".png") continue;
        
        doc.importFile(pngURI);
        
        // get item     
        var bmp_lib = doc.library.items[imported];
        bmp_lib.compressionType = "lossless";       
                bmp_lib.allowSmoothing = true;
        var bmp_tl = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0];
                
                // Center image
                
                bmp_tl.x = 0;
                bmp_tl.y = 0;
        
        // set doc size
        doc.width = Math.floor(bmp_tl.width);
        doc.height = Math.floor(bmp_tl.height);     

        // export   
        var swfURI = pngURI.substr(0,pngURI.lastIndexOf(".")+1)+"swf";
        doc.exportSWF(swfURI, true );
        
        // remove previous from timeline
        doc.selectAll();
        doc.deleteSelection();
        
        // increase imported count
        imported++;
    }
    
    doc.close(false);
    
    alert(imported + " files created.");
}

1

There are 1 best solutions below

0
Clif On

You can hard write the folder path. On Mac this might look like:

"file:///Macintosh%20HD/Users/[username]/Documents/..."

On PC:

"file:///C:/Users/[username]/Documents/..."

Some other options would be the config file path using an.configURI. Which is equivalent to:

"file:///Macintosh%20HD/Users/[username]//Library/Application%20Support/Adobe/Animate%20[version]/en_US/Configuration/"

Or:

"file:///C:/Users/[username]/AppData/Local/Adobe/Animate/[version]/Configuration"

Or you could get the document folder path (where your Animate file is saved) or your script folder path (where your script is located) like so:

Animate File Location:

var dom = an.getDocumentDOM();
var domFolder = dom.pahtURI.replace(dom.name, "");

Script File Location:

var loc = an.scriptURI;
var scriptFolder = loc.substring(0, loc.lastIndexOf("/") + 1);