03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

var doc1:XML = new XML();<br />

var doc2:XML = new XML();<br />

// create a root node <strong>and</strong> add it to doc1<br />

var rootnode:XMLNode = doc1.createElement("root");<br />

doc1.appendChild(rootnode);<br />

trace ("doc1: " + doc1); // output: doc1: <br />

trace ("doc2: " + doc2); // output: doc2:<br />

// move the root node to doc2<br />

doc2.appendChild(rootnode);<br />

trace ("doc1: " + doc1); // output: doc1:<br />

trace ("doc2: " + doc2); // output: doc2: <br />

// clone the root node <strong>and</strong> append it to doc1<br />

var clone:XMLNode = doc2.firstChild.cloneNode(true);<br />

doc1.appendChild(clone);<br />

trace ("doc1: " + doc1); // output: doc1: <br />

trace ("doc2: " + doc2); // output: doc2: <br />

// create a new node to append to root node (named clone) of doc1<br />

var newNode:XMLNode = doc1.createElement("newbie");<br />

clone.appendChild(newNode);<br />

trace ("doc1: " + doc1); // output: doc1: <br />

attributes (XMLNode.attributes property)<br />

public attributes : Object<br />

An object containing all of the attributes of the specified XML instance. The XML.attributes<br />

object contains one variable for each attribute of the XML instance. Because these variables<br />

are defined as part of the object, they are generally referred to as properties of the object. The<br />

value of each attribute is stored in the corresponding property as a string. For example, if you<br />

have an attribute named color, you would retrieve that attribute's value by specifying color as<br />

the property name, as the following code shows:<br />

var myColor:String = doc.firstChild.attributes.color<br />

Example<br />

The following example shows the XML attribute names:<br />

// create a tag called 'mytag' with<br />

// an attribute called 'name' with value 'Val'<br />

var doc:XML = new XML(" item ");<br />

// assign the value of the 'name' attribute to variable y<br />

var y:String = doc.firstChild.attributes.name;<br />

trace (y); // output: Val<br />

XMLNode 699

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!