A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: XML exporting, PHP co-operation?

  1. #1
    Member
    Join Date
    Sep 2007
    Posts
    31

    XML exporting, PHP co-operation?

    So, I have written a AS 3 project that basically opens an XML file, and allows the user to edit the contents of the file. I need a way to write the new information over the old file, but I have absolutly no real idea of where I need to start with this. I know the webservice I am using uses PHP scripts, and I have already implemented some form-mail services but I don't know of a free / usefull XML writing utility.

    The XML I am trying to write ends up looking like this :

    Code:
    <PACKAGE label="Sanctuary Units">
      <UNIT label="Unit 1" unitNumber="One" unitStatus="Sold" numBedrooms="4" numBathrooms="4" garageFt="690" liveableFt="3392" price="1950000"/>
      <UNIT label="Unit 2" unitNumber="Two" unitStatus="Sold" numBedrooms="4" numBathrooms="3.5" garageFt="276" liveableFt="2328" price="1095000"/>
      <UNIT label="Unit 3" unitNumber="Three" unitStatus="Sold" numBedrooms="4" numBathrooms="3.5" garageFt="276" liveableFt="2328" price="1095000"/>
      <UNIT label="Unit 4" unitNumber="Four" unitStatus="Available Soon" numBedrooms="4" numBathrooms="4" garageFt="344" liveableFt="2379" price="1095000"/>
      <UNIT label="Unit 5" unitNumber="Five" unitStatus="Available Soon" numBedrooms="4" numBathrooms="4" garageFt="344" liveableFt="2379" price="1095000"/>
      <UNIT label="Unit 6" unitNumber="Six" unitStatus="Available Soon" numBedrooms="4" numBathrooms="3.5" garageFt="276" liveableFt="2334" price="1095000"/>
      <UNIT label="Unit 7" unitNumber="Seven" unitStatus="Available Soon" numBedrooms="4" numBathrooms="3.5" garageFt="276" liveableFt="2303" price="1095000"/>
      <UNIT label="Unit 8" unitNumber="Eight" unitStatus="Available Soon" numBedrooms="4" numBathrooms="3.5" garageFt="276" liveableFt="2328" price="1095000"/>
      <UNIT label="Unit 9" unitNumber="awdawd" unitStatus="awdawd" numBedrooms="4wadawd" numBathrooms="3.5awdawd" garageFt="276awdawd" liveableFt="2334" price="1095000"/>
      <UNIT label="Unit 10" unitNumber="Ten" unitStatus="Available Soon" numBedrooms="4" numBathrooms="3.5" garageFt="276" liveableFt="2303" price="1095000"/>
      <UNIT label="Unit 11" unitNumber="Eleven" unitStatus="Available Soon" numBedrooms="4" numBathrooms="3.5" garageFt="276" liveableFt="2303" price="1095000"/>
    </PACKAGE>
    Obvisouly unit 9 was the test case and got the edited information.

    I know I need to use the URLRequest modules, but how do I get this kind of information out of flash and onto the disk formatted properly? Any suggestions?

    Thanks ahed of time!

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    here is a Flash 8 AS 2 version (including php)
    perhaps you can modify to AS 3

    http://www.jackleaman.co.uk/test/wri...hange_xml.html

  3. #3
    Member
    Join Date
    Sep 2007
    Posts
    31
    Cool, I'll see if I can hack that out to AS3, I appreciate it man.

  4. #4
    Member
    Join Date
    Sep 2007
    Posts
    31
    Ok, obviously I am still very new at this getting flash to interact with PHP thing, hell I don't actually know any PHP at all, still learning MXML and AS3. However, I tried to adapt what you did to AS3 and I can't seem to get it to work.

    here is the code I used.

    Code:
    	var request:URLRequest = new URLRequest("/cgi-bin/sendXML.php");
    		request.data = xmlData.toString();
    		request.contentType = "text/xml";
    		request.method = URLRequestMethod.POST;
    				
    		var loader:URLLoader = new URLLoader();
    		loader.addEventListener(Event.COMPLETE, finishedLoading);
    		loader.load(request);
    It looked like you just sent the XML data as plaintext to the PHP script, and since I don't know enough about PHP to change anything, I just sent xmlData.tostring() which should send the file as text like you did.

    Another quick question, how did you get your program to display the return value from the PHP script, I think I found it in your code,

    Code:
    tracer.text += this.returnMe;
    but I can't figure out how I would implement it. I am assuming I would have to set up a listener of some sort? Thanks for the help.

  5. #5
    Member
    Join Date
    Sep 2007
    Posts
    31
    Ok, in case anyone is curious I got this working.

    with AS3 you need to have

    Code:
    $mybody = $GLOBALS['HTTP_RAW_POST_DATA'];
    set up to get the data as far as I can tell, other than that the rest of the PHP was the same.

    The AS3 code worked fine, so yeah it's working now and I appreciate the help =)

    Oh, also I got the program to acknowledge that it was done saving with an

    Code:
    loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, finishedSaving);
    The only thing I am concerned about is i'm not sure this would work if I had a bunch of network calls going at once, but for this app it seemed to do the trick.

  6. #6
    Member
    Join Date
    Sep 2007
    Posts
    31
    Here is another question though.

    Everything works great, the XML gets updated with the new information, but half the time when the data finishes reloading after changes you don't see the new information till you clear the cache.

    I know the PHP script is working, every time you save new data you can check the XML file direct and it will reflect the changes. I think my browser might be caching the XML, so I don't see the new file until I clear it. Is there any way around this?

    Thanks!

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    to avoid the cached version, i appended a timestamp to the URL
    PHP Code:
    vers = new Date().getTime();
    myXML.load(path+"test.xml?"+vers); 
    can you adapt your AS3 code to include an appended variable ?

  8. #8
    Member
    Join Date
    Sep 2007
    Posts
    31
    Yeah I could manage that, however I'm unclear on how I would let flash know which of the files it needed to open when the user comes back to edit the information again? (it looks like there will be several, each with the date it was written tagged onto the filename)

    Storing the last written file in a file seems like it would have the same problem, it would be cached and I would get an older version anyway.

  9. #9
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    could you not store the last written file as data in a shared object
    on the users hard drive and access this data when the user returns ?

    http://www.flash-db.com/Tutorials/sa...ata.php?page=3

  10. #10
    Member
    Join Date
    Sep 2007
    Posts
    31
    I suppose I could use a cookie, but ideally it would all be server side. The app I am writing is a demo of a backend interface so our clients will be able to update relevant information (in this case, a real estate website can update the information on their housing units) direct from the web.

    The XML file I am writing is read by the website when a user looks at the unit section, I mean I guess that can all be transparent and my site can really load the last saved data off the clients computer, and then resave the XML as well as a new cookie, is this usually the way things like this are handled?

    Thanks for your help amigo, I definatly appreciate the patience.

  11. #11
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    are including a login for each client ?

    if so, i'd store a reference to the last written file, along side each
    clients details, in a database.

    files are accessed when the login details are verified.

    any help ??

  12. #12
    Junior Member
    Join Date
    Jun 2008
    Posts
    1
    echo5,
    would you be willing to share your code for you xml editor? i'm trying to do the same thing and not having much luck. thanks.

  13. #13
    Member
    Join Date
    Nov 2006
    Posts
    63
    kitter08, post the problem that you are having, and maybe somebody here can help you out.

  14. #14
    Member
    Join Date
    Sep 2007
    Posts
    31
    Sorry, I mustave missed your reply Kitter. I can't really post the code, I don't think my company would be so happy about that. However I'll try to awnser any questions you might have.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center