JSFL Publish Deploy Settings for Flash 8 flas

My goal was to place my generated swf deployment files into a separate directory from the fla source files(Flash 8 versions). I found quite a few JSFL based batch jobs for publishing multiple fla files in deployment directories but none for a single testMovie scenario. The batch scenario did not work for me because I wanted to develop a single fla page and then view and publish it in a separate location.

The JSFL documentation I found for Flash 8 was limited. I also wish I could have found documentation on the xml based publish profile files. The Flash IDE has a default publish profile which resides in the following directory:

C:\Documents and Settings\username\Local Settings\Application Data\Macromedia\Flash 8\en\Configuration\Publish Profiles\default.xml

I started from Steven Sacks blog about Using JSFL to Change Publish Profile Settings v2. I was coming at it from a beginners perspective with respect to JSFL and no real knowledge of how JSFL worked within the Flash IDE. He encapsulated his request within a function but I was unsure of the implications/side effects of all the JSFL functions called and which functions would work for my goal of just publishing a single fla page to a deployment directory. So I grabbed his code and stripped it down to what I thought was the bare minimum.

So I created as2TestDeploy.jsfl and placed it in the following directory:

C:\Documents and Settings\username\Local Settings\Application Data\Macromedia\Flash 8\en\Configuration\Commands\as2TestDeploy.jsfl

This script then became accessible from within the flash IDE by selecting the Commands menu > as2testDeploy

Here is the first pass at as2TestDeploy.jsfl:

//setup file variable name
//first get the DOM for the current file
var doc = fl.getDocumentDOM();

//next access the filename of the file
var filename = doc.name;
var filePath = doc.path;

//Use jsfl trace statement to view info returned
fl.trace("filename is " + filename);
fl.trace("file path name is " + filePath);

//set actionscript version
var asVersion = 2;

//next create the URI
//tried to hardcode it but jsfl did not like my format
//var tempURI = "file:///H|/nutrition/source/NEPP/RIA_src/pages/m100001-100200/" + filename;
//used getDocumentPath function to get URI for JSFL
//function appended at end 
var URI = getDocumentPath()+ "/" +filename;

//now call publish profile function
setPublishProfileSettings(URI,asVersion);

/*
* setPublishProfileSettings
*
* @param 	String 	full URI pathname to current file
* @param	Number	version number for actionscript(2 or 3)
* 
* @return 	void
*/
function setPublishProfileSettings(fileURI, asVersion)
{
    // does flash file exist
    if (fl.fileExists(fileURI))
    {
        var xml, from, to, delta;

        // open the flash file
        var doc = fl.openDocument(fileURI);

        //grab the file name from its folder path
        var fileName = fileURI.split("/").pop();
             
        //get the current folder path
        var folderPath = fileURI.split(fileName)[0];
	     
        //remove fla extension
        fileName = fileName.split(".")[0];

        //set pathname for a temp publish profile
        var pPath = folderPath + "_Profile_.xml";

        //export default profile settings to temp file
        fl.getDocumentDOM().exportPublishProfile(pPath);
            
        //reload default settings into local xml var
        xml = FLfile.read(pPath);

        //OVERRIDE default settings for new profile
       //in xml variable to be written to pPath file
                
        //NOTE:The flag settings below are set to false
       //Impact - default name values are not used
       //Changing these flags will cause a
       //permanent side-effect, the publish path is reset
       //within the actual fla file which is my desired 
       //behaviour

       // override default names to 0 from 1
       from = xml.indexOf("<defaultNames>");
       to = xml.indexOf("</defaultNames>");
       delta = xml.substring(from, to);
       xml = xml.split(delta).join("<defaultNames>0");

       // override flash default name to 0 from 1
       from = xml.indexOf("<flashDefaultName>");
       to = xml.indexOf("</flashDefaultName>");
       delta = xml.substring(from, to);
       xml = xml.split(delta).join("<flashDefaultName>0");

       // grab publish path indices for swf
       from = xml.indexOf("<flashFileName>");
       to = xml.indexOf("</flashFileName>");
       delta = xml.substring(from, to);
              
       //hard coded the desired deploy directory path
       var parentPath = "./../../../../RIA_deploy/AS" + asVersion + "/www/NIM/mod/";

       //switch publish path for the swf 
       xml = xml.split(delta).join("<flashFileName>" + parentPath + fileName + ".swf");
	
        // write the modified profile to temp file
        FLfile.write(pPath, xml);
      
        //import new publish profile to be used by fla
        fl.getDocumentDOM().importPublishProfile(pPath);

        //request fla testMovie
        //generates swf in deployment directory
        fl.getDocumentDOM().testMovie();

        // delete the publish profile xml (no longer needed)
	//FLfile.remove(pPath);
    }
}

//Found this function at: 
//http://www.phwinfo.com/forum/macromedia-flash/299555-jsfl-importing-images-text-file-x-ycoordinates.html
// returns URI path of document running the JSFL script.
function getDocumentPath()
{
    var path = String(fl.getDocumentDOM().path).replace(/\\/ig,"/");
    path = path.replace(/:/ig,"|");
    path = "file:///"+path;
    path = path.replace(/\/+$/ig,"");
    path = path.substring(0,path.lastIndexOf("/"));
    return path;
}

The above JSFL code works for basic fla files. It also performs two desired effects:

  1. The swf file will be output to the desired deployment directory
  2. The fla files publish directory setting has been modified to point to the deployment directory

Note the following side effect of this script:

Each time I run this jsfl command, the publish profile settings are changed so the fla file will be changed. This is a desired behaviour the first time it is run in order to reset the final publishing directory. If my fla file is included in a svn repository, I would then recommit the file to save the updated publish directory setting.

After the JSFL script has been run once, I can/should now just select Control > Test Movie and the swf file will be output to my deployment directory. This should be the desired sequence(run script first time, then use testMovie) because I don’t want to be constantly reverting or recommitting a fla file to/from my svn repository.

NOTO BENE:
To see the JSFL fl.trace output, you must comment out fl.getDocumentDOM().testMovie(). The testMovie() command clears the output panel and then generates publishing errors or trace statements from the fla timeline.

Finally, check JSFL Deploy Settings Part II for a fla file that is referencing my local class library files and how to update the script to point to my local library.

Advertisements

One Response to JSFL Publish Deploy Settings for Flash 8 flas

  1. […] flash 8 files for our website and integrate it with our desired project directory configuration. Part I discusses how to redirect the generation of the swf file which is to be deployed to a different […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: