I’ve used this many times and it saves a good amount of typing and time. I also believe it cleans up your app a bit…let me explain what I’m talking about then I’ll explain why.
bq. <mx:RemoteObject id=”ro” endpoint=”http://localhost:8080/MyService/messagebroker/amf” destination=”blah” showBusyCursor=”true”
This code merely points to the MyService app running on localhost, which is powered by BlazeDS/Spring. I changed a few names because this is work stuff. So, MyService has a DAO (data access object) which returns appropriate data, etc. One of the methods, for this blog post at least (hehe), is named getReportData. It expects an argument named report_ of type ReportDTO (a data transfer object mapped to the appropriate Java class using [RemoteClass(alias=”…”)]) and a number named _someID_.
The big win here is the databinding. The report_ argument is bound to my _report_ variable which, elsewhere in the code, is bound to my form. _someID_ is bound the the value in _myTextField.text_. Using databinding is what speeds up your code and, in my opinion, cleans up your code.
In my mx:Script block I have a method called _getData()_. This method takes the seleted value of a combobox, which is the name of a function, and calls it. So, I have 1 method to kick off any one of my RemoteObject calls. Seeing as each one of my methods has a different method signature (namely _someID_ changes names) and I don’t want to update my Java code to make them the same I have created a perfect scenario to not even worry about the method signatures.
When you create an mx:method and specify all of the arguments through databinding you don’t have to pass them into your method when you invoke a call. Here is what I mean.
That’s it. Yes, _getReportData()_ requires 2 parameters and I passed 0. This is because I already have my values “registered” (bound) in the _mx:arguments_ node.
Sweet, huh? I love it. What? I need to validate my claim on speeding things up for you? Ok…I’m glad you feel this way.
Let’s say you have to call getReportData 10 times in your code. Each call has different data so you would probably create 10 different functions or an if (or switch) statement with 10 blocks. Each one would pretty much do the same thing: update the _report_ variable and call _getReportData(report, Number(myTextField.text))_. That is a whole lot of code duplication.
So, your next argument is: I’ll bind my form to the report object. Good. That’s what I did too. But…you still have to make 10 calls and pass in the arguments. Let’s say the method signature changes. You have to update your entire app to pass in a new variable. Using mx:method/mx:arguments means your entire app call merely calls _getReportData()_ and let’s the _RemoteObject_ worry about the arguments.
Ok…that’s my argument and I’ll do the lawyer thing of allowing myself a way out of this argument. **Disclaimer** This does not apply to ALL situations. 😉
Anyways…enough fun for now…it is 1:49 and I haven’t eaten lunch so I guess I’ll go grab some grub. Hopefully this helps someone.