Hi, i have an xml file, which i have to read. I know how to read it once, but i
have to read it all the time, because it reads some numbers, which are changing
and managing my events.
The XML file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
- <hotspots>
<sequence>47</sequence>
<hotspot id="1">0</hotspot>
<hotspot id="2">0</hotspot>
<hotspot id="3">0</hotspot>
<hotspot id="4">0</hotspot>
<hotspot id="5">0</hotspot>
<hotspot id="6">0</hotspot>
<hotspot id="7">0</hotspot>
<hotspot id="8">0</hotspot>
<hotspot id="9">0</hotspot>
</hotspots>
I have to read if hotspot has value 1 or 0. I have to read only hotspots, with
id=1,id=2 and id=3.If the number changes, then something happens in my flash
file.
My current code:
var mojXML:XML = new XML();
mojXML.ignoreWhite = true;
var output:String = "";
mojXML.onLoad = function(success){
if(success)
{
var tabela:Array = mojXML.firstChild.childNodes;
//ce je prvi ena
if(tabela[1].childNodes[0].nodeValue == 1){
if(tabela[2].childNodes[0].nodeValue == 0){
if(tabela[3].childNodes[0].nodeValue == 0){
trace("zazeni prvega");
}else{trace("zazeni tretjega");}
}
else if(tabela[2].childNodes[0].nodeValue == 1){
if(tabela[3].childNodes[0].nodeValue == 0){
trace("zazeni drugega");
}else{trace("zazeni tretjega");}
}
}
//ce je prvi 0
else if(tabela[1].childNodes[0].nodeValue == 0){
if(tabela[2].childNodes[0].nodeValue == 0){
if(tabela[3].childNodes[0].nodeValue == 0){
trace("zazeni prvega, ki je default");
}else{trace("zazeni tretjega");}
}
else if(tabela[2].childNodes[0].nodeValue == 1){
if(tabela[3].childNodes[0].nodeValue == 0){
trace("zazeni drugega");
}else{trace("zazeni tretjega");}
}
}
else{
trace("first as default");
}
}
else{
trace("XML ni OK");
}
}
mojXML.load("hotspot_processed.xml");
It is probably a simple solution, so i hope that someone can help me.
mojXML.onLoad = function(success){
if(success)
{
var tabela:Array = mojXML.firstChild.childNodes;
//ce je prvi ena
if(tabela[1].childNodes[0].nodeValue == 1){
if(tabela[2].childNodes[0].nodeValue == 0){
if(tabela[3].childNodes[0].nodeValue == 0){
trace("zazeni prvega");
}else{trace("zazeni tretjega");}
}
else if(tabela[2].childNodes[0].nodeValue == 1){
if(tabela[3].childNodes[0].nodeValue == 0){
trace("zazeni drugega");
}else{trace("zazeni tretjega");}
}
}
//ce je prvi 0
else if(tabela[1].childNodes[0].nodeValue == 0){
if(tabela[2].childNodes[0].nodeValue == 0){
if(tabela[3].childNodes[0].nodeValue == 0){
trace("zazeni prvega, ki je default");
}else{trace("zazeni tretjega");}
}
else if(tabela[2].childNodes[0].nodeValue == 1){
if(tabela[3].childNodes[0].nodeValue == 0){
trace("zazeni drugega");
}else{trace("zazeni tretjega");}
}
}
else{
trace("first as default");
}
}
else{
trace("XML ni OK");
}
}
mojXML.load("hotspot_processed.xml");
theTraveler3 - 27 May 2008 16:35 GMT
If you need to constantly update and read the XML file I can think of 2 easy
solutions.
1. Create a time out, and just keep reloading that file ever n seconds (or
whatever is appropriate). This is like the AJAX approach. From a
synchronization perspective, you'll want a flag to indicate whether the
previous load has finished too, that way your XML object only loads 1 thing at
a time. The drawback is that your often pulling data from the server that
isn't new.
2. Use the XMLSocket Object, which opens a persistent-2-way socket connection
to your server. An event will be thrown whenever new data is sent through the
socket notifying your Flash doc to reparse. The drawback here is that you need
to setup a SocketServer somewhere... I havn't writen a Flash Socket Server in a
while, but last time I did it in Java or C.
Hope this helps out.