JSFL Publish Deploy Settings for Flash 8 – Part II

Noto Bene:
The information in this section only appears to apply to the Flash CS4 IDE and not the Flash 8 ide. I could not get the script to work to locate my classes when I removed my Edit>Preferences>Actionscript 2 Settings class reference. I guess the solution is you need to upgrade to CS4.

This JSFL script was developed to expedite our generation of new 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 directory from our source files. Part II will show how to add a reference to class libraries to be used when publishing more involved flash 8 files.

The next step in my understanding of the PublishProfileSetting JSFL script was how to setup the publishing profile to find the location of my actionscript 2 class library directories.

So using a brute force approach, I copied my global setting values located at Edit > Preferences > Actionscript(select actionscript 2 settings button) and replicated them in my local settings File> Publish Settings(Flash Tab > Actionscript version: ActionScript 2.0 settings button). I then generated the temporary publishing profile xml file and commented out the removal line to view the expected format.

This is what was generated in the node:

 <PackagePaths>.;$(LocalData)/Classes;H:\nutrition\source\NEPP\RIA_src\classes\AS2</PackagePaths>

Based on the above setting I modified the as2TestDeploy.jsfl script to update this element in the publish profile xml file.

Here is the final 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/";

       //change publish path for the swf from the default
       xml = xml.split(delta).join("<flashFileName>" + parentPath + fileName + ".swf");
	
        ////////////////////////////////////////////////////////////////
        //NEW CONTENT STARTS HERE
        // - code startpoint was cut and paste from Steven Sacks blog
        //
        // flas that need to reference classes, 
        // need to update Package Paths
        // make sure package paths look in :
        //  ./classes, and classes export in frame 1
        from = xml.indexOf("<ActionScriptVersion>");
        to = xml.indexOf("</ActionScriptVersion>");
        delta = xml.substring(from, to);
        xml = xml.split(delta).join("<ActionScriptVersion>" + asVersion);

        //set packages to export in frame 1
        from = xml.indexOf("<PackageExportFrame>");
        to = xml.indexOf("</PackageExportFrame>");
        delta = xml.substring(from, to);
        xml = xml.split(delta).join("<PackageExportFrame>1");

        // set package paths based on AS version
        if (asVersion == 2)
        {
            from = xml.indexOf("<PackagePaths>");
            to = xml.indexOf("</PackagePaths>");
        }
        else
        {
            from = xml.indexOf("<AS3PackagePaths>");
            to = xml.indexOf("</AS3PackagePaths>");
        }
	
        delta = xml.substring(from, to);
        var classPath = "./";
        if (fileName.indexOf("/") > -1)
        {
             classPath = "";
             var splitPath = fileName.split("/");
             splitPath.length--;
             var i = splitPath.length;
             while (i--)
             {
                  classPath += "../";
              }
        }
    	
        classPath += "classes";
        //alert(classPath);
        
        //brute force - ignored above class detection
        // and set the values here
        var neppPath = "H:\nutrition\source\NEPP\RIA_src\classes\AS2"
	allClasses = ".;$(LocalData)/Classes;" + neppPath;

        if (asVersion == 2)
        {
           //xml = xml.split(delta).join("<PackagePaths>" + classPath);
           xml = xml.split(delta).join("<PackagePaths>" + allClasses);    
        }
        else
        {
           xml = xml.split(delta).join("<AS3PackagePaths>" + classPath);
        }

       ////////////////////////////////////////////////////////////////////////////
       
        // 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 
        //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;
}

I know the code above is not elegant but serves a temporary service while we are converting our content to CS4 and actionscript 3.

Advertisements

One Response to JSFL Publish Deploy Settings for Flash 8 – Part II

  1. […] 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 […]

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: