I have a Flex application using ColdFusion to retrieve data from MS SQL. I'm trying to create a class where I can send in a numeric argument and it returns a value to the document calling the class.
This is my class
package com.procost
{
import mx.controls.Alert;
import mx.core.FlexGlobals;
import mx.rpc.AbstractOperation;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
public class EmailListRetrieve
{
public var emailListId:Number = -1;
public function send():void{
//Create the remote object
var _remoteObject:RemoteObject = new RemoteObject('test');
_remoteObject = new RemoteObject("ColdFusion");
_remoteObject.endpoint = "http://" + FlexGlobals.topLevelApplication.endPointLink + "/flex2gateway/";
_remoteObject.source = FlexGlobals.topLevelApplication.remotePath + "services.general";
_remoteObject.showBusyCursor = true;
//Send
var op:AbstractOperation = _remoteObject.getOperation('getEmailList');
op.addEventListener(ResultEvent.RESULT, result);
op.send(this);
}
// Result from CFC
private function result(event:ResultEvent){
Alert.show(event.result.toString());
}
}
}
**This is how I'm calling it from my MXML **
import com.procost.EmailListRetrieve;
public function fncClick():void{
var request:EmailListRetrieve = new EmailListRetrieve();
request.emailListId=1;
request.send();
}
The result function in my class is returning all the data I need from the DB. The issue is, how do I get this data back into the MXML document I called it from?
Any help would be appreciated.
All you need to do is echo the data from the
ResultEvent
in another event (note that you'll want a custom event class to carry the data):Then, in your MXML code:
Important: Your
request
EmailListRetrieve
object could end up getting garbage collected before you receive a response. I recommend saving a reference to it in a class-level variable in your MXML instead of having it be a function member.