# XML insertBefore() wont work

**URL:** <https://forum.kirupa.com/t/xml-insertbefore-wont-work/212823>\
**Category:** flash\
**Created:** [January 14, 2007, 8:55pm UTC](https://forum.kirupa.com/t/xml-insertbefore-wont-work/212823 "2007-01-14T20:55:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rille31](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@rille31](https://forum.kirupa.com/u/rille31)\
**Post date:** [January 14, 2007, 8:55pm UTC](https://forum.kirupa.com/t/xml-insertbefore-wont-work/212823/1 "2007-01-14T20:55:11Z")

</div>

Im working on a flash/XML CMS for a photo gallery and Im having trouble with the **insertBefore()** function.

```auto

<images>
<image thumb="carneruds.jpg" />
<image thumb="slides.jpg" />
<image thumb="hollywood.jpg" />
</images>

```

```php
function createNode():Void { 
var imageNode:XMLNode = myXML.firstChild.firstChild.cloneNode(true); 
imageNode.attributes.thumb = currPath+filename_txt.text; 
myXML.insertBefore(imageNode, myXML.firstChild.firstChild); 
trace(myXML); 
} 

```

I can insert the node with [FONT=Courier New][COLOR=#0000bb]myXML[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]insertBefore[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]imageNode[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]myXML[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]firstChild[/COLOR][COLOR=#007700]); [/COLOR][/FONT]  
but that inserts the node before my rootnode.  
When I try to insert it inside the xml trea ([FONT=Courier New][COLOR=#0000bb]myXML[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]insertBefore[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]imageNode[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]myXML[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]firstChild[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]firstChild[/COLOR][COLOR=#007700])[/COLOR][/FONT])  
it wont work, anybody have an idea?
