How do I get the root node of an XML object in Actionscript?
One would think that I could say this:
var Node:XMLNode = XMLVar as XMLNode;
But although XMLVar is of type XML, Node will = null.
So how do I do it?
How do I get the root node of an XML object in Actionscript?
One would think that I could say this:
var Node:XMLNode = XMLVar as XMLNode;
But although XMLVar is of type XML, Node will = null.
So how do I do it?
You code is a little confusing because you are using uppercase first characters for you variable names. Take a look at Adobe's coding conventions for AS3.
var xmlData:XML = new XML();
var node:XMLNode = xmlData.firstChild();
This example is pretty useless, but it just demonstrate the method.
Use the XML object's firstChild method. To get the first node as a XMLNode object.
var node:XMLNode = xmlVar as XMLNode;
although xmlVar is of type
XML
XML
and XMLNode
are not compatible in ActionScript-3. XML
class of AS2 (and its related classes) has been renamed to flash.xml.XMLDocument
in AS3.
The
XMLNode
/XMLDocument
class represents the legacyXML
object that was present in ActionScript 2.0 and that was renamed in ActionScript 3.0. In ActionScript 3.0, consider using the new top-levelXML
class and related classes instead, which support E4X (ECMAScript for XML). TheXMLNode
/XMLDocument
class is present for backward compatibility.
An object of type XML
cannot be cast directly to XMLNode
. Since you're trying to cast with as
keyword, it just returns null
instead of raising an alarm saying the cast failed.
And as already mentioned, consider using lowerCase names for variables, as UpperCase names are normally used for naming classes.