How to set a variable attribute of an xml element in actionscript 3?
Something that should be very easy has been the quest of my day.
How do you set a variable attribute of a xml element?
开发者_JS百科This is what I expected to work:
xmlElement.attribute(variableAttr) = "the variable attribute is set to this string";
However, I'm getting some error that this value can only be retrieved as a reference and not set.
Ofcourse, the following does not work either as it will look for the attribute named "variableAttr" and not for the attribute named after the value of the variable variableAttr:
xmlElement.@variableAttr = "example";
You have to enclose your variable name with square bracket @[my var]
:
xmlElement.@[variableAttr] = "example";
Try
xmlElement.attributes.variableAttr = "example";
example code:
var d:XMLDocument = new XMLDocument(); var e:XMLNode; d.appendChild(e = d.createElement("Root")); e.attributes.val = "100"; trace(d.toString()); //prints <Root val="100" />
精彩评论