Adding a classpath to the Flash IDE using JSFL

MXP files can place classes most anywhere on the user’s computer, but in order to make Flash able to use them, you need to add the classpath to either the FLA or to the IDE. The IDE is preferable, in my opinion, since you only have to add it once and it works for all files. This is how you do that using JSFL.

MMExecute(
	"var found = false;" +
	"var paths = fl.as3PackagePaths.split(';');" +
	"for(var i = 0; i<paths.length; i++){" +
	"	if(paths[i] == '$(LocalData)/myClasses'){" +
	"		found=true;" +
	"	}" +
	"}" +
	"if(!found){" +
	"	paths.push('$(LocalData)/myClasses');" +
	"	fl.as3PackagePaths = paths.join(';');" +
	"}" );

What are we doing?

  • First, we set a variable to determine if we already have this classpath in our list (multiple classpaths of the same location can make Flash crash instantly)
  • Next, we take the semicolon-delimited string from fl.as3PackagePaths and assign it to an array variable.
  • Then we loop through this array looking for a match for our classpath. In my case, I’ve chosen to use a classpath variable, $(LocalData) that resolves to your Flash Configuration folder (Mac is /Users/UserName/Library/Application Support/Adobe/Flash CS4/en/Configuration)
  • If we find it, we set our found variable to true to indicate we shouldn’t add the path again.
  • Otherwise, we add the path to the array, convert it back to a string, and set the Flash IDE’s paths equal to it.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">