Change attribute value to XML object in AS3

Is there an easy way to do this? Or do I need to parse the file and search / replace myself?

Ideal would be something like:

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

myXML.someAttribute = newValue; 
+3
source share
2 answers

Attributes are available in AS3 using a prefix @.

For instance:

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

Conclusion:

something
new
+15
source

The problem is with some attributes like @class. Imagine you want to create an HTML source and want to create a tag tag

So the code should be

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

but this is not compiled and it causes an error (at least in Flex Builder)

in this case, you can also use this:

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

+2
source

Source: https://habr.com/ru/post/1697112/


All Articles