One of our projects uses Flex 2 for our presentation layer. We were using Flex builder as the IDE to build the flex components, packaged it with the rest of the J2EE application as war and deployed it. As a practice with rest of the projects we wanted a build automation done in place for continuous integration, as well as saving time building and deploying it to different environments. We could get the ant scripts ready within no time for the J2EE piece of it as it was straightforward and we have done it numerous times. As far as flex goes even though flex ant tasks are available with documentation it wasn’t that easy for us to get things built as flex builder would do it. Sure the ant tasks built the swf files but when we deployed the application on the server we always got this error “RSL Error 1 of 1″ and nothing beyond that. Searching this error resulted in different reasons but nothing concrete in nature.
To be more exact, our application consisted of a Flex model folder containing action scripts common across the other Flex modules. So this had to be set as a run time shared library (RSL) rather than packaging it along with other modules. Packaging with other modules would make it work, but it becomes bulky and performance degrades because the model classes are loaded for each Flex package. To make it a RSL while building the flex components, the model has to be referred as RSL using the attribute in the task. We did this but only got the error mentioned above “RSL Error 1 of 1″. We were clueless at this point and tried out combination of attributes while compiling using mxmlc.
Our only hope remained in identifying what makes the build done by the flex builder make it work and the difference between the parameters it uses and what we use. We knew this because the size of SWF generated out of a Flex builder build was very different from the size that came out of our ant build. Because the build properties are GUI based, how to get what configuration flex builder uses and how it translates to the appropriate compiler options? After exploring the available compilation parameters with mxmlc, we found out the parameter -dump-config would dump the configuration used in a file. We added this parameter to the compiler parameters in the Flex compiler options as shown below in the screen.
We compared the configuration that flex builder used versus what we had been using in the mxmlc task, only to find out there wasn’t much difference except for few of the compile time properties which was also present in the flex.config file we were using. The same RSL attribute was present making the model package as reference. We were back to square one wondering what could be the difference and what we are missing. After two days of struggle, a careful re-examination of the configuration in Flex builder when referring the model package in other packages revealed something. Take a look at the snapshot below.
The “Auto extract swf: true” was something that we could not find a translation when using the compc ant task and we could not find any documentation mentioning this in the flex ant tasks documentation. We were able to confirm that something is happening here again because of the size difference between what Flex builder generated versus what our ant build generated. There must be a way to produce the package exploded rather than having it packaged as one SWF, just like an exploded war file. Fortunately there was option to do this with the compc task when the directory attribute is set to true and the output attribute holds a directory value. When we were able to do this everything got revealed. Here is a snapshot of the directory structure.
A look at the files that got generated told us that the SWF that contained the model was having a name of “library.swf”, and when this directory was packaged and added as RSL, there is a mismatch in the reference. The flex runtime binary is looking for MyModel.swf while the only file present is library.swf. That should be the reason for the RSL Error. Also the size when Flex builder built the package was exactly equivalent to the size of the library.swf file present above. So that answers what “Auto extract swf: true” configuration does.
So our ant script was ready, we used one compc task to generate an exploded model directory. Picked the library.swf and copied it to the war with “MyModel.swf”. Another compc task to generate the model packaged so that we can refer it only for compilation for other flex models. Once we did this, everything worked perfectly. So here is the sample ant code (right click and save as, then open in an editor) that made the trick.
Hope this is useful for someone struggling with similar situation and it saves the head cracking time. If someone has found out an easier approach to this please pass that on, we would be happy to learn.