Using Flex Hero SDK with FlexBuilder 3

Trying to compile a library project requiring Flex 4.0+ (or Hero) SDK in FlexBuilder 3 should be straightforward: just point Flex to the new SDK. However, like many things Flex, this simple task yields an error:

“unable to open ‘/Applications/Adobe Flash Builder Burrito/sdks/4.5.0/frameworks/libs/player/9.0”

The key is to add a compiler argument like: “-target-player=10.1". For library projects, we have to set a compiler argument since the Flex GUI does not allow for specifying flash player versions.

Check out this post for the full directions: http://opensource.adobe.com/wiki/display/flexsdk/Targeting+Flash+Player+10

Flex safely checking if XML attribute exists

I’ve often faced the issue of having to use an XML attribute that may not always be present. I wanted to ensure I don’t receive any NullPointerExceptions trying to parse an attribute that’s not there, so here’s a quick and easy way to check.


var xmlNode:XML = <node attr1="this is a test"/>
if (String(xmlNode.@attr1).length > 0)
trace("Attr1 exists");
else
trace("No Attr1 exists");

Flex application not downloading web-service data

I find this issue happening over and over, seemingly at random. I deploy a Flex application locally, which uses web-services, and eventually it stops connecting to web-services it uses after a couple of days of using the application. Note, it does not stop working within a session of the application, but instead will stop contacting web-services after a refresh or redeployment of the application. Before I knew what was going on, this made me think the web-services were not working, or JMS suddenly became inaccessible; however, it turned out there was some strange browser caching issue going on. I had to quit the browser (shut down the process) and restart the browser for the Flex application to start working. Refreshing the application within the browser does not do the trick.

My setup:

  • Snow Leopard 10.6
  • Firefox 3.6.13
  • Flash Player 10 debugger version
  • Tomcat 6

Solution:

  • Restart tomcat
  • Redeploy web-application
  • Shutdown and restart web-browser

Flex ComboBox not updating when dataProvider updates

This is something that should work in Flex, but it is not because of some internal bug.

I had a ComboBox binded on an Array of items. Sometimes it would update the ComboBox whenever a new item was added, and sometimes it would not. The behavior just wasn’t very consistent.

There are many posts about this, but the short solution I tried was to just use an ArrayCollection() instead of an Array() as my binded source. Also, whenever I updated the ArrayCollection, I called the “refresh()” method for the ArrayCollection and also called the “validate()” method for the combobox. Try those three and see what happens!

Flex checking if an XMLList contains a child node value using E4x

This is a simple question that took me a while to figure out. I know I can just loop through the contents of an XMLList and check manually if a certain child node’s value exists or not; however, I wanted a simple one-liner.

Here’s an example:

Description:

I want to find out if the string “JACKPOT” is contained within the child node value of this XMLList:

XMLList:

var list:XMLList =

<>

<Item>

<SubItem>123</SubItem>

</Item>

<Item>

<SubItem>JACKPOT</SubItem>

</Item>

<Item>

<SubItem>123</SubItem>

</Item>

</>;

E4x code (returns true or false if exists):

list.child("Item").(text().toString() == "JACKPOT").length() != 0

Do you need to recompile Flex apps when you change messaging-config.xml?

Apparently Flex apps contain an “embedded” portion of BlazeDS config files that they are compiled against. This means that a recompile is necessary whenever you choose to change BlazeDS config files like messaging-config.xml etc. If this is the case, what is the point of separating confi information externally if it is compiled into the application anyway?

Direct quote from Adobe:

“The destination and channel information is available to the client as a result of compile-time access to the XML configuration, which the server uses to manage services at runtime and the compiler uses to embed a portion of the configuration into the client.”

See: http://www.adobe.com/devnet/flex/articles/intro_fms_04.html

Iterating through an associative array in Flex

Always use an Object() type for an associative array. Do not use the Array() form of an associative array, as it has no inherent advantages, and doesn’t work well with iteration.

Moreover, if you are trying to iterate through an associative array of type Object(), remember the following:

Does it work? (YES):

for (var key:Object in myAssocArray) {

Alert.show(key + “ = “ + myAssocArray[key]);

}

Does it work? (NO):

for each (var key:Object in myAssocArray) {

Alert.show(key + “ = “ + myAssocArray[key]);

}