Question

Is there a easy way to do this? Or do I have to parse the file and do some search/replacing on my own?

The ideal would be something like:

var myXML: XML = ???; // ... load xml data into the XML object

myXML.someAttribute = newValue; 
Was it helpful?

Solution

Attributes are accessible in AS3 using the @ prefix.

For example:

var myXML:XML = <test name="something"></test>;
trace(myXML.@name);
myXML.@name = "new";
trace(myXML.@name);

Output:

something
new

OTHER TIPS

Problem is with some attributes, like @class. Just imagine you want to create HTML source and want to create tag test

So code should be

var myDiv:XML = test myDiv.@class = "myClass"; //I want to set it here, because it can vary

but this is not compilable and it throw error (at least in Flex Builder)

in that case you can also use this:

myDiv.@['class'] = "myClass";

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top