July 27, 2012

Flattening Hierarchical Data

Posted by Jeremy Mitchell
I'm not a big fan of hierarchical data structures. They can be a pain. For example, I hate having to perform recursive loops to find matching elements.

Unfortunately, many UI controls require hierarchical data (i.e. the Tree component) and sometimes it is unavoidable.

Therefore, if hierarchical data is required, I like to "flatten" the hierarchical data and maintain two data structures - a hierarchical one and a flat one. Flat data structures are much easier to navigate and thanks to the power of object references, each data structure contains references to the same objects so updating an object in the flat data structure also updates it in the hierarchical data structure.

To demonstrate, imagine we have a hierarchical data structure that looks like this:

- Object A
-- Object B
--- Object C

We can use that hierarchical data structure for the Tree component, but, to make our lives easier, let's create a flat data structure (i.e. Array or ArrayCollection) to hold the same objects:

- Object A
- Object B
- Object C

Searching and updating objects in the flat data structure will prove to be much easier.

Here's a example to demonstrate this technique. View source is enabled.

January 3, 2012

Testing for a Flash Builder Pro License

Posted by Jeremy Mitchell
Certain features of the Flex SDK require a valid Flash Builder Pro license to function properly. Examples include charting and automation. For example, if you compile a SWF without a valid Flash Builder Pro license, you'll get the following results:


Charts compiled without a Flash Builder Pro license contain a watermark.


Test automation tools (i.e. FlexMonkey) that interact with a SWF compiled without a Flash Builder Pro license will trigger a "License not present. With the trial version only limited records are allowed" error.

A Solution

To avoid these results, simply enter a valid Flash Builder Pro license into Flash Builder and compile your SWF using Flash Builder. Duh.

A Catch

Most enterprise applications are not compiled using Flash Builder. Instead, the build process directly utilizes the command-line compilers, MXMLC and COMPC, in tandem with Ant or Maven. In this scenario, the Flash Builder Pro license key must be entered into the configuration file (flex-config.xml):

            <serial-number>xxxx-xxxx-xxxx-xxxx-xxxx-xxxx</serial-number> <!-- this is my 4.5 license key -->

Another Catch

When using Ant or Maven, you may find out that your Flash Builder license will NOT work for all Flex SDKs. For example, a Flash Builder 4 license will not activate charting or automation for the Flex 4.5 SDK...but it will for the Flex 4.1 SDK. (see related StackOverflow post)

Testing for a valid Flash Builder license

Well, one way to ensure that a valid Flash Builder Pro license was compiled into your SWF is to simply check out your charts or your automation scripts. For charts, if there are no watermarks, you're good. For automation, if you don't get the "license not found" error, you're good. But, for automation, this can potentially get tedious.

A quick way to test that a valid Flash Builder license has been compiled into your SWF involves 2 classes, one super secret metadata tag and a trace statement. Check out this simple app to see how this is done (view source is enabled):