--- In [email protected], "wkolcz" <wko...@...> wrote:
>
> Thanks, that cleared the error on the AS page! Of course now I am
getting an error on my .mxml page.
>
> TypeError: Error #1009: Cannot access a property or method of a
null object reference.
> at com.isavepets.projects::ProjectGateway/list()
> at ASRemoteObject/initApp()
I think you're misunderstanding how event handling works. You can't
set up a result handler on an rpc call and then set some other
variable to the result of the function and think that when the result
handler gets called it will somehow return a value to where it was
called by some other code.
Try something like this:
ProjectGateway.as
package com.isavepets.projects
{
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.remoting.Operation;
import mx.rpc.remoting.RemoteObject;
public class ProjectGateway
{
private var _ro:RemoteObject=new RemoteObject();
public function ProjectGateway()
{
var RO:RemoteObject = new RemoteObject();
_ro.destination = "ColdFusion";
_ro.source = "com.isavepets.projects.projectGateway";
}
public function execute():ArrayCollection{
var token = _ro.list();
var ac=new ArrayCollection();
token.addResponder(list, faultHandler);
token.ac=ac;
return ac;
}
public function list():void{
e.token.ac.source=e.result as Array;
}
private function faultHandler(e:FaultEvent):void {
Alert.show(e.fault.message, 'Project Gateway Error');
}
}
}
Then:
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import com.isavepets.projects.ProjectGateway;
import mx.events.CollectionEvent;
[Bindable]
public var projectData:ArrayCollection;
public var ProjGateway:ProjectGateway = new ProjectGateway();;
public function initApp():void {
projectData = ProjGateway.execute();
projectData.addEventListener(CollectionEvent.COLLECTION_CHANGE,
onLoad);
}
private function onLoad():void{
//your data is ready to go
}
]]>
</mx:Script>