10 Replies Latest reply on Oct 29, 2007 10:07 AM by miragevideo

    Load,Edit and save XML file via Flex

      Hi, I posted this question in the AS3 forum but I am not sure if that was the correct place;
      http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=587&threadid =1267500&enterthread=y

      Hi I am new to Flex and AS3 but I have some experience with XML, XSLT, XPATH, VB etc..

      I am having trouble just loading the XML. How do I load an external XML file so I can edit it?

      This is what I have so far:

      var myxml = 'xml/request.xml';
      XML.ignoreWhitespace = true;
      var xml:XML = new(myxml);

      I recieve an error:

      "TypeError: Error #1007: Instantiation attempted on a non-constructor."

      Thanks in advance
        • 1. Re: Load,Edit and save XML file via Flex
          peterent Level 2
          Flex application run from within a browser have security restrictions. You cannot read or write local files; you can only send and receive data from the server. So your files have to live on a server. You request them at runtime using a data service, such as HTTPService.

          If you have static XML files on the server, then code the HTTPService's url parameter to point to the XML file itself. Most likely you will want to load a file based on the user or something specific. In that case you will need some server-side code, such as PHP, Flex Data Services, IIS, Java servlets, etc.
          • 2. Re: Load,Edit and save XML file via Flex
            XMLmaster Level 1
            Thank you for the information. As I am currently evaluating Flex 2, I wll look into FLEX Data Services.

            • 3. Re: Load,Edit and save XML file via Flex
              How can an official adobe representative be so wrong?
              You can read an xml file locally, and possibly write.
              • 4. Re: Load,Edit and save XML file via Flex
                peterent Level 2
                And how do you do that?
                • 5. Re: Load,Edit and save XML file via Flex
                  Anti-Girl Level 1
                  You said its not possible to read and then give an example off how its possible to read from server using HTTPSERVICE,
                  surely you can use HTTPService to read it locally aswell.

                  as for writing if you use flex3 etc im sure you can use FileStream to access and modify an .xml file
                  • 6. Re: Load,Edit and save XML file via Flex
                    peterent Level 2
                    You cannot use HTTPService to read and write local files. HTTPService uses the HTTP protocol to connect to a server that understands the protocol; the local file system does not. Further, the local file system is in another security sandbox. A sandbox is defined by the domain (eg, adobe.com). The domain from which the SWF is served is its home domain. Operations on data with that domain, such as HTTPService, are automatically allowed. If you try to request a file from outside that domain you have to get permission from the other domain to do so, usually in the form of a crossdomain.xml file.

                    The local file system cannot provide this. Plus, it would be a huge risk to allow the Flash Player to have access to the local file system. Imagine going to some website where a malicious SWF was placed, perhaps disguised as a banner add, where it then filled your drive with nonsense files, or read your files and transmitted them elsewhere.

                    The File classes in Flex 3 are part of the AIR package. The AIR player runs locally, thus it is in the local domain. AIR apps behave in the same way any locally installed program behaves and can read and write files. AIR apps are installed by the user and launched by the user (a user hitting a web page and getting SWFs as banner ads is not explicitly granting those SWFs permission). AIR apps can be distributed over the 'net, but not launched from the browser.

                    • 7. Load,Edit and save XML file via Flex
                      Anti-Girl Level 1
                      Hey Peter, i am aware of this but youre saying i cant access local files via HTTPSERVICE, when i can, the user has not stated that he is building an app for online use it could be just for local, and if so crossdomain will not apply and a simple point to the xml file using GET will do the job.

                      P.s: apologies for sounding very arrogant and ignorant, i had misread a bit of your reply earlier
                      • 8. Re: Load,Edit and save XML file via Flex
                        peterent Level 2
                        I believe your use case is uncommon. Going forward, AIR is the way to do this as we may beef up Flash Player security a bit more.
                        • 9. Re: Load,Edit and save XML file via Flex
                          levancho Level 3
                          Anti-Girl in any case : 1 or 2 you are wrong,
                          Case 1) as peter stated cant read client files , capish not possible, only from Server.
                          Case 2) if user is running app locally, then users local machine becomes also a users Server as well so that is why its possible in that case.
                          bottom line is still cant read client files,only from Server.
                          • 10. Re: Load,Edit and save XML file via Flex
                            miragevideo Level 1

                            I wanted to follow up with a similar request. I am trying to get a screen capture of my application and then allow the user to save this locally. I understand this will require a round-trip to the server. I am looking for some sample code to run on the server in Java. I have done the work on the client of encoding the image into a png format and then using URLLoader to send this to the server. What I am missing is the round-trip part. When the server gets the data, how does it return it to the client and how does the client show a "save" dialog box? Will this need to be done through the browser? WIll I need to open an additional window?

                            Any pointers would be helpful.


                            Jeff S