Eme Emertana
Eme Emertana

Reputation: 571

How to show web service results in flex?

Hi I have the following flex code but I dont know how to show the result of the xml. Currently the result of textbox is String[] but I need it to show the result of the xml as 100,200,300,400,500 Thanks

<?xml version="1.0" encoding="utf-8"?> 

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx="library://ns.adobe.com/flex/mx"
           xmlns:hellos="services.hellos.*"
           minWidth="955" minHeight="600"> 
<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        protected function 
        form_creationCompleteHandler(event:FlexEvent):void
        {
            sayHelloResult.token = hellos.sayHello();
        }

    ]]>
</fx:Script>
<fx:Declarations>
    <hellos:Hellos id="hellos"/>
    <s:CallResponder id="sayHelloResult"/>
</fx:Declarations>
<s:Form id="form" creationComplete="form_creationCompleteHandler(event)">
    <s:FormItem label="SayHello">
        <s:TextInput text="String[]"/>
    </s:FormItem>
</s:Form>

 </s:Application>

The xml is as following:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">
  <soapenv:Body>
    <sayHelloResponse xmlns="http://services">
     <sayHelloReturn>100</sayHelloReturn>
     <sayHelloReturn>200</sayHelloReturn>
     <sayHelloReturn>300</sayHelloReturn>
     <sayHelloReturn>400</sayHelloReturn>
     <sayHelloReturn>500</sayHelloReturn>
    </sayHelloResponse>
  </soapenv:Body>
</soapenv:Envelope>

Upvotes: 0

Views: 157

Answers (1)

user1875642
user1875642

Reputation: 1313

Add id to your label:

 <s:TextInput id="resultText" text=""/> 

Add handler to result event of call responder:

 <s:CallResponder id="sayHelloResult" result="processResult()" />

Apply responder like that:

protected function processResult():void{
    var r:Array = [];
    for each(var xml:XML in sayHelloResult.lastResult..*::sayHelloReturn){
        r.push(xml.toString());
    }
    resultText.text = r.join(',');
}

While dealing with xml, don't forget about namespaces: http://jodieorourke.com/view.php?id=76&blog=news

Upvotes: 1

Related Questions