Skip to main content
Inspiring
May 30, 2015
Question

Changing the content of a xml from as3 and saving it

  • May 30, 2015
  • 1 reply
  • 603 views

Hi guys...

I have a simple question... I access a xml from my code and read a value... and I need to change it to another one, since I will access the xml from the other stage... can it be done?

I have used replace but when I check the original xml, the value remains the same:

var xmlldr:URLLoader = new URLLoader();

xmlldr.addEventListener(Event.COMPLETE, loadComplete);

xmlldr.addEventListener(IOErrorEvent.IO_ERROR, loadError);

var xmlContent:XML;

var bT:int;

xmlldr.load(new URLRequest("c.xml"));

function loadComplete(e:Event):void {

xmlContent = new XML(xmlldr.data);

xmlldr.removeEventListener(Event.COMPLETE, loadComplete);

xmlldr.removeEventListener(IOErrorEvent.IO_ERROR, loadError);

trace(xmlContent.gCg.fBT);

ChangeBT();

}

function loadError(e:IOErrorEvent):void {

  }

function ChangeBT():void {

  bT = 2000;

  xmlContent.gCg.fBT.replace("1000", bT);

  trace(xmlContent.gCg.fBT);

}

Can it be done? meaning? can I, by changing the value on the first stage, have the original xml file value changed as well?

Thanks!!!

This topic has been closed for replies.

1 reply

kglad
Community Expert
May 30, 2015

is this an air app?  a web app?  an ios/android app?

SirMarleyAuthor
Inspiring
May 30, 2015

a web app...

I have tried with:

var fileb:FileReference = new FileReference;

    fileb.save( xmlContent, "c.xml" );

and it seems to work, however, if I put the code in the first stage and stop it there, it works fine and allows me to save the new *.xml, but, if after the code I try to go to the second stage (gotoAndPlay) it throws me this error:

TypeError: Error #1086: The replace method only works on lists with an element.

  at XMLList/http://adobe.com/AS3/2006/builtin::replace()

  at Application_fla::MainTimeline/ChangeBT()[Application_fla.MainTimeline::frame1:24]

  at Application_fla::MainTimeline/loadComplete()[Application_fla.MainTimeline::frame1:16]

  at flash.events::EventDispatcher/dispatchEventFunction()

  at flash.events::EventDispatcher/dispatchEvent()

  at flash.net::URLLoader/onComplete()

kglad
Community Expert
May 30, 2015

what's on line 24 of frame 1 that's triggering the error when you execute that goto?