Flex 4 Remote Object Method

6.5k Views Asked by At

I post this previously in Adobe Forum but haven't got any answers so far.

How do I do this in Flex 4?

 <mx:RemoteObject id="srv" destination="product" channelSet="{channelSet}"
 fault="faultHandler(event)">
   <mx:method name="getProducts" result="getProducts_resultHandler(event)"/>
 </mx:RemoteObject>

I got

Could not resolve <s:Method> to a component implementation.

When trying to do this

 <s:RemoteObject id="roMajor"
   destination="MajorSrv"
   fault="Alert.show('Remote Object Error')" >
     <s:Method name="AddMajor" result="roMajorResult(event)"/>
 </s:RemoteObject>

Thank you

1

There are 1 best solutions below

2
On BEST ANSWER

Move the <RemoteObject/> tag into <fx:Declarations> tag:

<fx:Declarations>
  <s:RemoteObject id="roMajor" destination="MajorSrv" 
    fault="Alert.show('Remote Object Error')">
      <s:method name="AddMajor" result="roMajorResult(event)"/>  
  </s:RemoteObject>
</fx:Declarations>

The following is taken from RIA Zone

In Flex 4, unlike its earlier versions, non-visual children that represent new property declarations are not allowed as immediate children of an Application. You can add these non-visual children under a <fx:Declarations> tag. This includes non-visual children such as effects, validators, formatters, data declarations, and RPC classes.

So practically anything that is not displayable (that doesn't extend DisplayObject (or UIComponent to be more flex specific)), should be added to the fx:Declarations tag, not as the direct child of root tag.