11 Replies Latest reply on Sep 3, 2006 11:04 AM by 2m

    More problems reading file in to Dynamic text field

    dad_1953
      This is so confusing. I can get the anchor tag to work in code; however it will not work when reading in from a file.

      I have a Dynamic Text field set to take HTML text. I want to read in a HTML text file and let the user click on a key work which will take tem to a different part of the movie. Thanks to Craig Grummitt I was able to get the code to work. The problem I am now having is when I try to put the code in a file it will not work.
      The following line of code works when it is hard coded in the movie:

      Byline1.htmlText = "<a href=\"asfunction:"+this+".gotoAndStop,LatestNews\"> Read More</a>"

      When I remove the above code and put in the following code in the mive:

      myData = new LoadVars();
      myData.onLoad = function() {
      Byline1.htmlText = this.myVariable;
      };
      myData.load("./Text/Byline1.txt");



      And in the Byline1.text file I have the following:

      myVariable=<a href=\"asfunction:"+this+".gotoAndStop,LatestNews\"> Read More</a>


      It doesn’t work.
      I don’t even see the Read More link text.
      Also, any text I put between
      myVariable= and <a
      will be seen.
      However any text after
      Read More</a>
      Will not be seen.


      What am I doing wrong?

      Thank you,
      Steve
        • 1. Re: More problems reading file in to Dynamic text field
          2m Level 2
          could you check (using debug menu in the output window or usind the debugger) if the variable is loaded correctly?

          Or could it be an issue ot displying fonts?

          A lof of guesswork here, but I could probaly help a bit more if you post the sources.
          • 2. Re: More problems reading file in to Dynamic text field
            dad_1953 Level 1
            This is not a font display problem. I have no problem reading in the file and displaying simple HTML formatted text in the file. I am sure the issue is caused by incorrectly formatting the anchor statement and most likely it has to do with proper formatting of the asfunction part of the anchor statement. The biggest problem I seam to have is that the formatting of HTML text that is hard coded in to a movie is different from the formatting of HTML text that is read in from a file.

            You asked for my source code. I created a very simple test movie when I was having problems and all the code that is in the test move is in the original post.

            Is there any good whitepapers or other sources that give detail examples of what the HTML string would look if it was hard coded in to your movie and what it would look like if it was placed in a file and the file was read in to the movie? I have found that the formatting is sometimes just a little different and other time there is a lot of differences.

            Thank you,
            Steve
            • 3. Re: More problems reading file in to Dynamic text field
              kglad Adobe Community Professional & MVP
              are you loading your text file? what kind of path is that? are there supposed to be two periods at the start of that path?
              • 4. More problems reading file in to Dynamic text field
                dad_1953 Level 1
                The path is correct. “./text/ByLine1.txt” is correct format. I always keep my text in there own folder. I do the same for my images. One dot means start at the current folder. Two dots means to start just before the current folder.
                • 5. Re: More problems reading file in to Dynamic text field
                  kglad Adobe Community Professional & MVP
                  then try url encoding the + in your text file. use:

                  %2b instead of +
                  • 6. Re: More problems reading file in to Dynamic text field
                    dad_1953 Level 1
                    The %2d didn’t fix the problem. I also tried using %22 to replace the double quotes. I then tried using the %2d and %22 at the same time. This still didn’t fix the problem.

                    Steve
                    • 7. Re: More problems reading file in to Dynamic text field
                      2m Level 2
                      Hi,

                      I reread your post and think that I'm coming to understand the problem.
                      The content of you textfile is : " &myVariable=<a href=\"asfunction:"+this+".gotoAndStop,LatestNews\"> Read More</a>&"?
                      If so, them I'm qite sure that it won't work and will never.

                      I'm not sure how to explain it, but I'll try:

                      The content ot a loaded textfile (or any other loaded Var) alwayi is of the datatype String. Thanks to the automatic typecasting of Flash Strings that are used in a clear Number way are interpreted as number, but are loaded a String.

                      The way you want to your your string is only partly as string especialy you want to have the term "this" replace with the datatype MovieClip. So what you want Flash to do is use your string as an Expression that has to be evaluated.

                      If this was Javascript you would use eval to do so, but even if AS knows "eval" it offers only very limited functinality and is deprecated any how.
                      (Ther reason for tihs limitation is, as far as I understand, that the Flash player does not contain a compiler, mostly because of download-size, probably because of strategical reasond of the company).

                      It's no big harm though, you would just have to put a function "in front" of your setting the textfield's content like:

                      Your text flield:

                      &myVariable=Read More;LatestNews&
                      your Code:

                      myData = new LoadVars();
                      myData.onLoad = function() {
                      var tmp_array = this.myVariable.split(";");
                      Byline1.htmlText = "<a href=\"asfunction:"+this+".gotoAndStop,"+tmpArray[1]+"\">"+tmpArray[0]+"</a>";
                      };
                      myData.load("./Text/Byline1.txt");

                      If you would need the content of your textfile exactly the way it is, you would need to do more elaborate parsing before you could set the htmText od Byline1, but it is doable none the less.

                      Markus

                      PS.: the code isn't tested, it might contain typos as the rest of my post(s) - sorry.
                      • 8. Re: More problems reading file in to Dynamic text field
                        dad_1953 Level 1
                        Thank you Markus for the information. I tried what you said and it almost works but not quite.
                        The LoadVare code that I used (following your example) is:

                        myData = new LoadVars();
                        myData.onLoad = function() {
                        var tmp_array = this.myVariable.split(";");
                        text1_txt.htmlText = tmp_array[0]+"<a href=\"asfunction:"+this+".gotoAndStop,LatestNews\"> Read More</a>";
                        };
                        myData.load("./Text/Byline2.txt");


                        All the text is being displayed in the text filed and when I put my mouse over the Read More link it thinks there is a link there. When I click on the link it doesn’t work.

                        I then tried the following code just to verify that the link still worked.

                        this.createTextField("text1_txt", 1, 10, 10, 200, 100);
                        text1_txt.multiline = true
                        text1_txt.html = true;
                        text1_txt.htmlText = "<a href=\"asfunction:"+this+".gotoAndStop,LatestNews\"> Read More</a>";


                        This proved that the link works.

                        I then tried the following code:

                        myData = new LoadVars();
                        myData.onLoad = function() {
                        text1_txt.htmlText = "<a href=\"asfunction:"+this+".gotoAndStop,LatestNews\"> Read More</a>";
                        };
                        myData.load("./Text/Byline2.txt");


                        The Read More acts like a link; however it doesn’t work.

                        Why would <a href=\"asfunction:"+this+".gotoAndStop,LatestNews\"> Read More</a> work out side the onLoad event and not work inside the onLoad event?

                        If you or someone else has a solution to this issue then I believe everything the way I need it to work.

                        Thank you,
                        Steve
                        • 9. Re: More problems reading file in to Dynamic text field
                          2m Level 2
                          sorry, it was my blunder.

                          "this" insided the onLoad event is the object that generates the event, in out case the LadVars object, so we would have to change our code as follows:

                          myData = new LoadVars();
                          myData.clip = this;
                          myData.onLoad = function() {
                          var tmp_array = this.myVariable.split(";");
                          text1_txt.htmlText = tmp_array[0]+"<a href=\"asfunction:"+ clip+".gotoAndStop,LatestNews\"> Read More</a>";
                          };
                          myData.load("./Text/Byline2.txt");

                          that should work.
                          • 10. Re: More problems reading file in to Dynamic text field
                            dad_1953 Level 1
                            Hello Markus,
                            Your changed worked after I corrected one typo. I am posting the fully working code for anyone that may be having similar problems. I am sure that there are other people that will benefit from this topic.
                            Setup
                            Create a test move and save it to a test folder
                            Create 2 layers within the movie (Labels, Actions)
                            On frame 10 of the Lables layer insert a blank key frame and name the frame label LatestNews
                            In frame 1 of the action layer put in the following code
                            stop();
                            this.createTextField("text1_txt", 1, 10, 10, 200, 100);
                            text1_txt.multiline = true
                            text1_txt.html = true;

                            myData = new LoadVars();
                            myData.clip = this;
                            myData.onLoad = function() {
                            var tmp_array = this.myVariable.split(";");
                            text1_txt.htmlText = tmp_array[0]+"<a href=\"asfunction:"+myData.clip+".gotoAndStop,LatestNews\"> Read More</a>";
                            };
                            myData.load("./Text/Byline2.txt");

                            On frame 10 of the Actions layer insert a blank key frame. Enter in the following code:
                            trace("This codes works");
                            Save the movie to your test folder.
                            In the test folder create a folder called Text and in the text folder create a text file called Byline2. Make sure that the full name of the text file is Byline2.txt
                            In the Byline2.txt add the following text:
                            myVariable=This is a test
                            Save the file and test your movie

                            I would like to once again like to thank Markus and Craig Grummitt.

                            Thank you,
                            Steve
                            • 11. Re: More problems reading file in to Dynamic text field
                              2m Level 2
                              Your very much welcome as far as I'm concerned.

                              Markus Mathieu