Fuel ANT Tasks

At Fuel Industries our projects always start with a FLA, but we use FDT for all of our coding. We wanted to have a way that we could publish our projects from FDT as well as run daily automatic builds. This is easy when working with Flex because Flex has a command line compiler, but Flash doesn’t. So we wrote custom ANT tasks in Java that will allow us to publish fla’s in multiple ways.

Here are a few examples of some of the things you can do.

First you can simply compile fla’s

<target name="fla_publish">
	<flash>
		<fla file="${src}/redsquare.fla" build="publish"/>
		<fla file="${src}/bluesquare.fla" build="export" swf="${src}/bluesquare.swf"/>
		<fla file="${src}/greensquare.fla" build="test"/>
	</flash>
</target>

The fla task can take multiple different types of values for the build parameter – publish, test, and export.
publish will simply publish the file at the current settings set for the fla.
test will compile and run the swf in the Flash IDE. This is like hitting cmd-enter/ctrl-enter
export will export the swf. In order to use this mode you must specify a output swf file.

You can also publish and test Flash CS3 Flp files

<target name="flp_publish">
	<flash>
	     <flp file="${src}/fuelanttask.flp" build="publish"/>
	</flash>
</target>

If set the build mode to “test” it will look for the flp project default file and compile that project last and test the default file.
The nice thing about using the flp task is that if one of your files has a compile error, it will stop the build process and alert you of the error. This is different then the IDE as it just keeps compile the project and you won’t see if one of your files compiled incorrectly.

We have also created a task called buildnumbercommand. This task gets the local SVN revision number and inserts it into a BuildNumber.as file. This way we have the build number accessible in ActionScript and we are able to display it automatically in our files. For instance we place ours in the right click menu so our clients can see what version of the build they are looking at.

<target name="version">
	<buildnumbercommand path="${src}" />
</target>

The path parameter is the directory in which the BuildNumber.as file is located. Below is an example of BuildNumber.as

package
{
	public class BuildNumber 
	{
		public static const BUILD_NUMBER : String = "1";
	}
}

Here are some of the other parameters for the Tasks

flash task

path – This is needed on Windows only. This is the path to your Flash IDE executable and is defaulted to the default install location for CS3 and CS4. C:\Program Files\Adobe\Adobe Flash CS3\Flash.exe and C:\Program Files\Adobe\Adobe Flash CS4\Flash.exe. If you have the Flash IDE installed in these locations you can omit this parameter.

version – accepts either “CS3″ or “CS4″. The default is “CS3″. This is used to determine which IDE to compile your files in. “CS3″ is the default and can be omitted if you want to use CS3.

deleteaso – true | false will delete your aso files before compiling any files. The default is false.

closeDocs – true | false will close your fla after it’s compiled. The default is false. This is ignored when compiling a flp project and will always close it afterwards.

quit – true | false will close the Flash IDE after all the files have been compiled.

verbose – true | false has some more output messages during compilation.

fla task

file – the path to your fla file

build – valid values are “export”, “publish”, “test”. The default is “publish”.
publish will simply publish the file at the current settings set for the fla.
test will compile and run the swf in the Flash IDE. This is like hitting cmd-enter/ctrl-enter
export will export the swf. In order to use this mode you must specify a output swf file.

swf – the file path to a swf to be compiled. This is only needed when the build parameter is set to “export” and will be ignored otherwise.

flp task

file – the path to your flp file

build – valid values are “export”, “publish”, “test”. The default is “publish”.
If set the build mode to “test” it will look for the flp project default file and compile that project last and test the default file.

UPDATE : the ANT tasks have been put up on Google code. The source, examples, documentation, and the compiled jar can be found there

http://code.google.com/p/fuelanttasks/

This is a video of me showing how to use them at Flash On The Beach during the speaker throwdown

FOTB09 – Jam Throwdown – Julian Dolce from John Davey on Vimeo.

Continue reading » · Rating: · Written on: 09-23-09 · 23 Comments »

Fix Textfields JSFL

Today Seb was having some issues when dealing with embedded fonts – read his post. He came up with some ActionScript ways to get around it. Well another way would be to use JSFL. A couple of my team members at Fuel Industries wrote the following JSFL script. It goes through your library and searches out any dynamic textfields. Once it finds one it makes sure it’s on a whole pixel, turns the auto kern off, embeds “UpperCase, LowerCase, Numerals, Punctuation” characters, and makes it not selectable. But you could make it do pretty much anything you can through JSFL.

fl.outputPanel.clear();
scanLibrary(fl.getDocumentDOM().library);
 
 
 
function getIsWholeInt(n)
{
	var s = String(n);
	if(s.indexOf(".") != -1)
	{
		return false;
	}
	else
	{
		return true;
	}
}
 
function round(n)
{
	var s = String(n);
	var a = s.split(".");
	var num = parseInt(a[0]);
	var dec = parseInt(a[1].substr(0, 1));
	if(dec >= 5)
	{
		num++;
	}
	return num;
}
 
/**
 * Scans the supplied flash library for linked classes and makes sure the textfields are set up properly
 * @param 	library		A flash library to scan.
 */
function scanLibrary(library)
{
    var items = library.items;
    var item;
	var replaceCount = 0;
 
    for( var i = 0; i < items.length; i++ )
    {
        item = items[i];
		if (item.itemType == 'movie clip') 
		{
			var timeline = item.timeline;
			var h = timeline.layerCount;
 
			library.selectItem(item);
			library.editItem();
 
			while(h--)
			{
				var k = timeline.layers[h].frameCount;
 
				while(k--)
				{
					var j = timeline.layers[h].frames[k].elements.length;
 
					while(j--)
					{
						var elems = timeline.layers[h].frames[k].elements;
						var p = elems.length;
 
						while(p--)
						{
							if(elems[p].elementType == "text" && (elems[p].textType == "dynamic" || elems[p].textType == "input"))
							{
								//Change the Static Text Fields to Dynamic
								if(elems[p].textType == "static") {
									elems[p].textType = "dynamic";
								}
 
								//Handle all Dynamic TextFields
								if(elems[p].textType == "dynamic") {
									//Remove the ability to be selectable
									elems[p].selectable = false;
								}
 
								//Handle all Dynamic or Input Textfields
 
								//Remove the auto kern attribute
								elems[p].setTextAttr('autoKern', false);
								//Embed fonts UpperCase, LowerCase, Numerals, Punctuation
								elems[p].embedRanges = "1|2|3|4";
 
								//Pop onto whole pixel
								var matX = elems[p].matrix;
								var x = matX.tx;
								if(!getIsWholeInt(x))
								{
									matX.tx = round(x);
									elems[p].matrix = matX;
								}
 
								var matY = elems[p].matrix;
								var y = matY.ty;
								if(!getIsWholeInt(y))
								{
									matY.ty = round(y);
									elems[p].matrix = matY;
								}
 
							}
						}
 
					}
 
				}
			}
		}
    }
}
Continue reading » · Rating: · Written on: 08-24-09 · 4 Comments »