Why wouldn’t they just say that?

A reader commented on my ScrollPane article, saying “why wouldn’t they just say that?”

I’ve found myself asking this question more and more as I’ve been diving into Flex and ActionScript 3.

For example, here is how to get the name of the root node of an XML object:

AS2:

myXML.childNodes[0].nodeName;

AS3:

myXML.name();

In AS3, nodeName has mysteriously disappeared, and the Migration Guide makes no mention of name() as its new equivalent.

In fact, the XML Class Definition for ActionScript 3 describes name() as “Gives the qualified name for the XML object.”, which led me to believe it was relevant only namespace-qualified XML tags and not useful for getting a root node’s name.

Splitting hairs, perhaps, but a good little tip nonetheless.

, , ,

Advertisements
  1. #1 by Dan Wilday on January 26, 2007 - 5:01 pm

    I don’t have anything on my machine here at work to test it so I’ll just ask:
    is myXML.name() actually a method or is .name a property of the XML Object?

    So, am I correct in assuming that you no longer have to navigate through root node but can jump right into the child nodes of the XML?

    For example to get the fourth childNode of an XML object is AS2 you’d do the following:
    myXML.firstChild.childNode[3];

    Am I correct in assuming they’ve killed this in AS3 allowing you to use just the following:
    myXML.childNode[3];

  2. #2 by admin on January 29, 2007 - 10:50 am

    myXML.name() is a built-in method for getting the root node’s name, regardless of whether it’s namespace-qualified or not.

    your assumption is almost corrected but the syntax is different in AS3:

    myXML.children()[3];

    There are code zealots out there who would take issue with having () and [] right next to each other, but meh, I just need this to work.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

  • Least-Old Tweets

    Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: