views:

19

answers:

2

Hi there, i'm using a Rails backend with my App and getting a AsyncToken returned from it (a DB-Call to be specific)

As far as i know the AsyncToken returns a result event when done loading all data from the request, this way its possible to make sure all data was loaded before executing some function which uses the data.

i tried the following implementation to get the AsyncToken converted into an Array and plotting its objects as strings to the user:

var dataSrv:services.databaseservice.DatabaseService = new services.databaseservice.DatabaseService;
    dataSrv.addEventListener(ResultEvent.RESULT, dbListener);

    //DBOPERATION returns my AsyncToken
    var listData:AsyncToken = dataSrv.DBOPERATION;

    var responder:AsyncResponder = new AsyncResponder( resultHandler, faultHandler );
    listData.addResponder(responder);



    public function resultHandler(event:ResultEvent, token:Object=null):void{
        var output: Array = (event.result as Array);
        for (var i:int = 0; i<output.length; i++){
         Alert.show( output[i].toString() );
        }
       }

       public function faultHandler(event:FaultEvent, token:Object=null):void{
        Alert.show( "FAULT: " + event.fault.message );
       }

But i keep getting a "null object-pointer" error!

A: 

You could add a breakpoint on the following line

  var output: Array = (event.result as Array);

Then go to the Flash Debug perspective, in the "Variables" pane you should be able to access the properties of the event and see the content of the result property.

If the result property is null, you may want to double check what is returned from Rails

PatrickS
Thanks mate, didn't think about the cool debuging features of Flex! I was able to troubleshoot the Problem with the debugger, see next post.
masi
+1  A: 

Ok here how it works:

var output:ArrayCollection = (event.result as ArrayCollection);
for (var i:int = 0; i<output.length; i++)
{
        // where VARIABLE is the name of the transmitted data-variable
    Alert.show(output[i].VARIABLE);
}

hope this helps others. Thx for Help Guys, stackoverflow is just awesome!

masi