Friday, January 23, 2009

Different ways of forcing Flex to compile a class

As a user of Spring Actionscript I have, of course, run into the problem of classes not being compiled into the swf file.

When you have defined an object in the Spring AS configuration, but there's not direct reference in your source code to the class, the Flex compiler will optimize the class out of the swf and you end up with runtime errors such as this:


a class with the name 'x.y.z' could not be found


So far I know of three different ways to tackle this problem:

1. Add dummy variables in your source code like this:



privare var _dummy1:MyClass;
privare var _dummy2:MyOtherClass;



2. Add a Frame tag for each class you want to be included to one dummy class, and include only that dummy class. Code would look like this:



package com.myclasses
{
[Frame(extraClass="com.myclasses.MyClass")]
[Frame(extraClass="com.myclasses.MyOtherClass")]
public class MyDummyClass
{
}
}



3. Use a bit of XSLT, an ANT script and add this a builder in FlexBuilder. I have posted a PDF with a how-to on the springsource forums over here:

Spring Actionscript forum post

Hopefully in the future there will be a more elegant way of forcing certain classes to be included, but until then, pick one of these solutions.

No comments:

Post a Comment

About Me

My photo

Co-Owner at Stack & Heap (http://www.stackandheap.com)
Lead developer for the Spring Actionscript (http://www.springactionscript.org) and AS3Commons (http://www.as3commons.org) projects.
I like noise.