# Xml - insertBefore node (problem)

**URL:** <https://forum.kirupa.com/t/xml-insertbefore-node-problem/211494>\
**Category:** Uncategorized\
**Created:** [January 2, 2007, 10:10am UTC](https://forum.kirupa.com/t/xml-insertbefore-node-problem/211494 "2007-01-02T10:10:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbailey](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jbailey/32/2380_2.png) [@jbailey](https://forum.kirupa.com/u/jbailey)\
**Post date:** [January 2, 2007, 10:10am UTC](https://forum.kirupa.com/t/xml-insertbefore-node-problem/211494/1 "2007-01-02T10:10:45Z")

</div>

Flashers,

I can’t seem to figure out why the following isn’t working. First off, \_global.news\_index is working properly. With that said, when I try to insertBefore using a dynamic method, it doesn’t work. Instead it generates as if news\_index is equaling 0 (everywhere else news\_index is showing the correct location).

```auto
    [FONT=Courier New][LEFT][COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]news_xml.[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]hasChildNodes[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
        [COLOR=#000000] **var** [/COLOR] nodePlace:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#000000] **_global** [/COLOR].[COLOR=#000080]news_index[/COLOR];
        [COLOR=#000000] **var** [/COLOR] insertPoint:[COLOR=#0000ff]XMLNode[/COLOR] = news_xml.[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]childNodes[/COLOR][COLOR=#000000][[/COLOR]nodePlace[COLOR=#000000]][/COLOR];
        news_xml.[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]insertBefore[/COLOR][COLOR=#000000]([/COLOR]entryNode, insertPoint[COLOR=#000000])[/COLOR];
    [COLOR=#000000]}[/COLOR][COLOR=#0000ff]else[/COLOR] news_xml.[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]appendChild[/COLOR][COLOR=#000000]([/COLOR]entryNode[COLOR=#000000])[/COLOR];

```

[/LEFT]  
[/FONT]

[COLOR=Red]\*\*ANSWER  
\*\*[COLOR=Black]

```auto

var nodePlace:Number = _global.news_index;

```

Must be placed outside the if statement and defined before the If-statement.

Does anybody know why? … _[COLOR=Red]It works, but I’d like to know why![/COLOR]_ [/COLOR]  
[/COLOR]
