Flash MX: XML News

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

thanks,
fatnslow

this tutorial can give you an idea
http://www.kirupa.com/web/xml_guestbook.htm

Hmmm, I tried some, but really need some help…
To much AS at one time there…could anyone help please?

Anyone able to help? Please

just create an xml file:

news.xml


<data>
   <news author="someguy" date="11-8-2004" post="BlaBlaBlaBla 1" />
   <news author="someguy" date="11-8-2004" post="BlaBlaBlaBla 2" />
   <news author="someguy" date="11-8-2004" post="BlaBlaBlaBla 3" />
   <news author="someguy" date="11-8-2004" post="BlaBlaBlaBla 4" />
   <news author="someguy" date="11-8-2004" post="BlaBlaBlaBla 5" />
</data>

And in flash, you can read this stuff with:


// 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:


echo "<news author=\"$author\" date=\"$date\" post=\"$post\" />";

you can use mysql to get news posts…
if you have done this, you can get the form in flash to, using loadVariables…

hope that helped you allot

Ok, it helped alot, but I can’t get my text field to display it as it does when it trace.
Not good with as, but tried something like this:

news = " - “+itemAuthor+” : “+itemDate+” - ";
news = (itemPost);
news = (newline);

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?

Sorry if you got confused

thanks,
fatnslow

Anyone?

Thanks,
fatnslow

use php and loadVars to send the data to a php script, then let php to do the rest (storing it in a database)

there is an tutorial on kirupa on that one…

OK, ill check it out.

thanks,
fatnslow

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 :slight_smile:
trace (“This was posted by “+itemAuthor+” on “+itemDate+”.”);
trace (itemPost);
trace (newline);
I can only get it to show only one of them.

Just can’t figure it out…

thanks for all the help so far,
fatnslow

Anyone able to help?

I know Dulcinea already said this, but, this http://www.kirupa.com/web/xml_guestbook.htm tutorial shows you how to do pretty much exactly what you’re asking.

Make sure the little render html button is selected in the properties box of your dynamic text field. Then try this.


news = " - "+itemAuthor+" : "+itemDate+" - <br><br>"+itemPost+"<br><br>";

basically you can use <br> to add spaces. If two <br>'s is too much, remove one… if it’s not enough, add one! hope that helps.

Ok, think I’m not so far from getting it. But how do I get this line :


this.firstChild.childNodes*.firstChild.firstChild.nodeValue

to point at the myHeadline text instead of myText in this xml? :


<guestbook>
	<entry myName="Simen" myDate="13.08.2004">
		 <myText>Bla bla bla bla.</myText>
		 <myHeadline>Ny Lay-out! </myHeadline>
	</entry>
</guestbook>

and this line to point at myDate instead of myName: ?


this.firstChild.childNodes*.attributes.myName

Thanks for any help,
fatnslow

Anyone able to help again?

thanks,
fatnslow

Anyone able to help again??

Thanks,
fatnslow

Anyone able to help on the post over?

Thanks,
fatnslow

this is a complete guess because you havent showed us your code for the loop but:

this.firstChild.childNodes*.childNodes[1].firstChild.nodeValue

Thanks! It was correct. But could you just explain it? or an web site wich makes things clearer?

Thanks,
fatnslow

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:

this.firstChild.childNodes*.attributes.myName

change myName to myDate… thats it :slight_smile:

Hope this helps a lil.