This content has been marked as final. Show 8 replies
Correction - the line to delete the attribute shouldn't include the 'build' node. Either way, I've got that figured out. Now, I need to figure out how to add an attribute.
It is unbelievably simple:
myNode.@myAttribute = "myValue";
I'm sorry, I should have explained my situation better. That's exactly the result I'm looking for, but I need to be able to set it dynamically and I'd like not to have to use a massive switch statement to switch between the new attributes. Example.
function setAttribute( attributeName:String ):void
myNode.@attributeName = "myValue";
Problem is '@attributeName' is taken literally where I need more of a 'this[ attributeName ]' = "myValue";
myNode.attribute("attributeName") = "myValue";
I tried that and I don't know if I'm not setting it up correctly or what, but I'm getting the following error:
1105: Target of assignment must be a reference value.
This is how I'm setting it up:
myXML.item[ itemIndex ].attribute( "attributeName" ) = "myValue";
Any clue on what I'm doing wrong? Thanks.
That looks ok.
Break it up into steps so you can make sure you have valid references at each point.
I must fundamentally be doing something wrong. I've ran through a dozen or so tests and even with a simple test, I can't get it to work:
var x1:XML = new XML( '<item type="test" />' );
x1.@name = "test 1"; //This works
x1.attribute( "name" ) = "test 2"; //This produces an error with or without the line above present.
I really don't want the second line (the one with @name). I want to be able to dynamically add run-time attributes. Any ideas? Thanks.
Ok, I just stumbbled upon the solution:
x1.@[ "name" ] = "test 2";
That appears to do it. I don't know if the other way just doesn't work or if I was simply doing it wrong. Thanks for all your help.