views:

4282

answers:

2

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;

+9  A: 

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
Swaroop C H
You can also use the following syntax to access attributes: myXML.attribute("id"), myXML["@id"], and myXML.@["id"]. http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#attribute_identifier
zproxy
+1  A: 

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";