Since the release of Beta 2, I have been playing with Flex 2 and AS3 whenever I've had spare moments. Most of my tinkering has been focused around calling SOAP web services as that is what is most applicable to my current work situation. A problem I kept running into was that the data returned contains default namespaces (i.e. no prefix, just xmlns="yaddayadda"), and at present there is a dearth of information on working with them. Long story short, you must specify which namespace you want to use for each and every operation, unless you use this approach:

namespace foo = "http://site.com/foo";
use namespace foo;

I really didn't like the idea of having those directives scattered about in my app, in every file that needed to work with my XML data. Today, guided by an initial tip from Brian, I've got it working. This is more or less a direct implementation of the examples shown in the docs applied to XML, rather than methods.

What follows is my initial take on how to approach the use of several namespaces in a Flex 2 application that uses the Cairngorm framework. I am a Flex and Cairngorm noob, so if someone has suggestions on a better structure, I am all ears. The approach is based around creating package-level namespace files, that you can then import into wherever you need them.

Here is a sample namespace file:

package com.fmr.nstest.business.namespaces
{
    public namespace CLIENT_MEASURES_NAMESPACE = "http://site.com/BackOffice/CMeasures";
}

I decided the most logical place to put these files was in a 'namespaces' package inside the 'business' package, which is where my Delegates and Services.mxml file reside. I am defining them in all caps since they are more or less constants. You can only define one namespace per file, however, because there can only be one externally accessible definition per file in AS3. Using these files is pretty straightforward as well. Simply import the file (it will not show up in the auto-complete list in Flex Builder) and then insert your use namespace directive where appropriate:

import com.fmr.nstest.business.namespaces.CLIENT_MEASURES_NAMESPACE;
...
use namespace CLIENT_MEASURES_NAMESPACE;

This approach is flexible in that if you put the use namespace directive before your actual class declaration starts, it can essentially be used as the default namespace for all the methods of your class. On the other hand, you could also import everything (*) from your namespaces package and place different use namespace directives in your methods so that they can address different sets of data.