ALL data service calls in flex are "asynchronous".  You can never access
the result of a data call in the same function in which you invoke the
send().  You must ALWAYS use the result event or bind to lastResult.

 

Binding directly to lastResult can be hard to debug, so get in the habit
of creating a result handler function. 

<mx:HTTPService ... result="onResult(event)"

 

import mx.rpc.events.ResultEvent;

import mx.rpc.events.FaultEvent; 

private function onResult(event:ResultEvent):void  {

  Var xmlResult:XML = event.result as XML;

  Alert.show(xmlResult.toXMLString());

 

Post back if you need more guidance.

 

Tracy

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of kim_boulton
Sent: Friday, December 08, 2006 9:05 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] httpservice conundrum

 

I need to change a httpservice url at runtime. However when I change
the url the xml is not being updated, it is always one step behind.

See the following example app, the xml displayed in the Alert box is
always from the previous call.

How do I get it to update correctly?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> "
layout="absolute" creationPolicy="all"
creationComplete="onCreationComplete();" width="687" height="332">
<mx:HTTPService id="gsservice" url="test0.xml" resultFormat="e4x"
result="gsData = gsservice.lastResult as XML"/>
<mx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.controls.Alert;
private var gsData:XML;

private function onCreationComplete():void{
gsservice.send();
}

private function test(file:String):void {
gsservice.url = file;
gsservice.send();
gsData = gsservice.lastResult as XML;
Alert.show(gsData.toString());
}
]]>
</mx:Script>
<mx:Button x="10" y="10" label="Test 1" width="180"
click="test('test1.xml');"/>
<mx:Button x="10" y="40" label="Test 2" width="180"
click="test('test2.xml');"/>
</mx:Application> 

 

Reply via email to