# Trying to get away from \_root!

**URL:** <https://forum.kirupa.com/t/trying-to-get-away-from--root/266053>\
**Category:** flash\
**Created:** [July 15, 2008, 8:53pm UTC](https://forum.kirupa.com/t/trying-to-get-away-from--root/266053 "2008-07-15T20:53:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Finkster](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@Finkster](https://forum.kirupa.com/u/Finkster)\
**Post date:** [July 15, 2008, 8:53pm UTC](https://forum.kirupa.com/t/trying-to-get-away-from--root/266053/1 "2008-07-15T20:53:33Z")

</div>

Hello, how do I adjust this AS2 code to eliminate the \_root so this MC can be used anywhere in a .swf?

var dados:XML = new XML();  
dados.ignoreWhite = true;  
dados.load(‘children.xml’);  
dados.onLoad = function():Void {  
qtd = this.childNodes[0].childNodes.length;

for (i=0; i\<qtd; i++) {  
bt.duplicateMovieClip(‘bt’+i, \_root.getNextHighestDepth());  
\_root[‘bt’+i].\_y += i_22;  
\_root[‘bt’+i].t = this.childNodes[0].childNodes_.childNodes[0].firstChild;  
\_root[‘bt’+i].texto.text = \_root[‘bt’+i].t;  
\_root[‘bt’+i].link = this.childNodes[0].childNodes\*.childNodes[1].firstChild;  
\_root[‘bt’+i].onPress = function() {  
getURL(this.link, “\_self”);  
};  
\_root[‘bt’+i].onRollOver = function() {  
this.gotoAndStop(2);  
};  
\_root[‘bt’+i].onRollOut = function() {  
this.gotoAndStop(1);  
};  
}  
bt.unloadMovie();  
};  
stop();

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 15, 2008, 9:47pm UTC](https://forum.kirupa.com/t/trying-to-get-away-from--root/266053/2 "2008-07-15T21:47:38Z")

</div>

First Way :---------------

var dados:XML = new XML();  
dados.ignoreWhite = true;  
dados.load(‘data.xml’);  
refer = this;

dados.onLoad = function():Void  
{  
qtd = this.childNodes[0].childNodes.length;

for (i = 0; i \< qtd; i++)  
{  
bt.duplicateMovieClip(‘bt’+i, refer.getNextHighestDepth());  
refer[‘bt’+i].\_y += i_22;  
refer[‘bt’+i].t = this.childNodes[0].childNodes_.childNodes[0].firstChild;  
refer[‘bt’+i].texto.text = refer[‘bt’+i].t;  
refer[‘bt’+i].link = this.childNodes[0].childNodes\*.childNodes[1].firstChild;

refer[‘bt’+i].onPress = function()  
{  
getURL(this.link, “\_self”);  
};

refer[‘bt’+i].onRollOver = function()  
{  
this.gotoAndStop(2);  
};  
refer[‘bt’+i].onRollOut = function()  
{  
this.gotoAndStop(1);  
};  
}

bt.unloadMovie();  
};  
stop();

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 15, 2008, 9:49pm UTC](https://forum.kirupa.com/t/trying-to-get-away-from--root/266053/3 "2008-07-15T21:49:50Z")

</div>

Second Method:

import mx.utils.Delegate;

var dados:XML = new XML();  
dados.ignoreWhite = true;  
dados.onLoad = Delegate.create(this,loaded);  
dados.load(‘data.xml’);

function loaded()  
{  
var qtd = this.childNodes[0].childNodes.length;

for (i = 0; i \< qtd; i++)  
{  
bt.duplicateMovieClip(‘bt’+i, this.getNextHighestDepth());  
this[‘bt’+i].\_y += i_22;  
this[‘bt’+i].t = this.childNodes[0].childNodes_.childNodes[0].firstChild;  
this[‘bt’+i].texto.text = this[‘bt’+i].t;  
this[‘bt’+i].link = this.childNodes[0].childNodes\*.childNodes[1].firstChild;

this[‘bt’+i].onPress = function()  
{  
getURL(this.link, “\_self”);  
};

this[‘bt’+i].onRollOver = function()  
{  
this.gotoAndStop(2);  
};  
this[‘bt’+i].onRollOut = function()  
{  
this.gotoAndStop(1);  
};  
}

bt.unloadMovie();  
};  
stop();

---

<div class="post-metadata">

**Author:** ![Finkster](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@Finkster](https://forum.kirupa.com/u/Finkster)\
**Post date:** [July 15, 2008, 10:06pm UTC](https://forum.kirupa.com/t/trying-to-get-away-from--root/266053/4 "2008-07-15T22:06:46Z")

</div>

Thanks for your reply

I tried both your first method, and also “this.\_lockroot = true;” above my origional script and they both work great!

Only now, the text from my XML doesn’t show up when I use these methods elseware in the SWF. I know that it is reading the XML because when I rename the actual .XML as a test, a path error comes up in the output.

---

<div class="post-metadata">

**Author:** ![Finkster](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@Finkster](https://forum.kirupa.com/u/Finkster)\
**Post date:** [July 15, 2008, 11:51pm UTC](https://forum.kirupa.com/t/trying-to-get-away-from--root/266053/5 "2008-07-15T23:51:30Z")

</div>

Upon further testing, the XML text references **show up** when I run “Test Scene” from within the MC.

But when I test-run the whole thing, the mouse overs and the duplicateMovieClip command both work, but no text???

---

<div class="post-metadata">

**Author:** ![Finkster](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@Finkster](https://forum.kirupa.com/u/Finkster)\
**Post date:** [July 16, 2008, 12:15am UTC](https://forum.kirupa.com/t/trying-to-get-away-from--root/266053/6 "2008-07-16T00:15:14Z")

</div>

Here is my XML file if this helps 🙂  
It sems as if the “\<![CDATA[???]]\>” commands are ignored when the MC is not on the main timeline even though everything else works.

\<?xml version=“1.0” encoding=“UTF-8”?\>  
\<menu\>  
\<item\>  
\<texto\>  
\<![CDATA[Link 1]]\>  
\</texto\>  
\<link\>  
\<![CDATA[children.php]]\>  
\</link\>  
\</item\>  
\<item\>  
\<texto\>  
\<![CDATA[Link 2]]\>  
\</texto\>  
\<link\>  
\<![CDATA[children.php]]\>  
\</link\>  
\</item\>  
\<item\>  
\<texto\>  
\<![CDATA[Link 3]]\>  
\</texto\>  
\<link\>  
\<![CDATA[children.php]]\>  
\</link\>  
\</item\>  
\<item\>  
\<texto\>  
\<![CDATA[Link 4]]\>  
\</texto\>  
\<link\>  
\<![CDATA[children.php]]\>  
\</link\>  
\</item\>  
\<item\>  
\<texto\>  
\<![CDATA[Link 5]]\>  
\</texto\>  
\<link\>  
\<![CDATA[children.php]]\>  
\</link\>  
\</item\>  
\</menu\>

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 16, 2008, 12:26am UTC](https://forum.kirupa.com/t/trying-to-get-away-from--root/266053/7 "2008-07-16T00:26:51Z")

</div>

are you able to read in  
\<item\>  
\<texto\>

tags?

---

<div class="post-metadata">

**Author:** ![Finkster](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@Finkster](https://forum.kirupa.com/u/Finkster)\
**Post date:** [July 16, 2008, 12:49am UTC](https://forum.kirupa.com/t/trying-to-get-away-from--root/266053/8 "2008-07-16T00:49:00Z")

</div>

[quote=sparkdemon;2359355]are you able to read in  
\<item\>  
\<texto\>

tags?[/quote]

I can tell that the \<item\> tag works because it duplicates the bt MC the amount of times I have that tag in there. For example, It outputs 5 MC fields and then 4 when I edited one of the \<item\> tags out.
