Release mode, describeType(), and keep-as3-metadata

This post was written by jimrobson on September 26, 2012
Posted Under: Flex

The previous post outlined an issue that we faced as a result of the fact that describeType() outputs more information when the SWF is compiled in debug mode than when it is compiled in release mode. This post provides a couple of possible solutions.

Solution 1: Compiler Option

The first solution was referenced in a helpful comment by Simon Gladman: the keep-as3-metadata compiler option. The ArrayElementType metadata is retained in the release SWF by adding this snippet to the compiler options:


Notice the += operator. This is to ensure that the default metadata is also retained. According to the documentation, the = operator would cause the default metadata to be replaced. I was not able to confirm this in my testing, but nonetheless += is more intuitive as well as perhaps being safer.

Here is a snapshot of the compiler option in Flash Builder:

Keep AS3 Metadata Compiler Option in Flash Builder

Keep AS3 Metadata Compiler Option in Flash Builder

You can see a demo of the above solution running here. To see the difference, you can see the original version (without the compiler option) here.

Solution 2: XML

The second solution, which is the one that was implemented in our project, was to add the data type to the schema for the XML that stores the screen layouts, widget configurations, and service calls. While this solution requires slightly more maintenance, it is more robust. For example, it allows us to use our own data type descriptors, such as guid. It also provides a safeguard against arbitrary code changes; if a developer changes the data type of one of these properties in the ActionScript, the application will break as soon as the developer runs it, thereby preventing it from being deployed with an error. If were to rely on the compiler option and describeType(), and the application were to be deployed without thorough regression testing, then the error might not appear until a user tried to open a previously saved screen or widget.

So, we created a set of enums in ActionScript to define the data types that may be stored in our XML configurations, and we use these enums rather than string literals to create the XML:

<property type={XMLDataTypes.GUID.key}>

Likewise, we use the enums when evaluating the data types when parsing the XML when it comes back from the server.

There are certainly other possible solutions, but either of the above will work.


Reader Comments


  1. Debug and describeType()  on September 26th, 2012 @ 5:13 pm