XML.insertBefore( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
XML.insertBefore( ) Method Flash 5

insert a new sibling node before an existing node
theNode.insertBefore(newChild, beforeChild)

Arguments

newChild

An existing XML node object.

beforeChild

The child of theNode before which newChild should be inserted.

Description

The insertBefore( ) method adds newChild to theNode's child list, before beforeChild (theNode can be an XML or XMLnode instance). The insertBefore( ) method is similar to appendChild( ), but it lets us position a new node precisely in an existing XML object hierarchy.

Example

// Create a document with a P node myDoc = new XML('<P>paragraph 2</P>');     // Create another P node and a text node newP = myDoc.createElement("P"); newText = myDoc.createTextNode("paragraph 1");     // Append the text node to the new P node newP.appendChild(newText);     // Insert the new P node (including its text child) before the existing P node myDoc.insertBefore(newP, myDoc.firstChild);     trace(myDoc);  // Displays: "<P>paragraph 1</P><P>paragraph 2</P>"

See Also

XML.appendChild( ) XML.previousSibling, XML.removeNode( )



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net