PDA

View Full Version : Displaying XML Data in Flash



osp
April 6th, 2007, 02:18 AM
Im loading data into flash using xml and it works all fine but how do I make it so that when the user presses the button I have made, it loads in the next set of data?

To give you an idea; There are 4 facts loaded onto a page (using xml), user presses NEXT and then another set of 4 facts load.

I have the xml all written out how its supposed to be so that it can be loaded. I just dont know what the script is the make the button bring the next facts.


This is the tutorial I used to figure out the xml thing: http://www.kirupa.com/developer/actionscript/xmldataflash.htm (http://www.kirupa.com/forum/../developer/actionscript/xmldataflash.htm)

Thanks in advance for any help!
-Olivia

kompuser
April 6th, 2007, 03:48 AM
Hey hi
I'm actually working on a similar project but with more controls,


Below the code used for things to work, Hope it helps

:thumb:

First, here is the AS to set on your 1st frame :



xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("inventors.xml");
p = 0;

function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
inventor = [];
comments = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
inventor[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
comments[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
}
Display(p);
} else {
trace (total);
}
}


function Display(p) {
name_txt.text = inventor[p];
comment_txt.text = comments[p];
}


btNext.onRelease = function() {
Next();
};


function Next() {
if(p<(total-1)){
p++;
Display(p);
}else{
p=0;
Display(p);
}
};



Next, here is the XML used , based on the tutorial :



<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<inventors>
<person>
<name>1.Thomas Edison</name>
<comment>2.Inventor of many things such as the incandescent lightbulb.</comment>
</person>
<person>
<name>3.Doug Engelbart</name>
<comment>4.Invented the mouse at the Stanford Research Institute</comment>
</person>
</inventors>

osp
April 6th, 2007, 02:30 PM
You're awesome, thank you!!! That worked exactly how I needed it to.:hugegrin:

osp
April 6th, 2007, 08:08 PM
Okay, here's my next question...

Upon completion of loading all of the different facts. How do I Make it so that when the user presses the btnNext it goes to the next frame? Right now it goes back to the beginning fact if it has reached the end, and then goes through them again endlessly.

kompuser
April 8th, 2007, 10:57 AM
what do you mean next frame ? you mean another xml record ? just add as many nodes as you wish on your XML file (duplicating for example this part- including the tags: <person><name>aaaa</name><comment>bbb</comment</person>

osp
April 8th, 2007, 11:50 PM
Okay, I did not explain myself well enough.

This is what I want:
I have the flash file and it is a sort of slideshow going on with the facts. The user clicks next, next, next and looks at all of the facts. Well once he gets to the end of the facts - there is more to the flash presentation, so once he is done with the facts I want to make it so it goes to the next frame of the flash presentation. I have all of the rest worked out with the facts apearing and the user being able to click next and see all of the facts. So what I need to work out now is how to make it immediately go to the next frame of the flash upon completion of the facts. Also, right now the way I have the flash with the data apearing - when it gets to the end of the facts it goes back to the beginning and starts them all over again, so how do I make it so when it gets to the end of the facts it stops with the facts and goes to the next frame of the flash.

Sorry for repeating myself several times. Hopefully that makes sense.

kompuser
April 9th, 2007, 05:42 PM
hey.

Not tested but it may work, see the newly defined Next() Function below:

function Next() {
if(p<(total-1)){
p++;
Display(p);
}else{
this.gotoAndPlay(#);
}
};