6 Replies Latest reply on Dec 29, 2006 1:01 PM by phi2265

    import text from file

    phi2265 Level 1
      so i need to load stories into my application. now that i have the asp script working that builds an xml file of the directories.. i can get the location of all the images and text/html files that i need to load. what i cant seem to find is how to load the text from the text or html file.

      anyone have any tips or suggestions?
        • 1. Re: import text from file
          ntsiii Level 3
          Use the Filesystem api to load the file into asp, then wrap it in an xml root tag an pass it to Flex using HTTPService.

          • 2. Re: import text from file
            phi2265 Level 1
            I just found the URLLoader function in flex... but i'm not sure that it will work.

            the documentation says this about security...
            For Flash Player 8 and later:

            Data loading is not allowed if the calling SWF file is in the local-with-file-system sandbox and the target resource is from a network sandbox.
            Data loading is also not allowed if the calling SWF file is from a network sandbox and the target resource is local.

            does that mean i can't use this if i were to load the .txt file which is referenced in an xml file?
            • 3. Re: import text from file
              ntsiii Level 3
              Have you changed the Player sandbox settings?

              I prefer HTTPService, I know that will work since I am doing it in production.

              For either approach, a crossdomain.xml file will be required on the server providing the files if its domain is different than the domain serving the application swf.
              • 4. Re: import text from file
                phi2265 Level 1
                No I havent changed the sandbox settings... how would i go about that?
                I also dont know how to do what you suggested earlier.. haha.

                the .txt file would be in the same directory, or in a directory in that directory. heres the documentation on URLLoader
                I'm a little confused by what it said about the sandbox.
                • 5. import text from file
                  phi2265 Level 1
                  i believe URLLoader will work, if i can figure out how to use it correctly.

                  im trying to import the package that they give in the example, which i named textLoader

                  i do 'import textLoader.*' and i get an error of textloader could not be found, but after typing import textLoader is one of the suggested options! as well as the name of the class that i want to use which is called URLLoaderExample.

                  when i try to use textLoader.URLLoaderExample, it tells me URLLoaderExample is an undefined property!

                  what am i doing wrong here?
                  • 6. Re: import text from file
                    phi2265 Level 1
                    finally.. i got it. sorry for all the posts...

                    heres what i did if anyone else is interested

                    public var textImport:String;
                    public var loader:URLLoader = new URLLoader();
                    public var request:URLRequest = new URLRequest("test.txt");
                    private function completeHandler(event:Event):void{
                    loader = URLLoader(event.target);
                    textImport = new String(loader.data);
                    impTest.text = textImport.toString();

                    and in the function that runs on the Application creationComplete is:
                    loader.addEventListener(Event.COMPLETE, completeHandler);