1

I have an Adobe Air 2 app developed for single desktop usage. It reads/write XML files stored in My Documents. (Win)

I must adapt this Air 2 app to read/write data through a server from several computers of a network.

I'd like to find a working sample in order to modify the single desktop app and make it server based, with XML read/write capabilities.

Any help will be highly regarded.

Sergio
  • 608
  • 12
  • 35
  • do you want to save XML on desktop or server? – Pier Nov 19 '13 at 19:37
  • XML must be saved on server, because there are 2 different desktop computers with desktop apps that will read/write the XML an another one that will only read the XML data. – Sergio Nov 21 '13 at 01:48
  • You will need a server solution for that, AS3 cannot save on a server. Commonly PHP is used. (like Mika suggested) – Pier Nov 21 '13 at 21:36

2 Answers2

1

There are many ways of doing it, thousands... But in any way you chose, you'll need a backend script running on the server to handle incoming requests (POST or GET). Or eventually a socket server but that is more complicated if you're not sure what you're doing.

Look into form submission scripts with PHP, maybe start by reading this post: http://johannesluderschmidt.de/save-xml-and-text-files-from-flash-to-your-hd-with-as3-and-php/127/

Good luck!

mika
  • 1,411
  • 1
  • 12
  • 23
0
    import flash.text.*;


var xmlData:XML = new XML();

var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.load(new URLRequest("exemple.xml"));
    xmlLoader.addEventListener(Event.COMPLETE, function(e:Event){
        xmlData=new XML(e.target.data);

        var myText:TextField = new TextField();
        myText.text=xmlData;
        addChild(myText);
        myText.type = TextFieldType.INPUT;
    });


btn_save.buttonMode = true;
btn_save.addEventListener(MouseEvent.CLICK, saveXML)

function saveXML(event:MouseEvent):void {
    var ba:ByteArray = new ByteArray();
    ba.writeUTFBytes(xmlData);
    var file:FileReference = new FileReference();
    file.save(ba, "exemple.xml");
}
chakroun yesser
  • 1,407
  • 1
  • 12
  • 18
  • Did you test it by yourself, chakroun yesser? What characteristics must have the server configuration in order to allow read/write tasks from the desktop apps? – Sergio Nov 20 '13 at 03:07
  • yes this is the code i'm working with to edit xml in my admin application, the xml file in server must just have 770 privilege to read and write on it, this is what you need? – chakroun yesser Nov 20 '13 at 08:04
  • What about the connection? Your admin app keep connected during it use (as a session), or it makes a connection with every load/write function? . I guess the path must be absolute. I'm right? I think it will work, chakroun. I can't test it right now becouse I'm travelling. I'll comeback next week, that's why I'm making more questions. I think, also, I can trust in you, so I'll give you the bounty after receive your answers. Many thanks. – Sergio Nov 20 '13 at 13:20
  • Mika says that I need a backend script running on the server to handle incoming requests (POST or GET). Are you using something like that? I'll give the bounty after receive sample/answers about the backend script. Many thanks. – Sergio Nov 20 '13 at 13:32
  • All right, so if you want to write/read xml from server, i think that the best solution is first 'change "exemple.xml" to http:// your_host/exemple.xml' (to read xml from server) , second, to save it on the server create php file that receive data with POST or GET and simply use this link to save the file http://stackoverflow.com/questions/3418376/how-to-save-changed-simplexml-object-back-to-file – chakroun yesser Nov 20 '13 at 21:02