HTTPService and Display Synchronisation
Bonjour,
--> Niveau : 3 jours de FLEX.
Presentation : j ai une application qui lorsque je double click sur un element me creer un NodeInformation qui est une mx:TitleWindow.
main.mxml :
Code:
1 2 3 4 5 6 7
|
.....
public function itemDoubleClick(event: Event, text: String, id: String): void {
var nodeInformation:NodeInformation=NodeInformation( popUpManager.createPopUp( this, NodeInformation , true) );
nodeInformation.setNode(text,id);
}
..... |
Lors de la creation de cette fenetre je fais appelle a un HTTPService afin d'obtenir un contenu xml et ainsi pour voir renseigner les champs de ma fenetre.
NodeInformation.mxml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="600" height="400"
borderColor="#666666" backgroundColor="#666666"
horizontalAlign="center" verticalAlign="middle"
close="onClose()" showCloseButton="true"
preinitialize="hostData.send()">
<mx:HTTPService id="hostData" url="http://127.0.0.1/host.xml"
requestTimeout="20" showBusyCursor="true"
resultFormat="e4x"
result="gotHostData(event)"/>
<mx:Script>
<![CDATA[
var data: XML;
...
private function gotHostData( event: ResultEvent ):void {
data = event.result as XML;
}
public function setInfoText():void {
infoText.text = data.toString();
}
</mx:Script>
<mx:HBox width="100%" height="100%">
<mx:Accordion id="accordion" width="100%" height="100%" initialize=";">
<mx:Canvas label="General Information" width="100%" height="100%" >
<mx:Text id="infoText" width="100%" height="100%" initialize="setInfoText()" />
</mx:Canvas>
</mx:Accordion>
</mx:HBox>
</mx:TitleWindow> |
Probleme : l appel a la fonction setInfoText() se fait avant que le handler du httpService est recu la reponse et execute gotHostData() ce qui a pour effet de creer un Null Pointer Exception.
J ai essaye de mettre un preinitialize="hostData.send()" cependant la methode send etant asynchrone setInfoText() s execute quand meme avant.
Si j enleve le initialize dans <mx:Text id="infoText" width="100%" height="100%" initialize="setInfoText()" /> pas de pb cela se passe bien cependant est ce que je risque pas d avoir une pages blanche qui s affiche si HTTPService est long a repondre ?
Question :
* est il possible d attendre le retour de l appelle a hostData.send() ( HTTPS ervice) avant de lancer la methode setInfoText() ?
* est t il possible de passer d atures parametres au constructeur var nodeInformation:NodeInformation=NodeInformation( ) afin de donner directement le resultat et dans ce cas comment le repercuter dans le code de NodeInformation.mxml ?
* y a t il un autre moyen de faire cela en ordonnancant les appels dans le code d un autre facon ?
Merci :D