9 Replies Latest reply on Aug 7, 2006 7:32 AM by kglad

    Loading jpgs and txt files into flash

    datawizard
      Hi all , I am having a bit of a problem, What I am attempting to do is create a simple photo album where the user can add more pics and text captions by editing an external file for adjusting the array lenghts for the jpg and the text files, each text caption is its own txt file the problem I am running into is I cannot get flash to see the external variable for the number of JPGs, here is what I have for actionscript for first part
      //load external value from text file
      varReceiver = new LoadVars();
      varReceiver.load("external.txt");

      var myNum = varReceiver;
      //sets jpg info up

      var NumberOfImages = myNum;
      var NumberOfText = 9;
      var LocationToImages = "pics/";
      var FileType = ".jpg";
      -->rest of script which works fine, I cut it off so that you wouldnt have to read all of the code

      if I change the "myNum" in this statment "var NumberOfImages = myNum;" to a number , the photos display
      what I have set for the external data looks like this &myNum=29&

      my 2nd problem is loading external text, I can load a single txt file but I cannot get my array working for loading multiple txt files. again I would like the number of text files to be from an external txt file for ease of updating- or just though of this, Is there anyway to set flash so that it counts the number of files in the jpg and text folders for settings its array? would appricate any help in this matter, thanks d_wiz
        • 1. Re: Loading jpgs and txt files into flash
          kglad Adobe Community Professional & MVP
          1. what is the line

          var myNum=varReceiver supposed to do?

          2. you need an onLoad handler to ensure the data from external.txt is loaded before you try and use it.

          3. all variables in external.txt are string variables. so, despite myNum (in external.txt) appearing to be a number, it is a string when loaded into flash. use the Number function to convert it to a number.
          • 2. Re: Loading jpgs and txt files into flash
            datawizard Level 1
            hi kglad,
            I have modified the script to where it looks like this now
            first frame AS
            stop();
            myData = new LoadVars();
            myData.load("external.txt");
            myData.onLoad = function (success) {
            if (success) {
            NOI = Number(NOI);
            trace(this.NOI);
            gotoAndStop(2);
            } else {
            trace("error loading");
            }
            }
            then in 2nd frame AS i have this
            stop();
            var LocationToImages = "pics/";
            var FileType = ".jpg";
            var x = 0;this
            var jpg = new Array();
            var i = 0;

            while (i <= NOI)
            {
            jpg = LocationToImages + i + FileType;
            i++;
            } // end while
            and in my external text file i have this
            NOI=10
            what I get when I test movie is message saying script is causing flash player to run slowly do you wish to abort
            I tested the first frame AS without going to the 2nd frame and I can trace out the value so I know it is getting loaded
            but its still not transfering over to the 2nd frame for array number, any idea as to what I am doing wrong here? D_wiz
            • 3. Re: Loading jpgs and txt files into flash
              kglad Adobe Community Professional & MVP
              your trace() correctly uses this.NOI, but that's the only place you use the correct path. to remedy, in your onLoad handler use:

              NOI=Number(this.NOI);

              // or

              NOI=Number(myData.NOI);
              • 4. Re: Loading jpgs and txt files into flash
                datawizard Level 1
                Hi kglad, I tried using the NOI=Number(this.NOI) on the onLoad handler but that didnt work as I got the script is causing flash to runs slowly message, I also tried adding the "this" to the array line on frame 2 "while(i <= this.NOI)" to maybe see if that would work but I still get script runs slowly error message. I am at a lost as to why the external variable is not transfering to the array. do you have any other suggestions I could try?
                Thanks d_wiz
                • 5. Re: Loading jpgs and txt files into flash
                  kglad Adobe Community Professional & MVP
                  show your updated code using the attach code option so your [ i ] does not trigger italic font.
                  • 6. Re: Loading jpgs and txt files into flash
                    datawizard Level 1
                    Hi kglad, I got the jpg portion working so that it loads jpgs from number from external file, I wound up doing this.(code shown below). The jpgs are working properly now. The problem I am running into is trying to duplicate this script so that I can display external text files as well. Lets say theres 10 jpgs to be displayed, there will be 10 txt files as well for diplaying captions and all user would have to do is edit the external txt files for number of jpgs and number of txt files that are added. I have tried changing up the script to show txt for file type and changed the loadmovie to loadVariablesNum but its not working like I though it should. If you have any suggestions as how I can modify this script to display txt files in a dynamic txt box I would be forever gratful, I do thank you for your time and suggestions on this D_wiz

                    • 7. Re: Loading jpgs and txt files into flash
                      kglad Adobe Community Professional & MVP
                      what's the name of the text file that corresponds to pics/i.jpg and what variable in that text file contains i.jpg's description? and what's the instance name of your textfield that will display that description?
                      • 8. Loading jpgs and txt files into flash
                        datawizard Level 1
                        hi kglad, I have been doing dome rewriting here and I have the txt showing up somewhat, I have a folder called txtFiles with 4 txt files in there numbered from 0.txt to 3.txt , every one of the txt files has this inside of it
                        display=And num of picture
                        the problem I am having with this now is when I test it, the dynamic txt box on stage which has a var name of display shows content of txt file 3.txt wheresas it should start with 0.txt and i also get error message saying cannot find 4.txt and 5.txt. my code looks like this, and reason I have var=4 for number of files for array is I am using this to get this part working then I will incorperate the function of loading an external var(using what I have for the JPG that was fixed). I am getting closer to ironing this bug out, lol D_wiz
                        • 9. Re: Loading jpgs and txt files into flash
                          kglad Adobe Community Professional & MVP
                          display will always be the data stored in the last text file that you load. to remedy, don't load all the text files in that while statement. only load the textfile that corresponds to the current image that's loaded.