Hey, I wonderd how I could make an XML, or php, news. I have thought it like this:
I have an member section, with user and password, and in the section I want the the logged in user to be able to post a news that shows up in the home.swf.
If the user could send the info (name, date, message) to an xml file, then in the home.swf a dynamic field could read the xml and, it would show up.
Could anyone help?
If possible, I would like the output in the home.swf to be something like this :
- fatnslow, 01.09.04 -
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
- fatnslow, 29.08.04 -
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
// determine that myXML is in xml format
MyXML = new XML();
// when its loaded:
MyXML.onLoad = function(){
// get the full news list
newsList = this.firstChild.childNodes;
// loop trough the news list
for(i=0;i<newsList.length;i++){
// get an item (including all the data), from the newsList
newsItem = newsList*;
// make sure it has the news tag
if(newsItem.nodeName.toLowerCase() == "news"){
// get the info from the Item
itemAuthor = newsItem.attributes.author;
itemDate = newsItem.attributes.date;
itemPost = newsItem.attributes.post
// now do stuff with it :)
trace("This was posted by "+itemAuthor+" on "+itemDate+".");
trace(itemPost);
trace(newline);
}
}
}
// load your file, relative or absolute
MyXML.load("news.xml");
this should be clear anough…
when you want to do this with php and xml and flash,
simply rename the loaded file in .php, and generate the same xml format like:
But then, only one of them displays, so could anyone just correct it?
And, how do I write to the xml? Like I write someguys name in the nameInput and 11-11-11 in the dateInput, and the message in a input. How do I get this to write it to the xml?
Ok, im not sure wich of the tuts you mean, but isnt it possible to write directly to the xml? and how?
and how do i show this in a text field: ?
// now do stuff with it
trace (“This was posted by “+itemAuthor+” on “+itemDate+”.”);
trace (itemPost);
trace (newline);
I can only get it to show only one of them.
Your at the website my friend, kirupa himself wrote a great tutorial on displaying txt w/xml. Senocular (http://www.senocular.com) has written like 4-5 tutorials which are also all here on kirupa. Just search around. At the begining of each forum check the threads that say “resources”.
as for the code i posted for you…
this.firstChild.childNodes*.childNodes[1].firstChild.nodeValue
This part loops through your xml file and finds the first node which in your case is “entry”
this.firstChild.childNodes*.childNodes[1].firstChild.nodeValue
This part points to your second set of nodes within “entry” even though it says 1 its actually the second so if you wanted to point to “myText” it would be a 0.
Forgive me if i explained this wrong, i too am just learning like you. I really would suggest just reading everything you can get your hands on and practice practice practice.
And now for the new question you added to your post:
and this line to point at myDate instead of myName: ?
Code: