0

really drives me insane to get the results of a HTTPService object. When the call to the server is completed, a result event will be triggered. That all is working OK and the server can serve XML data or JSON data without errors. But what to do with the event object "ResultEvent", it is not clear to me.

Let me show you some code:

<fx:Declarations>
    <s:HTTPService id="hsConfig"
       url="{IR_BASE_URL}/getconfig.json"
       result="onGetConfig(event)"
       fault="onGetConfigError(event)"
       method="POST" 
       showBusyCursor="false" 
       resultFormat="array"
       makeObjectsBindable="true"
      >
    <s:request xmlns="">
        <post1>Hello</post1>
        <post2>World</post2>
    </s:request>    
    </s:HTTPService>
</fx:Declarations> 

And then some actionscript:

protected function onGetConfig(e:ResultEvent):void
    {
        //var adata:XMLList = XML.(e.result);
        var data:Object = e.result,
        oo : HTTPService = (e.currentTarget as HTTPService);            

    trace( oo.lastResult );
        trace( e.result.lastResult );
        trace( data.cfg );
        trace( e.result.length );
        if( e.result.length )
        {
            trace( e.result[0].length );
        }

}

xml returned by server:

<?xml version="1.0" encoding="UTF-8"?>
<cfg>
    <param1>Hello</param1>
    <param2>World</param2>
</cfg>

for example trace( e.result.cfg ) raises an error that the name does not exist. Tried several things and use the debugger to see what is inside the property e.result. I can see that the result is a ArrayCollection with one element [0] and the element is an ObjectProxy.

I saw some 'solutions' on the internet but all of the using a datagrid to show the results but that is not what i want. I want to access it like a simple array or object.

How can i do this?

mleko
  • 11,650
  • 6
  • 50
  • 71
Codebeat
  • 6,501
  • 6
  • 57
  • 99

1 Answers1

0

try changing resultFormat="array" to resultFormat="e4x"

now e.result.param1 should return "Hello" and e.result.param2 should return "World" You can stick them in an array, custom class or bind it to a view

  • Thank you for your answer after a long time. But, i decide to take a different approach and that is not using XML but just a simple INI-file. Works fast, less bloated (less size). Works great! – Codebeat Aug 13 '12 at 10:47