JSFL Script to Ensure Actual ActionScript Classes Exist for Symbols

One way to design or skin ActionScript 3 projects is using the Flash IDE for graphical assets.  You export your FLA as an SWC, and you can utilize those assets in your AS3 and/or Flex project.  Flash CS3/CS4/CS5 have the ability to link to an ActionScript 3 class that represents the code behind the Symbol.  If the Flash IDE doesn’t find the class in its source paths, it’ll create one for you.

The downside is, when you compile, you do not get errors if the Flash IDE didn’t find a class for a particular Symbol that’s set to have one.  Maybe you mis-typed the package path or class name.  Maybe you forgot to set the class path for the FLA.  Maybe the FLA is in the wrong place.  Whatever the reason, your code “won’t work” and you won’t know why.  You may not get code hints in Flash Builder / FDT / IntelliJ, and certain other dependencies may be missing as well and you’ll be left wondering why.

Flash CS5 Check ClassThe Flash IDE provides a check mark button next to the linkage class to allow you to confirm or deny Flash can find the class.  In a quick scan of the JavaScript for Flash docs, I could not find a way to use this button’s functionality in JSFL.  So, I wrote a quick script that does.

NOTE: I do not take source paths into account; I assume that the classes are in the same directory as the FLA’s.  You can easily change this by querying fl.getDocumentDOM().sourcePath, or just hardcoding your known path.

fl.outputPanel.clear();
fl.trace("*** Checking for un-found classes... ***");
var totalNotFound = 0;

var doc = fl.getDocumentDOM();
var lib = doc.library;
var items = lib.items;

var itemsLen = items.length;

for(var i = 0; i < itemsLen; i++)
{

	var item = items[i];
	/*
	fl.trace("--------------");
	for(var prop in item)
	{
		fl.trace(prop + "::" + item[prop]);
	}
	*/

	if(item.linkageExportForAS)
	{
		var className = item.linkageClassName;
		var classPath = className.split(".").join("/");
		var exists = doesClassExistOnDisk(classPath);
		if(exists == false)
		{
			totalNotFound++;
			fl.trace("Couldn't find class for '" + item.name + "', class: " + className);
		}
	}

}

if(totalNotFound == 0)
{
	fl.trace("*** DONE. All classes found.");
}
else
{
	fl.trace("*** DONE. " + totalNotFound + " classes not found.");
}

function doesClassExistOnDisk(classPath)
{
	var filename = classPath + ".as";
	var doc = fl.getDocumentDOM();
	var currentFolder = doc.pathURI.split(doc.name).join("");
	var fullURI = currentFolder + filename;
	//fl.trace("fullURI: " + fullURI);
	return FLfile.exists(fullURI);
}

On a side note, Dru Kepple has a lot of wonderful JSFL classes to help working with ActionScript in the Flash IDE, specifically the Document class.

One Reply to “JSFL Script to Ensure Actual ActionScript Classes Exist for Symbols”

Comments are closed.