If you have already setup your Flex 2 project in Eclipse (either w/ the Flex Builder Plugin OR Flex Builder itself) and you did not select any form of data services, then you will notice that the properties on the project under Flex Server will be disabled and you cannot change them. Why can’t you add data services later? Who knows! Maybe it will be easier in a later release, but here is a way to do it for now.

Step 1
Go to you project’s root directory and open the .flexProperties file. Inside that file you will notice that flexServerType will be set to “0″. Here is what it looks like before we change it:

<?xml version=”1.0″ encoding=”UTF-8″?>
<flexProperties flexServerType=”0″ toolCompile=”true” version=”1″/>

Change the “0″ to a “2″. The file will now look like this:

<?xml version=”1.0″ encoding=”UTF-8″?>
<flexProperties flexServerType=”2″ toolCompile=”true” version=”1″/>

Now when you reopen your project, the boxes on the Flex Server properties will be enabled. The two boxes will set the values serverRoot and serverRootURL in the .flexProperties file. The serverRoot value is set to the webapp folder of your project source. It will be looking for the WEB-INF sub-folder within this value. The serverRootURL is the url to the debug version of the SWF that the project’s main mxml file will generate.

Step 2
This is possibly the next gotcha. You may not be generating a debug version of your flex project. There are several ways to get this done. I will cover a few options for the way that most of my flex projects are setup. If you are setting up your flex project differently, then you should still be able to use these concepts to get yours working.

Option A
Inside your <project>-config.xml file for your flex project, there is a parameter under compiler that says

<debug>false</debug>

You can set this to true and then this project will be automatically compiled as a debug SWF. This setting could also be changed in your flex-config.xml file that is in your flex 2 source, then ALL projects will be compiled with the debug information included. One drawback here is that you will have a larger sized SWF, and you may forget to switch this back before deploying it to a production server. You may not want the bloated sized SWF deployed for production.

Option B
You can leave the setting in the <project>-config.xml file set to false for debug, but make a change to your maven files to compile the extra debug SWF. A few more options here. The mxmlc.exe flex compiler can only compile a single mxml file right now. So you will need to either have maven loop through all project files that need to be built, OR setup different targets for each one you want compiled. Here is a maven script that compiles two separate SWF’s.

<goal name="mxmlc">
  <ant:exec executable="c:\flex2\bin\mxmlc.exe" failonerror="true">
    <ant:arg value="${maven.build.sourceDirectory}/flex2/<project>.mxml"/>
  </ant:exec>

  <ant:exec executable="c:\flex2\bin\mxmlc.exe" failonerror="true">
    <ant:arg line="-debug=true -output ${maven.build.sourceDirectory}/flex2/<project>-debug.swf"/>
    <ant:arg value="${maven.build.sourceDirectory}/flex2/reportal.mxml"/>
  </ant:exec>
</goal>

The first ant:exec compiles the standard SWF without debug information. The second compiles WITH debug information. You can see that the second target has the extra “ant:arg line” in it as well. This is because you can’t put the arguments on the executable properties, nor can you add it to the parameter value where the project’s mxml is listed. Remember that you have to replace <project> in this maven xml file with your project’s name. In this example it isn’t a dynamic parameter, but you can change that if you want.

This now compiles both types of SWF, so the debug version is available for the serverRootURL above.

Recommendation: I would change your maven files so that you have two different targets, one for building a debug version and one for building a non-debug version. This way you don’t have to wait for two versions to be compiled each time you build the project.

Posted: November 4, 2006, 6:09 am by Brian Radford

Respond to this post or Trackback Link

So far none to this article

  1. So far no posts

Add your own post

You must log in in order to be able to contribute.



RSS 2.0-Feed for the comments to this article.