如何在actionscript 3中设置xml元素的变量属性?

Tom*_*Tom 2 xml variables dynamic actionscript-3

应该很容易的事情一直是我一天的追求.

如何设置xml元素的变量属性?

这是我期望的工作:

xmlElement.attribute(variableAttr) = "the variable attribute is set to this string";
Run Code Online (Sandbox Code Playgroud)

但是,我收到一些错误,该值只能作为引用检索而不能设置.

当然,以下内容不起作用,因为它将查找名为"variableAttr"的属性,而不是查找变量variableAttr的值后面的属性:

xmlElement.@variableAttr = "example";
Run Code Online (Sandbox Code Playgroud)

Pat*_*ick 9

您必须用方括号括起变量名称@[my var]:

xmlElement.@[variableAttr] = "example";