Archive

Posts Tagged ‘typed object’

Problem solved transferring typed objects to Flex

January 14th, 2009 Gareth 7 comments

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.