private function someFunction(myObject:Identifiable) : void {
var myXML:XML = <objectreference objectid="{myObject.id}">;
myRoot.appendChild(myXML);
}
Then later on in my code I was doing an XPath query like so:
var list:XMLList = myRoot.objectReference.(@objectId=='foo');
Can you spot the problem? It took me way to long to notice the problem, which was obvious once I admitted to myself that I needed to actually use the debugger.
The problem was that I had double quotes around the expression {myObject.id}. The code should have been:
Since having it incorrect with the quotes doesn't cause an error, I was really baffled on this.
private function someFunction(myObject:Identifiable) : void {
var myXML:XML = <objectreference objectId={myObject.id}/>;
myRoot.appendChild(myXML);
}
3 comments:
(@objectId=='foo'); could also be problematic since using @ in an E4X filter can throw an error if an element of the list does not have the specified attribute.
A safer approach that avoids this error is using the attribute() method in place of @.
I saw the other obvious problem: setting "objectid" but referring to "objectId", but I guess that is just a typo in the post =)
Good catch Theo. You're right, that was a typo.
Post a Comment