All data service calls in Flex are asynchronous. This means that you *cannot*
access the result in the same function in which you invoke the send().
Instead, create a handler function and call it from the result event. Like
this:
<mx:HTTPService id="userRequest" url="donnees.xml" result="onResult(event)"/>
In a script tag:
import mx.rpc.events.ResultEvent;
/** this will be called when the HTTPService call returns with data */
private function onResult(oEvent:ResultEvent):void {
var xmlResult:XML = XML(oEvent.result);
trace(xmlResult.toXMLString());
affiche.text = xmlResult.message.affiche.info;
...
Tracy
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of
titipouns19
Sent: Wednesday, December 20, 2006 4:40 PM
To: [email protected]
Subject: [flexcoders] TypeError: Error #1009 - httpservice
Hello,
I try to display the word 'bonjour' (xml file) and when i click to
the button "id_button" i have this error :
TypeError: Error #1009: Il est impossible d'accéder à la propriété ou
à la méthode d'une référence d'objet nul.
at affiche_bonjour/affichebonjour()
at affiche_bonjour/__id_button_click()
- Here my xml file (donnees.xml) :
<message><affiche><info>bonjour</info></affiche></message>
- Here my mxml page :
<?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">
<mx:Script>
<![CDATA[
public function affichebonjour():void
{
userRequest.send();
affiche.text =
userRequest.lastResult.message.affiche.info;
}
]]>
</mx:Script>
<mx:HTTPService id="userRequest" url="donnees.xml"/>
<mx:Button id="id_button" x="192" y="113" label="affiche
bonjour" click="affichebonjour();"/>
<mx:TextInput id="affiche" x="167" y="174"/>
</mx:Application>
Thanks for your help.
Titipouns.