Home > ColdFusion, Flex, code > Problem solved transferring typed objects to Flex

Problem solved transferring typed objects to Flex

I really do like using the struct method of transferring typed objects from ColdFusion to Flex. However, today I ran into an issue when passing them to Flex from ColdFusion.

I had been following along with Dan Vega’s posts on RocketFM, and I decided to download the code and tinker with it (as all good little programmers should :) ). I had added a FileInfo VO to Flex and one to ColdFusion. Then within the FileManager object, I was returning the newly typed object ( temp['__type__'] = “RocketFM.src.org.vega.FileInfo”; ). However, every time I returned the the data, I kept getting a plain, ol’ generic object. On to the debug steps:

I had recently removed my CF7 install, so I thought that maybe that had messed something up within my CF8 install. I restarted my CF instance ( a couple of times in the end), turned various settings on and off, all to no avail. I tried changing where I was pointing my CFC and my aliasing of them, but everything seemed to be correct there also. I then fired up an old project that I had previously used that I knew was returning typed objects. I ran it through the debugger, and lo and behold…typed objects still. So, I ruled out CF as being the problem (I’m using the same instance across all of my projects…not the best method, but until I get more than 5 different CF projects I’m working on, I should be ok)

I then decided it must be something on the Flex side of things. I got distracted with something else, and just as my mind had begun to relax, the solution hit me…I haven’t included the FileInfo class in my project anywhere (queue head slapping moment). Flex only includes classes that are referenced somewhere in the project, even though the VO was included in the project directory structure, I was not referencing it anywhere in the code (as all I cared about at first was that the data would be returned as typed objects). I then added the import statement and created a private variable that would all me to just reference the VO in Flex. Once this had been added, the typed objects were returning like champs back to the Flex project. A somewhat simple solution in the end, but unless you’re actually thinking about it, very easy to overlook as well.

  1. January 14th, 2009 at 14:09 | #1

    You can also use the Frame metadata tag:

    [Frame(extraClass="org.vega.FileInfo")]

    just make sure you use the full package name in Flex

  2. Gareth
    January 14th, 2009 at 15:26 | #2

    Hmm…hadn’t seen that one used before. So (after poking around a bit), I guess you just drop all of the classes in your application mxml page? Flex then knows to include those classes in the compiled code. I guess a benefit is that you don’t unnecessarily instantiate a class in your code. Any other reason for doing it this way?

  3. Gareth
    January 14th, 2009 at 16:25 | #3

    Looking at the documentation again, I’m not sure where the Metadata stuff goes. Is it in the class itself, and thus Flex “knows” to include that class in your build? I just haven’t been able to find anything specific about where to include the “Frame” information.

  4. January 14th, 2009 at 21:15 | #4

    It’s an undocumented tag. You should be able to define a tag as a child of the tag and drop all your Frame metadata tags in there.

    See:
    http://livedocs.adobe.com/flex/2/langref/mxml/metadata.html

  5. January 14th, 2009 at 21:23 | #5

    One last note, the above code I gave does the same as specifying the ‘includes’ option to the compiler, but allows you to have it right in your code instead of in a build script somewhere.

  6. November 11th, 2009 at 15:22 | #6

    OK. That saved the day for me! Thank you very much.

  7. Gareth
    November 11th, 2009 at 16:08 | #7

    Glad to help. This one has been a frustration for me on a couple of occasions (after I forget that I really *do* know what the issue is :) )

  1. No trackbacks yet.