Random placement

Hi -
I have a list of countries that are in an xml document.
I was wondering if here was a way to randomly load ten of these and place them on the stage in random places.

i want to get the effect of this intro:
http://www.ianschragerhotels.com/intro.html
(not the one with the black background)

thanks a lot!
zach

yup, you can do this no problem!

Do you know how to load an XML document into flash?

There are a few tutorials on this site, and some real good ones on actionscript.org.

To simplify - load the XML doc into flash, tear apart all the child nodes (the country names), assign them to variables, display those variables in dynamic text boxes, us AS to put these names all around.

Say you assigned the child node values to country1, country2, country3, etc…

Then you can use a random number generator and switch/case to randomize which name goes up.

Or if you’re not into switch/case statements, something that might actually be easier is:

var newcontry = “country”+Math.random()*50;

then you spawn new movies (using attach movie) and within the movie is a dynamic text box holding the value of “newcontry”.

If there were 50 countries.

If you post a link to the XML doc I can give it a shot.

sure - here it is:
thanks

ok great. I’m going to post this one step at a time, since it might be more helpful for forum readers.

Part 1: This is the AS for tearing apart the XML file and assigning all of the country names to the “country” object, in the form of [country.name0 = “countryname”]. This script also assumes that “countries.xml” is in the same directory as your flash file.

[AS]_root.country = new Object();
country_xml = new XML();
country_xml.ignoreWhite = true;

country_xml.onLoad = function(success) {
if (success) {
processXML(country_xml);
};
};

country_xml.load(“countries.xml”);

function processXML(country_xml){
for(i=0; i<233; i++){
_root.country[“name”+i] = country_xml.firstChild.childNodes*.firstChild.nodeValue;
}
}[/AS]

Part 2: This attaches a new movie clip at a random position, on every frame. The movie clip contains a dynamic text box that displays the variable “newdisplay”. The AS in the first frame of the movie clip pulls the value of “newdisplay” from _root.display, which is randomly generated on every frame (yeah yeah you can eliminate some code here, but whatever).

Now, I am having a problem with the fading. It appears that you can’t fade out dynamic text, so I have to make a “cover” for it, and just increase the alpha per frame of that cover. This is a bad way to do it, but I don’t know how to fix it. Ideas?

NOTE: The attached file MUST be placed in the same folder with the file labeled “countries.xml” to work.

thank you so much!!!

Originally posted by jingman
Now, I am having a problem with the fading. It appears that you can’t fade out dynamic text, so I have to make a “cover” for it, and just increase the alpha per frame of that cover. This is a bad way to do it, but I don’t know how to fix it. Ideas?

embed the font.

Thanks Kax!

You are quite welcome bigcheese. Here is the new improved file, and now they move!