VO's with ColdFusion and Flex...gotcha!

Ok, so I was pulling my hair out last night trying to figure out why the value object that ColdFusion was returning was not casting to the value object on the Flex/Actionscript side.

I bet I ran the Flex debugger 100 times. Everything looked just fine. The object that was being returned from ColdFusion was typed correctly and had the correct data, but when I went to assign the object to the proper type in Flex, it would end up being null.

After a few hours of this, I decided to open a bottle of wine and call it a night. Nothing like a well rested pair of eyes to solve the problem.

After having no luck this morning, I had my friend, Kevin Kazmierczack take a look at my VO on the Flex side of things.










Before:

[RemoteClass(alias="openmetric.com.openmetric.cfc.vo.OpenMetricEventVO")]

import com.openmetric.as3.model.vo.OpenMetricEventTypeVO;

[Bindable]
public class OpenMetricEventVO
...

Kevin suggested moving the import statement above the meta data for the RemoteClass. Shazaam! It worked.

Now, I don't know if I'm just dumb and I missed this in Flex 101 and need to go back, or if this is just something you have to find out the hard way. I'm guessing it's the former, but who knows. However, swapping those two little lines of code to this made all my headaches go away:

After:

import com.openmetric.as3.model.vo.OpenMetricEventTypeVO;

[RemoteClass(alias="openmetric.com.openmetric.cfc.vo.OpenMetricEventVO")]

[Bindable]
public class OpenMetricEventVO
...

Anyone else ever run into this?

Comments
Dusty's Gravatar Meta-tags describe the next piece of actual code, so the remote class was attempting to describe the import statement. If you remember that it's a meta-tag, and treat it just like a [Bindable] tag, then you won't have any issues
# Posted By Dusty | 5/28/08 10:13 AM
Kevin Schmidt's Gravatar Thanks Dusty!
# Posted By Kevin Schmidt | 5/28/08 10:15 AM
Glenn Williams's Gravatar been caught out with this one myself also.

I almost gave up and thought it was a flex SDK error.

Was pure change that I found the problem. I was basically just making my code look nicer, just for something to do rather than pull my hair out, and then as you very rightly say 'Shazaam!'
# Posted By Glenn Williams | 8/31/08 9:38 AM
phigl's Gravatar Started to work on that problem on Monday, 06:30 and found solution on Thursday, 15:40!!
20Mins later im tapping over this article. Now i feel so proud of myself :D :D
..that this issue got me 50 more gray hair i am pulling out now, cause i wasnt googling properly!

But hey, this error is the most stupid thing ever happend in my flex life so far, though i can understand as i remember back lecture on "compiler construction" ;)
# Posted By phigl | 11/4/08 8:41 AM
Questions or comments? Feel free to email me at kevin.schmidt[at]flexinabox.com