开发者

Flex AsyncToken implementation on Rails

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!


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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜