[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Random Text from XML File

Posted on 2011-10-04
11
Medium Priority
?
418 Views
Last Modified: 2012-05-12
I have been all over the Internet looking for a random text generator that used more than one variable. I do not have time to create it.

What I have is a series of old baseball newspaper headlines that I want to generate randomly as the visitor clicks through the website or automatically generate a new one at a given interval if they remain on the page for longer.

Ideally, I would like something that uses Flash 8 (AS2) and XML so that I only need to edit the XML file to add a new headline.

I have the Flash file I want to dump the data into set up like and old newspaper, so I need to place the headline in one place, with its own special type formatting, and the year in another, with its own formatting.

Any ideas?

Thanks in advance!

Tammi
0
Comment
Question by:TammiCole
  • 6
  • 5
11 Comments
 
LVL 29

Expert Comment

by:dgofman
ID: 36911856
Can you attach your XML file?
0
 

Author Comment

by:TammiCole
ID: 36911904
Sure! Thanks for the help! headlines.xml
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36911925
Are you using AS2 or AS3?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:dgofman
ID: 36911935
and do you want to load XML at runntime or embed to SWF?
0
 

Author Comment

by:TammiCole
ID: 36911945
AS2 and it needs to be editable in Flash 8. I am attaching what I have so far. It pulls in the headlines, but doesn't change...doesn't rotate. xmldata.fla xmldata.html
0
 

Author Comment

by:TammiCole
ID: 36911987
Which would cause less site-load lag?
0
 

Author Comment

by:TammiCole
ID: 36911995
Oh, it would also be nice if there was a button that would allow the user to flip through the headlines at their leisure...
0
 
LVL 29

Accepted Solution

by:
dgofman earned 2000 total points
ID: 36912019
You completed 95% :)

function loadXML(loaded) {
	if (loaded) {
		setInterval(loop, 1000, this.firstChild.childNodes);
		loop(this.firstChild.childNodes); //start now
	} else {
		content = "file not loaded!";
	}
};

var lastIndex:Number;
function loop(nodes):Void{
	var index:Number = random(nodes.length);
	if(lastIndex == index){
		loop(nodes)
		return;
	}
	lastIndex = index;
	var node:XML = nodes[index];
	_root.myyear = getValue(node.childNodes[0].firstChild.nodeValue);
	_root.date = getValue(node.childNodes[1].firstChild.nodeValue);
	_root.headline = getValue(node.childNodes[2].firstChild.nodeValue);
	_root.subheadline = getValue(node.childNodes[3].firstChild.nodeValue);
	myyear_txt.text = _root.myyear;
	date_txt.text = _root.date;
	headline_txt.text = _root.headline;
	subheadline_txt.text = _root.subheadline;
};

function getValue(str:String):String{
	return str != undefined ? str : "";
};

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("headlines.xml");

Open in new window

0
 

Author Comment

by:TammiCole
ID: 36912064
I guess I was further along than I thought :) Will it start over when the visitor goes to another page? Is there a way to make it totally random? Also, is there a way to add a button to stop the auto play so they can flip through it once by one? If we can't do both, I would really like it to be completely random first :)

Thanks again!
0
 

Author Closing Comment

by:TammiCole
ID: 36912676
Thank you very much for your help!
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36912705
Welcome and thanks for saving my time :-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to count occurrences of each item in an array.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question