third

"It was not his fault he was a Third." - Enders Game
 blog | photos | videos | search | links

Using JSFL to Verify Flash Art

 ||  blog  || 

February 4, 2010

This is a quick overview of how to create a JavaScript Flash (JSFL) script that uses the DOM to verify artwork in a Flash fla file. The best reference I have found for JSFL is the Extending Flash PDF provided by adobe. You have to make sure when running the script lets say our script is called VerifyArt.jsfl, that it is run with the fla on the main timeline.

First I want to check my AS version, and then the Stage sizes of the fla to verify it will work if loaded into my application.

// Check AS version
if (fl.getDocumentDOM().asVersion > 3) { 
	passed = false;
	msg += "\r\t - File needs to published in AS3, Flash CS3  " ;
}

This verifies if the file is AS3 or not. First we get the DOM with fl.getDocumentDOM() then we look at the ActionScript version of the document with fl.getDocumentDOM().asVersion. If you are wondering what the passed and msg variables are we will go over it at the end. Mainly these are just our variables that we output when saying pass/fail on the script.

var stageH = fl.getDocumentDOM().height;
var stageW = fl.getDocumentDOM().width;

This gets the height and width to verify with the following code.

// Check stage width & height.
if (stageW != 550)
{
	passed = false;
	msg += "\r\t - Base Layer width is incorrect. Base layer width should be 550 pixels.";
}
if (stageH != 345)
{
	passed = false;
	msg += "\r\t - Base Layer height is incorrect. Base layer height should be 345 pixels.";
}

Now we have verified the size of the fla stage. Next lets output our response to the user.

// Output the report
if (passed ) { 
	fl.trace("\rPASSED! " + warning);
} else {
	fl.trace("\r\rFAILED " + msg + "\r" + warning);
}

And here is the finished script. Simple yet effective.

/* VerifyArt.jsfl - Script to verify ActionScript version and stage size. */

var stageH = fl.getDocumentDOM().height;
var stageW = fl.getDocumentDOM().width;
var msg = "";			// Validation message	
var warning = "";		// Warning
var passed = true;		// Validated?

// Check AS version
if (fl.getDocumentDOM().asVersion > 3) { 
	passed = false;
	msg += "\r\t - File needs to published in AS3, Flash CS3  " ;
}

// Check stage width & height.
if (stageW != 550)
{
	passed = false;
	msg += "\r\t - Base Layer width is incorrect. Base layer width should be 550 pixels.";
}

if (stageH != 345)
{
	passed = false;
	msg += "\r\t - Base Layer height is incorrect. Base layer height should be 345 pixels.";
}

// Output the report
if (passed ) { 
	fl.trace("\rPASSED! " + warning);
} else {
	fl.trace("\r\rFAILED " + msg + "\r" + warning);
}

Download VerifyArt.jsfl

Related tags: fla, flash, javascript, jsfl

Leave a comment

captcha