• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

Random Text from XML File

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
TammiCole
Asked:
TammiCole
  • 6
  • 5
1 Solution
 
dgofmanCommented:
Can you attach your XML file?
0
 
TammiColeAuthor Commented:
Sure! Thanks for the help! headlines.xml
0
 
dgofmanCommented:
Are you using AS2 or AS3?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
dgofmanCommented:
and do you want to load XML at runntime or embed to SWF?
0
 
TammiColeAuthor Commented:
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
 
TammiColeAuthor Commented:
Which would cause less site-load lag?
0
 
TammiColeAuthor Commented:
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
 
dgofmanCommented:
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
 
TammiColeAuthor Commented:
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
 
TammiColeAuthor Commented:
Thank you very much for your help!
0
 
dgofmanCommented:
Welcome and thanks for saving my time :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now