Search code examples
javascriptxmle4x

e4x newb woes - attribute trace


Sorry if I'm doing anything really dumb, but could anybody see anything immediately wrong with the following?

var layout = new XML()

layout=
<layout color="red">
</layout>

function init()
{ 
post(layout.@color);
}

it returns what I assume to be a ram address rather than the value.

In the event that the software in question wants an object of type string, what is the best way to enforce that? I doubt thats the cas, but am willing to try


Solution

  • A string cast should work fine, e.g.:

    trace(String(layout.@color));
    

    Note that in your example there's no need to assign a new XML object to layout, since you overwrite it with the next assignment one line later.

    This article is highly useful if you're just getting started with E4X.