4 Replies Latest reply on Mar 9, 2009 3:12 PM by GumpsterF

    Flash to XML

    GumpsterF Level 1
      Can anyone point me in the right direction on this one.
      I need to find a VERY basic example of how (if possible), one can use an input text in Flash to change text in a external XML file. Must you first send your test to a .PHP file, and from there change the XML document?

        • 1. Re: Flash to XML
          Level 7
          >>Must you first send your test to a .PHP file, and from there change the
          >>XML document?

          Yes, you must send your text to some server-side script, such as a php
          script, which in turns saves the text as an .xml file - overwriting the old
          one. What you'll need to do some reading/research on, is sending text to the
          server from Flash (LoadVars) and saving to a text file from PHP.

          AS2:
          var myLV = new LoadVars(); //for send
          var myRV = new LoadVars(); //for response
          myLV.theXML = myXMLTextField.text;
          myLV.sendAndLoad("//mydomain.com/scripts/phpToXML.php", myRV);

          then in phpToXML.php
          <?php
          $myXML = $_REQUEST['theXML']; //change to $_POST for production
          $myFile = "../css/myXML.xml"; //relative server path
          $fh = fopen($myFile, 'w');
          fwrite($fh, $myXML );
          fclose($fh);
          echo("&ok=1"); //whatever you want to send back to your response loadVars
          ?>

          you will want to add the onLoad of the response object so you can listen for
          the echo back from php, but otherwise this is about all you need.

          --
          Dave -
          www.offroadfire.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Flash to XML
            GumpsterF Level 1
            Thanks DMennenoh. I had already done some direct response email forms using LoadVars, so I have successfully sent info to and from a PHP file.
            What I don't understand about the example you set out was, what did you mean by;
            [PHP]$myXML = $_REQUEST['theXML']; //change to $_POST for production[/PHP]
            Do I change $_REQUEST to $POST when I go live?
            Not sure what you meant by, //change to $_POST for production.
            Also, what does the 'w' represent in, [php]$fh = fopen($myFile, 'w');[/php] ?
            Is this the node in the XML file you are trying to change?
            cheers

            • 3. Re: Flash to XML
              Level 7
              Flash, in the gui sends requests using the get method, but post when in the
              browser. So I like to use $_REQUEST in php, which works with either - for
              testing. When live use $_POST as it's more secure. You can look up fopen in
              the php docs... but I think the 'w' means write mode. You are sending the
              text of the field, not a single node.

              --
              Dave -
              www.offroadfire.com
              Adobe Community Expert
              http://www.adobe.com/communities/experts/


              • 4. Re: Flash to XML
                GumpsterF Level 1
                OK, I kinda understand.
                I went to PHP.net to look up all the operators mentioned here, but what I still am having a hard time with is how to replace text in a node in the XML file with the fwrite command. I see that is writing $myXML into the XML file, but how do I direct the to replace the text string "Canada wins gold" in the XML file? Do I need to change the names of my child or parent nodes in the XML file to match the PHP language, such as <Destination>$myXML</Destination>?
                Here is my current XML code.