3 Replies Latest reply on Jun 25, 2008 2:41 AM by Whitetimer

    Guidance for a Noob :)

    Whitetimer Level 1
      Hi All

      Im working on a small utility for a Racing Sim and i'd like to ask for some guidance as i'm still new to AS. This Utility will be in Air, but its the AS that i wanted some advice with. Anyway

      I want to open a text file and generate random numbers to add to the text file and then save and close the file.

      steps

      1) Generate random number between 1 and 3.
      2) then if 1, generate random number between say 10 and 45, or 2 then generate 2 numbers between 10 and 45 with the second number being greater than the first, or if 3 then generate 3 numbers between 10 and 45 where the first is less than the second and third, the second is greater than the first and less than the third and the third is greater than the first and second.

      The 10 and 45 are examples for the moment and there will be further refinements once i can get a basic.

      Any suggestions ?

      Many Thanks

      Whitetimer
        • 1. Re: Guidance for a Noob :)
          John Hall Level 4
          Wow. There must be a zillion approaches you can take on this. One that I sometimes use is to use the local store to save a text or xml doc. Here's a good tutorial on saving xml and updating it.

          http://www.adobe.com/devnet/air/flex/quickstart/xml_prefs.html

          out of curiosity, why do you have to save the file? Is it something that is accessed later or something. Just curious.
          • 2. Re: Guidance for a Noob :)
            John Hall Level 4
            In addition, if you already generate an array or something, you can save it to a file and it should be hard to read (if that's concern) with something along these lines:

            var newFile:File = new File();
            newFile = File.applicationStorageDirectory.resolvePath("numbers.xml");
            var str:ArrayCollection = myArrayCollectionOfNumbers;
            var stream:FileStream = new FileStream();
            stream.open(newFile, FileMode.WRITE);
            stream.writeObject(str);
            stream.close();

            untested but it looks about right.
            • 3. Re: Guidance for a Noob :)
              Whitetimer Level 1
              quote:

              Originally posted by: John Hall
              Wow. There must be a zillion approaches you can take on this. One that I sometimes use is to use the local store to save a text or xml doc. Here's a good tutorial on saving xml and updating it.

              http://www.adobe.com/devnet/air/flex/quickstart/xml_prefs.html

              out of curiosity, why do you have to save the file? Is it something that is accessed later or something. Just curious.



              Hi John

              Thanks for the advice, will take a look. The file is read by the application/game, hence needing to be saved once the changes are made, but also to save the original file as a backup.