# Random placement

**URL:** <https://forum.kirupa.com/t/random-placement/24273>\
**Category:** Uncategorized\
**Created:** [June 28, 2003, 3:59am UTC](https://forum.kirupa.com/t/random-placement/24273 "2003-06-28T03:59:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![thebigcheese](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@thebigcheese](https://forum.kirupa.com/u/thebigcheese)\
**Post date:** [June 28, 2003, 3:59am UTC](https://forum.kirupa.com/t/random-placement/24273/1 "2003-06-28T03:59:36Z")

</div>

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](http://www.ianschragerhotels.com/intro.html)  
(not the one with the black background)

thanks a lot!  
zach

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 28, 2003, 5:35am UTC](https://forum.kirupa.com/t/random-placement/24273/2 "2003-06-28T05:35:34Z")

</div>

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](http://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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 28, 2003, 6:00am UTC](https://forum.kirupa.com/t/random-placement/24273/3 "2003-06-28T06:00:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 28, 2003, 1:07pm UTC](https://forum.kirupa.com/t/random-placement/24273/4 "2003-06-28T13:07:30Z")

</div>

sure - here it is:  
thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 29, 2003, 5:06am UTC](https://forum.kirupa.com/t/random-placement/24273/5 "2003-06-29T05:06:27Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 29, 2003, 5:55am UTC](https://forum.kirupa.com/t/random-placement/24273/6 "2003-06-29T05:55:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 29, 2003, 1:03pm UTC](https://forum.kirupa.com/t/random-placement/24273/7 "2003-06-29T13:03:09Z")

</div>

thank you so much!!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 29, 2003, 1:38pm UTC](https://forum.kirupa.com/t/random-placement/24273/8 "2003-06-29T13:38:57Z")

</div>

> _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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 29, 2003, 3:30pm UTC](https://forum.kirupa.com/t/random-placement/24273/9 "2003-06-29T15:30:05Z")

</div>

Thanks Kax!

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