Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML vs FLASHMX 2

Status
Not open for further replies.

bubu

Programmer
Joined
Mar 3, 2002
Messages
463
Location
RO
Hello guys!
I have a little problem:

I want to make a "news bar" ...something like CNN television(in the lower
part of the screen there is a bar where the news is showing up).
The problem is that i want to read the data from an xml document.
My xml document will look something like this:
<flights>
<f Destination=&quot;MADRID&quot; Price=&quot;145&quot;/>
<f Destination=&quot;PARIS&quot; Price=&quot;130&quot;/>
<f Destination=&quot;BUCHAREST&quot; Price=&quot;110&quot;/>
</flights>
...and so on
In flash i want this data to appear something like this:
MADRID 145 :: PARIS 130 :: BUCHAREST 110
and the flash movie to update the data read from the xml document.

Any suggestion will be appreciated. Regards,
Dragos.

dragos.jpg

 
You need to create a new XML object in Flash and then load the data into it.

//set up XML
flightsXML = new XML();
flightsXML.ignoreWhite = true;
flightsXML.onLoad = convertXML;
flightsXML.load('flights.xml');
//counter
numFlights=3;
//set up arrays to store values
destinationArray = new Array();
priceArray = new Array();
//callback function to parse XML document
function convertXML() {
if (flightsXML.loaded) {
for (i=0; i<numFlights; i++) {
destinationArray = flightsXML.firstChild.childNodes.attributes.Destination;
priceArray = flightsXML.firstChild.childNodes.attributes.Price;
}
} else {
convertXML();
}
}

You can output this later in the movie as a string with something like this:

for(i=0;i<numFlights;i++){
output+=destinationArray+&quot; &quot;+priceArray+&quot;::&quot;;
}

Remember that if you're loading the XML in from a remote file you'll have to loose the backslash escape characters as Flash won't read the data correctly otherwise - you only need these if the XML is stored in Flash as a string like myXML=new XML(&quot;<f Destination=&quot;MADRID&quot; Price=&quot;145&quot;/>&quot;);
 
Let's try that again without TGML screwing it up...

Code:
//set up XML
flightsXML = new XML();
flightsXML.ignoreWhite = true;
flightsXML.onLoad = convertXML;
flightsXML.load('flights.xml');
//counter
numFlights=3;
//set up arrays to store values
destinationArray = new Array();
priceArray = new Array();
//callback function to parse XML document
function convertXML() {
    if (flightsXML.loaded) {
        for (i=0; i<numFlights; i++) {
            destinationArray = flightsXML.firstChild.childNodes.attributes.Destination;
            priceArray = flightsXML.firstChild.childNodes.attributes.Price;
        }
    } else {
        convertXML();
    }
}

You can output this later in the movie as a string with something like this:

Code:
for(i=0;i<numFlights;i++){
output+=destinationArray+&quot; &quot;+priceArray+&quot;::&quot;;
}

Remember that if you're loading the XML in from a remote file you'll have to loose the backslash escape characters as Flash won't read the data correctly otherwise - you only need these if the XML is stored in Flash as a string like myXML=new XML(&quot;<f Destination=&quot;MADRID&quot; Price=&quot;145&quot;/>&quot;);
 
David!

For some reason the .fla and .xml files are not working properly on my machine....nothing is displayed in the browser.

Where am i doing wrong?

How can i continuosly scroll the text in the textbox from right to left with actionscript?
Regards,
Dragos.

dragos.jpg

 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top