views:

407

answers:

4

I'm working on a large Flash CS4 project with multiple swfs and want to consolidate my build process. Are ant/make overkill or have people out there successfully used them on large Flash projects?

Thanks

A: 

I'm using ant right now for a project that needs to compile upwards of 10-20 separate components into their own respective swfs... also using it to deploy to a staging and production server. It's kind of a pain to setup, but once it is it's really easy with relatively fast compile times. Additionally, you can totally customize ant compile targets... for example, you might only want to compile only 3 of the 10 swfs 90% of the time, so you'd setup a build target to do just that. In my opinion it's definitely worth it. Good luck!

heavilyinvolved
How does ant hook into the authoring tool, to open/publish/close files?
fenomas
Not sure. I'm using the flex compiler...
heavilyinvolved
A: 

I use Ant to open multiple .fla (queued) and run JSFL command inside them. You could compile multiple fla one after another with this method and also clean some properties. (Remove debug mode, get rid of a classpath or replace an obsolete path, raise flag, etc.)

I do this on 100+ fla. Works great, but can be slow.

Here's an ANT script with a JSFL command has example. (The JSFL use a parameter to force or not force a compilation even if the fla was not modified)

<?xml version="1.0" encoding="utf-8" ?>

<property name="flash" value="C:\[Replace this]\Flash.exe"/>
<!-- we start from this model and do a build...jsfl-->
<property name="model_jsfl_path" value="${basedir}\jsfl\model_jsfl_clean_permit_debug.jsfl"/>

<property name="paths" value="C:/[target path containing nested fla..]/Flash/"/>
<property name="forceBuild" value="true"/> <!-- param given to jsfl -->

<loadfile property="model_jsfl" srcfile="${model_jsfl_path}">
    <filterchain> 
        <expandproperties/>
    </filterchain>
</loadfile>
<!--build...jsfl-->
<property name="jsfl_file" value="${basedir}\jsfl\build_xml_clean_permit_debug.jsfl"/>
<!-- we clear the file-->
<echo file="${jsfl_file}"></echo>
<!-- we apped the model_jsfl--> 
<echo file="${jsfl_file}" append="true">${model_jsfl}</echo>


<!-- This task launches the compileSWF.jsfl script to compile Assets.swf using the Flash IDE -->
<target name="compile" description="Compile the demo1 SWF with the Flash IDE">
    <echo>using model ='${model_jsfl_path}'</echo>
    <echo>using jsfl command ='${jsfl_file}'</echo>
    <echo>---build.xml completed---</echo>
    <exec executable="${flash}" failonerror="true">
        <arg line="${jsfl_file}" /> 
    </exec>
</target> 

Here's the JSFL, its an assembly of stuff I found/did over the years...

clearASOCache ( fl.configURI + "Classes/aso" );


var tempDoc=undefined;
if(fl.documents.length==0){
    //xmlPanel need a document, if there is none, create a temp document
    tempDoc=fl.createDocument();
}

//Put ${param1} here
//Remove whiteSpaces?
var paths = "${paths}";
var folders=paths.split("\r").join("").split("\n").join("");
folders=folders.split(",");
fl.trace(folders);
//Build folders roots array
for(var i=0;i<folders.length;i++){
    if(folders[i].substr(0,8)!="file:///"){
        folders[i]="file:///"+folders[i].split(":").join("|").split("\\").join("/");
        fl.trace("format:"+folders[i]);
    }
    if(folders[i].substr(folders[i].length-1,1)!="/"){
        folders[i]=folders[i]+"/";
    }
}
fl.trace("folders="+folders);

//Build exportlist array
exportlist=new Array();
for(var j=0;j<folders.length;j++){
    checkFolder(folders[j],exportlist);
}

//Go trough exportlist
var totaltime=0;
if(exportlist.length==0){
    fl.trace("No file need to publish.");
}else {
    fl.trace("exportlist="+exportlist.join("\n"));
    fl.trace("Start publishing...");
    for(var i=0;i<exportlist.length;i++){
        fl.trace("["+(i+1)+"/"+exportlist.length+"] "+exportlist[i].substr(exportlist[i].lastIndexOf("/")+1)+"\t@ "+exportlist[i].substr(0,exportlist[i].lastIndexOf("/"))+"");
        var t=exportswf(exportlist[i]);
        fl.trace("Completed in "+formatTime(t));
        totaltime+=t;
    }
    fl.trace("All done. Total time:"+formatTime(totaltime));
}





function clearASOCache( path ) {
  if (!FLfile.exists( path )) {
    fl.trace( path + "does not exist" );
    return;
  }
  FLfile.remove( path );
}
function formatTime(num){
    var h=Math.floor(num/3600000);
    num=num%3600000;
    var m=Math.floor(num/60000);
    if(m<10){
        m="0"+m;
    }
    num=num%60000;
    var s=Math.floor(num/1000);
    if(s<10){
        s="0"+s;
    }
    num=num%1000;
    return h+":"+m+":"+s+"."+num;
}
function exportswf(flapath,swfpath){
    var stime=new Date().getTime();
    var fla=fl.openDocument(flapath,true);
    if(swfpath==undefined){
        swfpath=flapath.substr(0,flapath.lastIndexOf("."))+".swf";
    }
    // call the method. In case there's
    // an error, trace it to the output window
    try {
        //replaceClassText("mx.flash.UIMovieClip","gm.flash.UIMovieClip");
        updateProfile(flapath);
    }catch(error){ 
        fl.trace(error); 
    }

    fla.exportSWF(swfpath,true);
    fla.close(false);
    var etime=new Date().getTime();
    return etime-stime;
}
function checkFolder(folder,list){
    fl.trace("folder="+folder);
    var flas=FLfile.listFolder(folder+"*.fla","files");
    for(var i=0;i<flas.length;i++){
        //fl.trace(flas[i]);

        var flatime=Number("0x"+FLfile.getModificationDate(folder+flas[i]));
        var swfname=flas[i].substr(0,flas[i].lastIndexOf("."))+".swf";
        var swftime=Number("0x"+FLfile.getModificationDate(folder+swfname));
        fl.trace(swfname+" "+flatime+" vs "+swftime);
        //$\{forceBuild}
        if(swftime<(flatime-100) || ("${forceBuild}" == "true")){
            list.push(folder+flas[i]);
            fl.trace(flas[i]);
        }
    }

    var flds=FLfile.listFolder(folder,"directories");
    for(var i=0;i<flds.length;i++){
        //fl.trace(i+" "+flds[i]+" of "+flds.length);
        checkFolder(folder+flds[i]+"/",list); 
    }
}
function updateProfile(flapath) {
    var xml, from, to, delta;
    // export the profile and read it in
    var pPath = flapath+".Profile.xml"; 
    fl.getDocumentDOM().exportPublishProfile(pPath);
    xml = FLfile.read(pPath);
    //fl.trace(xml);
    // override DebuggingPermitted to 0
    from = xml.indexOf("<DebuggingPermitted>");
    to = xml.indexOf("</DebuggingPermitted>");
    delta = xml.substring(from, to);
    xml = xml.split(delta).join("<DebuggingPermitted>0") 

    // write the modified profile and import it
    FLfile.write(pPath, xml);
    fl.getDocumentDOM().importPublishProfile(pPath);

    // save changes
    fl.saveDocument(fl.getDocumentDOM(), flapath);

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

I have almost more than 500 FLA files and currently publishing them through ANT+JSFL. The problem I am facing here is, FlashIDE crashes at a certain point and the point is not fixed. But it definitely crashes after publishing a part from the total lot of the files. Would like to listen, if anyone is finding any sort of crash experience while publishing through ANT and JSFL.

saumya
A: 

I use the Amethyst plugin for Visual Studio. Not only will it build multiple projects, it can detect the dependencies and only build what is necessary.

Jason King