0

I'm trying to update a value in a subnode of an XML structure. New value should come from an Input TextField whose instance name is the same of the value of the attribute of the node I should update.

For example, when focusing out textfield called "label10", I should edit the node:

<label id="label10">
    <eng>Description</eng>
    <de>DE Description</de>
</label>

...and that's ok, I achieved it using this callback function:

private function onFocusOut (evt:FocusEvent):void {
        var nodeToModify:XML = xmlFillData.label.(@id==evt.target.name)[0];
        trace ("nodeToModify is " +nodeToModify );
}

Now my problem is I wish to replace the content of the subnode eng or de, depending on a variable defined in a static class called VarHolder, but I'm not able to do it.

I've tried to use this line inside the callback function:

 nodeToModify.replace (VarHolder.activeLang , evt.target.text);

but then if I trace nodeToModify, this is the result ( tag disappeared)

<label id="label10">
rrr
<de>DE Description</de>

Any help?


EDIT (and solved): trying to implement @jens answer. This is how I did it

 nodeToModify.replace (VarHolder.activeLang,  new XML("<" + VarHolder.activeLang + ">" +  evt.target.text + "</" + VarHolder.activeLang + ">"));

1 Answer 1

2

XML.replace() does expect the 2nd parameter to be an XML-Object which then is converted to a (XML-)string. Meaning: it replaces '<eng>Description</eng>' with 'rrr' and its working as intended. You need to pass it an XML-object or pass it '<eng>rrr</eng>'. If the value of VarHolder.activeLang is plainly 'eng', you could use this:

nodeToModify.replace (VarHolder.activeLang ,  "<" + VarHolder.activeLang + ">" + 
                           evt.target.text + "</" + VarHolder.activeLang + ">");

See this link for more information on XML.replace(): http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html#replace%28%29

Sign up to request clarification or add additional context in comments.

1 Comment

thx @jens, I tried this solution before posting the question, I was hoping there was another solution to do it. By the way, I gave up with that because when tracing it I was reading: &lt;eng&gt;rrr&lt;/eng&gt; any idea of how to get rid of that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.