I am trying to pass a simple VO from CF to Flex with Flash remoting,
but I can't seem to make it work. ServiceCapture shows a correctly
typed object in the response, but Flex won't let me cast it as such. 
What am I missing here?

http://coldfusion.pastebin.com/f36d7abbd

TestVO.as:

package vo
{
        [RemoteClass(alias="components.test.TestVO")];
        [Bindable]
        public class TestVO
        {
                public var value1:String;
                public var value2:String;
                public var value3:String;
                public var value4:String;
                
                public function
TestVO(value1:String="",value2:String="",value3:String="",value4:String="")
                {
                        this.value1 = value1;
                        this.value2 = value2;
                        this.value3 = value3;
                        this.value4 = value4;
                }

        }
}





TestVO.cfc:

<cfcomponent output="false" alias="components.test.TestVO">
        <!---
                 These are properties that are exposed by this CFC object.
                 These property definitions are used when calling this CFC as a 
web
services, 
                 passed back to a flash movie, or when generating documentation

                 NOTE: these cfproperty tags do not set any default property 
values.
        --->
        <cfproperty name="value1" type="string" default="">
        <cfproperty name="value2" type="string" default="">
        <cfproperty name="value3" type="string" default="">
        <cfproperty name="value4" type="string" default="">

        <cfscript>
                //Initialize the CFC with the default properties values.
                variables.value1 = "";
                variables.value2 = "";
                variables.value3 = "";
                variables.value4 = "";
        </cfscript>

        <cffunction name="init" output="false" returntype="TestVO">
                <cfreturn this>
        </cffunction>
        <cffunction name="getValue1" output="false" access="public"
returntype="any">
                <cfreturn variables.Value1>
        </cffunction>

        <cffunction name="setValue1" output="false" access="public"
returntype="void">
                <cfargument name="val" required="true">
                <cfset variables.Value1 = arguments.val>
        </cffunction>

        <cffunction name="getValue2" output="false" access="public"
returntype="any">
                <cfreturn variables.Value2>
        </cffunction>

        <cffunction name="setValue2" output="false" access="public"
returntype="void">
                <cfargument name="val" required="true">
                <cfset variables.Value2 = arguments.val>
        </cffunction>

        <cffunction name="getValue3" output="false" access="public"
returntype="any">
                <cfreturn variables.Value3>
        </cffunction>

        <cffunction name="setValue3" output="false" access="public"
returntype="void">
                <cfargument name="val" required="true">
                <cfset variables.Value3 = arguments.val>
        </cffunction>

        <cffunction name="getValue4" output="false" access="public"
returntype="any">
                <cfreturn variables.Value4>
        </cffunction>

        <cffunction name="setValue4" output="false" access="public"
returntype="void">
                <cfargument name="val" required="true">
                <cfset variables.Value4 = arguments.val>
        </cffunction>

</cfcomponent>





TestRO.cfc:

<cfcomponent>
        <cffunction name="getTestVO" returnType="components.test.TestVO"
access="remote">
                <cfscript>
                        testVO = CreateObject("component", 
"components.test.TestVO");
                        testVO.init();
                        testVO.setValue1("AAAA");
                        testVO.setValue2("BBBB");
                        testVO.setValue3("CCCC");
                        testVO.setValue4("DDDD");
                        return testVo;
                </cfscript>
        </cffunction>
</cfcomponent>





main.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute">
        <mx:Script>
                <![CDATA[
                        import vo.TestVO;
                        import mx.rpc.remoting.RemoteObject;
                        import mx.rpc.events.ResultEvent;
                        import mx.rpc.events.FaultEvent;
                        import mx.controls.Alert;                       
                        
                        [Bindable]
                        public var testVO:TestVO = new TestVO();
                        
                        public function getTestVOHandler(event:ResultEvent):void
                        {
                                testVO = event.result as TestVO;
                        }
                        
                        public function faultHandler(event:FaultEvent):void
                        {
                                Alert.show(event.toString());
                        }
                        
                ]]>
        </mx:Script>
        
        <mx:RemoteObject id="testRO" destination="ColdFusion"
source="components.test.TestRO">
                <mx:method name="getTestVO" result="getTestVOHandler(event)"
fault="faultHandler(event)"/>
        </mx:RemoteObject>
        <mx:Panel x="10" y="10" width="380" height="280" layout="absolute">
                <mx:Button x="147" y="208" label="Button" 
click="testRO.getTestVO()"/>
                <mx:Label x="10" y="10" text="Value 1:" fontSize="16"
fontWeight="bold"/>
                <mx:Label x="94" y="10" text="{testVO.value1}" fontSize="16"/>
                <mx:Label x="10" y="42" text="Value 2:" fontSize="16"
fontWeight="bold"/>
                <mx:Label x="94" y="42" text="{testVO.value2}" fontSize="16"/>
                <mx:Label x="10" y="74" text="Value 3:" fontSize="16"
fontWeight="bold"/>
                <mx:Label x="94" y="74" text="{testVO.value3}" fontSize="16"/>
                <mx:Label x="10" y="106" text="Value 4:" fontSize="16"
fontWeight="bold"/>
                <mx:Label x="94" y="106" text="{testVO.value4}" fontSize="16"/>
        </mx:Panel>
        
</mx:Application>

Reply via email to