Looking for a little education from all the people smarter than me of
remoteObjects. I have always used the MXML version which includes the
resultHandler attribute which made managing the returned data easy. However I
never learned the AS version very well. I can create the remoteObject in AS and
call its method, add the EventListener, but how do I actually get the data back
to a caller function?
index.mxml
import org.mywindow.data.Users;
[Bindable] public var users:ArrayCollection;
public function getMyData():void {
users = Users.getAll();
}
for the User's getAll function I have something like:
UserDAO.as
...
public var _users:ArrayCollection;
public function getAll():void {
var UserDAO:RemoteObject = new RemoteObject();
UserDAO.destination = "ColdFusion";
UserDAO.source = "org.mywindow.data.userDAO";
UserDAO.getAll.addEventListener(ResultEvent.RESULT, resultHandler);
UserDAO.getAll.addEventListener(FaultEvent.FAULT, faultHandler);
}
public function resultHandler(e:ResultEvent):ArrayCollection{
_users = e as ArrayCollection;
return users;
}
I know some of the code may be off, but I am trying to understand how a non
called function (resultHandler) can return data to the called function in a
different class. So my question is, if the index.mxml calls the getAll function
in the UserDAO class, will the getMyData function still receive the
ArrayCollection from the resultHandler? If I were to fire this off, till the
result be that my users ArrayCollection in the index.mxml be populated in the
end? Thanks!