

Intégrer des données XML dans application Flex
#1
Posté 05 March 2014 - 17:33 PM
#2
Posté 05 March 2014 - 21:35 PM
[Embed(source="test.xml", mimeType="application/octet-stream")]
private const EmbeddedXML:Class;
private var myXML:XML = XML(new EmbeddedXML());
#3
Posté 06 March 2014 - 08:54 AM
Merci pour votre réponse, mais ça ne fonctionne tjs pas, peut être j'ai mal exploité le code dans les balise <fx:Script> de ma application Flex.
et ce qui m'intéresse aussi à savoir; c'est comment que je peux relier mon code action script 3.0 à mon code MXML dans la même application avec une source de données vernant d'un fichier xml.
Comme il a eu une erreur de mise en page dans mon premier message je poste à nouveau mon code Xml avec mon fichier Flex.
Fichier Config.xml:
<?xml version="1.0" ?>
<configuration>
<MyURL1>http://intraesri/ArcGIS/rest/services/arcopole/Cadastre/MapServer</MyURL1>
<MyURL2>http://esri3/ArcGIS/rest/services/Diffusion/FDP_plan_ville/MapServer</MyURL2>
<MyURL3>http://intraesri/ArcGIS/rest/services/arcopole/Ortho_2011/MapServer</MyURL3>
</configuration>
Fichier MaCherApplication3.mxml:
<?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" minWidth="955" minHeight="600"
xmlns:esri="http://www.esri.com/2008/ags"
>
<fx:Declarations>
<!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
<s:RadioButtonGroup id="baseMaps"/>
<esri:QueryTask id="queryTask" url="http://esri3/ArcGIS/rest/services/Diffusion/debit_boissons/MapServer/0"/>
<esri:Query id="queryParam" where="ETIQUETTE='{typesChoose.selectedItem}'" returnGeometry="true" outSpatialReference="{mainMap.spatialReference}">
<esri:outFields>
<fx:String>NOM</fx:String>
<fx:String>ETIQUETTE</fx:String>
</esri:outFields>
</esri:Query>
</fx:Declarations>
<esri:Map id="mainMap" panArrowsVisible="{panArrowsCheck.selected}">
<esri:extent>
<esri:Extent xmax="1576219.09331764" ymax="5193479.710001" xmin="1550845.50090379" ymin="5173884.5082954">
<esri:SpatialReference wkid="3946"/>
</esri:Extent>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer url="MyURL1" visible="{topoBase.selected}" alpha="{mapTrans.value}"/>
<esri:ArcGISTiledMapServiceLayer url="MyURL2" visible="{streetBase.selected}" alpha="{mapTrans.value}"/>
<esri:ArcGISTiledMapServiceLayer url="MyURL3" visible="{imageryBase.selected}" alpha="{mapTrans.value}"/>
<esri:GraphicsLayer id="myGraphicsLayer" graphicProvider="{queryTask.executeLastResult.features}">
<esri:renderer>
<esri:SimpleRenderer>
<esri:SimpleFillSymbol id="basicSymbol" color="0xfd0101" style="solid"/>
</esri:SimpleRenderer>
</esri:renderer>
<esri:infoWindowRenderer>
<fx:Component>
<mx:VBox label="{data.NOM}">
<s:Label text="{data.ETIQUETTE}" color="0xffffff"/>
</mx:VBox>
</fx:Component>
</esri:infoWindowRenderer>
</esri:GraphicsLayer>
</esri:Map>
<s:ToggleButton id="mapoptionButton" x="1150" y="15"
label="Options carte"
selected="{mapOptionsWindow.visible}"
click="mapOptionsWindow.visible ? mapOptionsWindow.visible=false: mapOptionsWindow.visible=true"/>
<s:TitleWindow id="mapOptionsWindow"
mouseDown="mapOptionsWindow.startDrag()" mouseUp="mapOptionsWindow.stopDrag()"
title="Options carte"
visible="false"
width="275" height="215" top="60" right="60"
close="mapOptionsWindow.visible=false">
<s:VGroup paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="1"
width="100%" height="100%" horizontalAlign="center">
<mx:Text text="Types cartes" fontWeight="bold"/>
<s:HGroup id="baseMapToggle">
<s:RadioButton label="Carte Topo" id="topoBase"
groupName="{baseMaps}" selected="true"/>
<s:RadioButton label="Carte des rue" id="streetBase"
groupName="{baseMaps}"/>
<s:RadioButton label="Satellite" id="imageryBase"
groupName="{baseMaps}"/>
</s:HGroup>
<mx:Text text="Transparence de la carte" fontWeight="bold"/>
<s:HSlider id="mapTrans" width="100%" minimum="0" maximum="1"
snapInterval="0.1" value="1" liveDragging="true"/>
<s:CheckBox id="panArrowsCheck" label="Flèche sur" selected="false"/>
<mx:Text text="échelle carte en cours 1:{mainMap.scale}" fontWeight="bold"/>
</s:VGroup>
</s:TitleWindow>
<s:ToggleButton id="recherche" x="600" y="15" horizontalCenter="0"
label="Vous cherchez"
selected="{map.visible}"
click="map.visible ? map.visible=false: map.visible=true"
/>
<s:TitleWindow id="map"
mouseDown="map.startDrag()" mouseUp="map.stopDrag()"
title="Recherche"
visible="false"
width="275" height="275" top="60" horizontalCenter="0"
close="map.visible=false">
<s:layout>
<s:VerticalLayout paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10">
</s:VerticalLayout>
</s:layout>
<s:TextInput width="100%" id="qText" text="Limoges"/>
<s:ComboBox id="typesChoose"
selectedItem=" " change="queryTask.execute(queryParam)" width="75%">
<s:ArrayCollection>
<fx:String>Eglise</fx:String>
<fx:String>Ecole elementaire</fx:String>
<fx:String>Ecole maternelle</fx:String>
<fx:String>Hopital</fx:String>
<fx:String>Accueil Loisirs</fx:String>
<fx:String>Lycée</fx:String>
<fx:String>Faculté</fx:String>
<fx:String>Collège</fx:String>
<fx:String>Gymnase</fx:String>
<fx:String>Terrain de sport</fx:String>
<fx:String>Piscine</fx:String>
<fx:String>Maison de retraite</fx:String>
<fx:String>Restaurant scolaire</fx:String>
<fx:String>Logement de fonction</fx:String>
</s:ArrayCollection>
</s:ComboBox>
<mx:DataGrid id="resultsGrid" width="100%" height="100%" dataProvider="{queryTask.executeLastResult.attributes}">
<mx:columns>
<mx:DataGridColumn headerText="NOM" dataField="NOM"/>
<mx:DataGridColumn headerText="TYPE" dataField="ETIQUETTE"/>
</mx:columns>
</mx:DataGrid>
</s:TitleWindow>
<s:Spinner x="22" y="225"/>
<s:Label text="Label" backgroundColor="#FFFFFF" x="913" y="653"/>
</s:Application>
Merci d'avance.
#4
Posté 06 March 2014 - 11:12 AM
je ne vois pas de balise <fx:Script> dans ton mxml ?
#5
Posté 06 March 2014 - 11:28 AM
et voilà à nouveau :
Fichier Config.xml:
<?xml version="1.0" ?>
<configuration>
<MyURL1>http://intraesri/ArcGIS/rest/services/arcopole/Cadastre/MapServer</MyURL1>
<MyURL2>http://esri3/ArcGIS/rest/services/Diffusion/FDP_plan_ville/MapServer</MyURL2>
<MyURL3>http://intraesri/ArcGIS/rest/services/arcopole/Ortho_2011/MapServer</MyURL3>
</configuration>
Fichier MaCherApplication3.mxml:
<?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" minWidth="955" minHeight="600"
xmlns:esri="http://www.esri.com/2008/ags"
initialize="init()">
<fx:Script>
<![CDATA[
private function init():void{
var chargementXML : URLLoader = new URLLoader();
var fichier : URLRequest = new URLRequest("config.xml");
chargementXML.addEventListener(Event.COMPLETE,chargementComplet);
chargementXML.load(fichier);
}
private function chargementComplet(event:Event):void{
var xml : XML = new XML(event.target.data);
trace("test " + xml);
var myvalueURL1 = xml.configuration.@MyURL1
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Placer ici les �l�ments non visuels (services et objets de valeur, par exemple). -->
<s:RadioButtonGroup id="baseMaps"/>
<esri:QueryTask id="queryTask" url="http://esri3/ArcGIS/rest/services/Diffusion/debit_boissons/MapServer/0"/>
<esri:Query id="queryParam" where="ETIQUETTE='{typesChoose.selectedItem}'" returnGeometry="true" outSpatialReference="{mainMap.spatialReference}">
<esri:outFields>
<fx:String>NOM</fx:String>
<fx:String>ETIQUETTE</fx:String>
</esri:outFields>
</esri:Query>
</fx:Declarations>
<esri:Map id="mainMap" panArrowsVisible="{panArrowsCheck.selected}">
<esri:extent>
<esri:Extent xmax="1576219.09331764" ymax="5193479.710001" xmin="1550845.50090379" ymin="5173884.5082954">
<esri:SpatialReference wkid="3946"/>
</esri:Extent>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer url="{myvalueURL1}" visible="{topoBase.selected}" alpha="{mapTrans.value}"/>
<esri:ArcGISTiledMapServiceLayer url="MyURL2" visible="{streetBase.selected}" alpha="{mapTrans.value}"/>
<esri:ArcGISTiledMapServiceLayer url="MyURL3" visible="{imageryBase.selected}" alpha="{mapTrans.value}"/>
<esri:GraphicsLayer id="myGraphicsLayer" graphicProvider="{queryTask.executeLastResult.features}">
<esri:renderer>
<esri:SimpleRenderer>
<esri:SimpleFillSymbol id="basicSymbol" color="0xfd0101" style="solid"/>
</esri:SimpleRenderer>
</esri:renderer>
<esri:infoWindowRenderer>
<fx:Component>
<mx:VBox label="{data.NOM}">
<s:Label text="{data.ETIQUETTE}" color="0xffffff"/>
</mx:VBox>
</fx:Component>
</esri:infoWindowRenderer>
</esri:GraphicsLayer>
</esri:Map>
<s:ToggleButton id="mapoptionButton" x="1150" y="15"
label="Options carte"
selected="{mapOptionsWindow.visible}"
click="mapOptionsWindow.visible ? mapOptionsWindow.visible=false: mapOptionsWindow.visible=true"/>
<s:TitleWindow id="mapOptionsWindow"
mouseDown="mapOptionsWindow.startDrag()" mouseUp="mapOptionsWindow.stopDrag()"
title="Options carte"
visible="false"
width="275" height="215" top="60" right="60"
close="mapOptionsWindow.visible=false">
<s:VGroup paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="1"
width="100%" height="100%" horizontalAlign="center">
<mx:Text text="Types cartes" fontWeight="bold"/>
<s:HGroup id="baseMapToggle">
<s:RadioButton label="Carte Topo" id="topoBase"
groupName="{baseMaps}" selected="true"/>
<s:RadioButton label="Carte des rue" id="streetBase"
groupName="{baseMaps}"/>
<s:RadioButton label="Satellite" id="imageryBase"
groupName="{baseMaps}"/>
</s:HGroup>
<mx:Text text="Transparence de la carte" fontWeight="bold"/>
<s:HSlider id="mapTrans" width="100%" minimum="0" maximum="1"
snapInterval="0.1" value="1" liveDragging="true"/>
<s:CheckBox id="panArrowsCheck" label="Fl�che sur" selected="false"/>
<mx:Text text="�chelle carte en cours 1:{mainMap.scale}" fontWeight="bold"/>
</s:VGroup>
</s:TitleWindow>
<s:ToggleButton id="recherche" x="600" y="15" horizontalCenter="0"
label="Vous cherchez"
selected="{map.visible}"
click="map.visible ? map.visible=false: map.visible=true"
/>
<s:TitleWindow id="map"
mouseDown="map.startDrag()" mouseUp="map.stopDrag()"
title="Recherche"
visible="false"
width="275" height="275" top="60" horizontalCenter="0"
close="map.visible=false">
<s:layout>
<s:VerticalLayout paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10">
</s:VerticalLayout>
</s:layout>
<s:TextInput width="100%" id="qText" text="Limoges"/>
<s:ComboBox id="typesChoose"
selectedItem=" " change="queryTask.execute(queryParam)" width="75%">
<s:ArrayCollection>
<fx:String>Eglise</fx:String>
<fx:String>Ecole elementaire</fx:String>
<fx:String>Ecole maternelle</fx:String>
<fx:String>Hopital</fx:String>
<fx:String>Accueil Loisirs</fx:String>
<fx:String>Lyc�e</fx:String>
<fx:String>Facult�</fx:String>
<fx:String>Coll�ge</fx:String>
<fx:String>Gymnase</fx:String>
<fx:String>Terrain de sport</fx:String>
<fx:String>Piscine</fx:String>
<fx:String>Maison de retraite</fx:String>
<fx:String>Restaurant scolaire</fx:String>
<fx:String>Logement de fonction</fx:String>
</s:ArrayCollection>
</s:ComboBox>
<mx:DataGrid id="resultsGrid" width="100%" height="100%" dataProvider="{queryTask.executeLastResult.attributes}">
<mx:columns>
<mx:DataGridColumn headerText="NOM" dataField="NOM"/>
<mx:DataGridColumn headerText="TYPE" dataField="ETIQUETTE"/>
</mx:columns>
</mx:DataGrid>
</s:TitleWindow>
<s:Spinner x="22" y="225"/>
<s:Label text="Label" backgroundColor="#FFFFFF" x="913" y="653"/>
</s:Application>
surtout j'arrive pas à déboguer mon code actionScript dans dans mon code XMXL
#6
Posté 06 March 2014 - 11:35 AM
de plus elle n'est pas bindable pour pouvoir être réutiliser dans le code mxml ?
#7
Posté 06 March 2014 - 11:41 AM
#8
Posté 06 March 2014 - 11:42 AM
[Bindable]
private var myvalueURL1:*;
#9
Posté 06 March 2014 - 11:52 AM
var myvalueURL1 = xml.configuration.@MyURL1
#10
Posté 06 March 2014 - 11:57 AM
myvalueURL1 = xml.configuration.@MyURL1
et mettre en dehors de la function
[Bindable]
private var myvalueURL1:*;
#11
Posté 06 March 2014 - 12:07 PM
voici mon code ActionScript :
<fx:Script>
<![CDATA[
private function init():void{
var chargementXML : URLLoader = new URLLoader();
var fichier : URLRequest = new URLRequest("config.xml");
chargementXML.addEventListener(Event.COMPLETE,chargementComplet);
chargementXML.load(fichier);
}
private function chargementComplet(event:Event):void{
var xml : XML = new XML(event.target.data);
trace("test " + xml);
myvalueURL1 = xml.configuration.@MyURL1
[Bindable]
private var myvalueURL1:*;
}
]]>
</fx:Script>
#12
Posté 06 March 2014 - 12:10 PM
<fx:Script>
<![CDATA[
private function init():void{
var chargementXML : URLLoader = new URLLoader();
var fichier : URLRequest = new URLRequest("config.xml");
chargementXML.addEventListener(Event.COMPLETE,chargementComplet);
chargementXML.load(fichier);
}
[Bindable]
private var myvalueURL1:*;
private function chargementComplet(event:Event):void{
var xml : XML = new XML(event.target.data);
trace("test " + xml);
myvalueURL1 = xml.configuration.@MyURL1
}
]]>
</fx:Script>
#13
Posté 06 March 2014 - 12:21 PM
<MyURL1>http://intraesri/ArcGIS/rest/services/arcopole/Cadastre/MapServer</MyURL1>
est ce que c'est car ça été mal déclaré dans mon code mxml ?
#14
Posté 06 March 2014 - 12:26 PM
#15
Posté 06 March 2014 - 12:32 PM
Ce qui m'inquiète que le fichier Flex n'arrive pas à lire le fichier xml est ce qu'il manque des code actionScript peut être ?
#16
Posté 06 March 2014 - 13:47 PM
#17
Posté 06 March 2014 - 14:15 PM
Le débogueur arrive à bien lier le contenu du fichier xml, mais quand je fait un traca de la valeur MyURL1 il ne la lit pas
voici ce que j'ai dans mon débogueur:
[SWF] C:\FlexBuilder\bin-debug\MaCherApplication3.swf\[[DYNAMIC]]\6 - 317 875 octets après la décompression
test <configuration>
<MyURL1>http://intraesri/ArcGIS/rest/services/arcopole/Cadastre/MapServer</MyURL1>
<MyURL2>http://esri3/ArcGIS/rest/services/Diffusion/FDP_plan_ville/MapServer</MyURL2>
<MyURL3>http://intraesri/ArcGIS/rest/services/arcopole/Ortho_2011/MapServer</MyURL3>
</configuration>
ma valeur
[Décharger SWF] C:\FlexBuilder\bin-debug\MaCherApplication3.swf
il n'y a rien qui s'affiche à côté "ma valeur" suite à une trace que je l'ai dans mon actionScript :
trace("ma valeur " + myvalueURL1);
#18
Posté 06 March 2014 - 15:08 PM
myvalueURL1 = xml.configuration.@MyURL1
<MyURL1> qui est dans mon fichier xml on la définir comme ça
myvalueURL1 = xml.MyURL1.toString();
private var myvalueURL1:String;
En tous cas merci beaucoup pour ton aide "pol" ça me permit de mieux comprendre l'ActionScript et de mieux chercher afin de localiser le problème et le rectifier

#19
Posté 06 March 2014 - 15:11 PM
@ c'est pour les attributs
#20
Posté 06 March 2014 - 16:07 PM
Bon fin de journée

1 utilisateur(s) li(sen)t ce sujet
0 membre(s), 1 invité(s), 0 utilisateur(s) anonyme(s)