27 Replies Latest reply on Apr 11, 2007 7:22 PM by kglad

    Displaying results in a text column

    paulpsd7
      I'm developing a health questionnaire, where you answer a bunch of health-related questions, and are shown a bunch of health recommendations at the end.

      After the user answers all 15 questions, I use a bunch of logic (if...then...else) to go through the answers and determine which result to show. Each question provides a specific recommendation. I then import the various recommendations as XML files. That all works fine.

      Here's my problem. Each time I import an XML file, I'm trying to concatenate that content into a variable called "recommendations" and display it on the screen. Eventually, the recommendations should consist of a bunch of smaller recommendations pulled from each XML file.

      Here's how I set up that field:

      var ss:TextField.StyleSheet = new TextField.StyleSheet();
      ss.load("kaiser_hra.css");
      recommendations.styleSheet = ss;
      recs = new XML();
      recs.ignoreWhite = true;
      // Formatting text field and importing content
      recommendations.multiline = true;
      recommendations.wordWrap = true;
      recommendations.html = true;
      recommendations._quality = "HIGH";

      Then here's how I import each XML file and attempt to concatenate it:

      add_content = function (chapter) {
      chapterLoad = "recommendations/" + chapter + ".htm";
      trace ("adding " + chapter);
      recs.load(chapterLoad);
      recs.onLoad = function() {
      all_recs = all_recs + recs;
      trace ("recs: " + recs);
      trace ("all_recs: " + all_recs);
      }
      }

      For the function above, I'm passing the variable "chapter" to determine which piece should load. I use the variable "chapterLoad" to set the file path and name of the actual file to load. Then I load the file into an XML object called "recs" which I defined earlier. All that works fine.

      The problem comes when I try and concatenate the value of "recs" into a variable called "all_recs" which contains all the previous and subsequent values of "recs." In the trace command above, "all_recs" returns "NaN". Therefore, I think the problem revolves around this line:

      all_recs = all_recs + recs;

      Isn's this the correct way to concatenate a string variable? Let me know.
        • 1. Re: Displaying results in a text column
          kglad Adobe Community Professional & MVP
          where have you initialized all_recs? you need:

          all_recs=""; // outside your recs.onLoad() handler.
          • 2. Re: Displaying results in a text column
            paulpsd7 Level 1
            Thanks for the tip. On your recommendation, I added all_recs=""; outside of my event handler.

            That changed is so that all_recs no longer returns NaN. Now it just returns nothing.

            The problem seems to be this line:

            [CODE]all_recs.text = all_recs + recs;[/CODE]

            in my add_content function.

            One thing you should know about that function. It gets called 15 times in immediate succession. Therefore, recs loads 15 different XML files into itself, and then tries to pass that value into all_recs.
            • 3. Re: Displaying results in a text column
              kglad Adobe Community Professional & MVP
              where'd that code come from? that's not in add_content shown in your first message.

              is all_recs a string variable or a textfield? and don't be stingy using variables. you're going to cause a lot of programming headaches for yourself if you try and use objects and variables with the same name.
              • 4. Re: Displaying results in a text column
                paulpsd7 Level 1
                all_recs is a string variable. It's supposed to collect all the various XML pieces. Then there's a command to pass the value into "recommendations," which is a text field:

                recommendations.htmlText = all_recs;

                In answer to your question, this line is in my add_content function now:

                all_recs.text = all_recs + recs;

                By defining all_recs as text, it returns as blank rather than as NaN.
                • 5. Re: Displaying results in a text column
                  kglad Adobe Community Professional & MVP
                  that line is incorrect. leave it as it was before and add the initialization.
                  • 6. Re: Displaying results in a text column
                    paulpsd7 Level 1
                    Okay, we're getting closer. By implementing your suggestions, I can see through trace commands that all_recs now contains all the content I want it to.

                    However, nothing is yet appearing in my "recommendations" field on the stage. Here's the command:

                    recommendations.htmlText = all_recs;

                    Simple enough, but "recommendations" remains blank.
                    • 7. Re: Displaying results in a text column
                      kglad Adobe Community Professional & MVP
                      you don't want to assign htmlText to recommendations until all_recs is defined and no longer undergoing concatenation.
                      • 8. Re: Displaying results in a text column
                        paulpsd7 Level 1
                        quote:

                        Originally posted by: kglad
                        you don't want to assign htmlText to recommendations until all_recs is defined and no longer undergoing concatenation.


                        Yeah, that's what I'm doing. The command recommendations.htmlText = all_recs; actually appears on the next frame, after all_recs has been fully defined. The recommendations field is on the stage during both of these frames.

                        • 9. Re: Displaying results in a text column
                          paulpsd7 Level 1
                          However, before all_recs is defined, I do apply this to recommendations:

                          recommendations.multiline = true;
                          recommendations.wordWrap = true;
                          recommendations.html = true;
                          recommendations._quality = "HIGH";

                          Should I apply that later as well?
                          • 10. Re: Displaying results in a text column
                            kglad Adobe Community Professional & MVP
                            as long as your textfield (recommendations) exists on each frame that contains code referencing recommendations you should have no problem.

                            do you need to embed your font? test with

                            recommendations.htmlText="this is a test"; // does the text appear?
                            • 11. Re: Displaying results in a text column
                              paulpsd7 Level 1
                              Good question. However, I've already embedded the fonts. I did your "this is a test" test, and that text appeared fine.
                              • 12. Re: Displaying results in a text column
                                kglad Adobe Community Professional & MVP
                                on frame 2 just after recommendations has its htmlText property defined, use:

                                trace(recommendations+" "+all_recs+" "+recommendations.htmlText);

                                copy and paste the output panel results.
                                • 13. Re: Displaying results in a text column
                                  paulpsd7 Level 1
                                  Well, I'll spare you the actual output, which is enormous. Instead, I'll just describe it, which should be helpful.

                                  trace (recommendations); returned this:
                                  _level0.instance160.recommendations
                                  (This just seems to be the path to the field itself.)

                                  trace (all_recs); returned exactly what it is supposed to: A collection of content from several XML files, all enclosed in their appropriate tags.

                                  trace (recommendations.htmlText); also returned exactly what it is supposed to: exactly the same as what's in all_recs.

                                  The trouble is, this content will not appear in the field called "recommendations" on the stage. However, if I replace the HTML content of all_recs with "this is a test," that appears fine.
                                  • 14. Re: Displaying results in a text column
                                    kglad Adobe Community Professional & MVP
                                    is there html code in all_recs after it's finished being concatenated? is there any font color assignment that could be causing the font to be the same color as the background
                                    • 15. Re: Displaying results in a text column
                                      paulpsd7 Level 1
                                      all_recs looks like this:
                                      <body_text>
                                      Choosing to eat whole grain foods and fruits and vegetables frequently is healthy for your heart. For more information click here:
                                      <li>Nutrition</li><li>High Cholesterol</li><li>DASH Diet for High Blood Pressure</li></body_text>

                                      all_recs contains about 15 pieces of content that look like that.

                                      The font color in the field is not the same as the background. I can see that from my "this is a test" test.

                                      However, there's been a hopeful development. After the calculations are complete, the correct content appears in "recommendations" for a brief instant before disappearing. I can tell it starts with exactly what appears in all_recs (minus the tags).

                                      Here's the last frame in its entirety:

                                      var ss:TextField.StyleSheet = new TextField.StyleSheet();
                                      ss.load("kaiser_hra.css");
                                      recommendations.styleSheet = ss;
                                      // Formatting text field and importing content
                                      recommendations.multiline = true;
                                      recommendations.wordWrap = true;
                                      recommendations.html = true;
                                      recommendations._quality = "HIGH";

                                      recommendations.htmlText = all_recs;
                                      trace ("\n \n");
                                      trace ("RECOMMENDATIONS: \n" + recommendations);
                                      trace ("ALL_RECS: \n" + all_recs);
                                      trace ("RECOMMENDATIONS (HTML): \n" + recommendations.htmlText);

                                      stop ();

                                      From what I can tell, somewhere after recommendations.htmlText = all_recs; and before stop ();, something is making my text disappear!
                                      • 16. Re: Displaying results in a text column
                                        kglad Adobe Community Professional & MVP
                                        does recommendations have an associated variable? is there any other code that assigns text or htmlText to recommendations?

                                        if the answer is no to both of those use the following to get an estimate of how long it takes for the text property to be changed for your textfield:

                                        • 17. Re: Displaying results in a text column
                                          paulpsd7 Level 1
                                          To clarify, recommendations is not being sent values from anywhere else. Also, recommendations is the instance name of a field, but is not the variable name. I did it that way because on a past project, I successfully loaded XML files into a field the same way.

                                          I attached that code you recommended. This is what was returned (infinite times):

                                          If you do not know your blood pressure, we recomm

                                          These are the first 50 characters of what should appear in the recommendations. This appears without the tags.

                                          (By the way, thanks heaps for your attention on this!)
                                          • 18. Re: Displaying results in a text column
                                            kglad Adobe Community Professional & MVP
                                            ok, then the text (and htmlText) properties are not the issue. your textfield's properties must be changing and that css (that's trying to load) is looking suspicious. disable that to check it that's the issue.
                                            • 19. Re: Displaying results in a text column
                                              paulpsd7 Level 1
                                              Good thinking! The stylesheet is indeed the culprit. I disabled it, and my results came through fine.

                                              Here's the stylesheet code:

                                              var ss:TextField.StyleSheet = new TextField.StyleSheet();
                                              ss.load("kaiser_hra.css");
                                              recommendations.styleSheet = ss;

                                              I grabbed that code from an older project where it was working fine. Given Flash's gremlins, however, I don't know why I assumed it would ever work again.

                                              I would be tempted to ditch the stylesheet and be done with this. However, my XML content contains links, and without some kind of styling, the links don't look like anything. So for that reason alone, I need to get the stylesheet working.

                                              Any ideas?
                                              • 20. Re: Displaying results in a text column
                                                kglad Adobe Community Professional & MVP
                                                remove your duplicate code that was outside the ss.onLoad method and use:



                                                • 21. Re: Displaying results in a text column
                                                  paulpsd7 Level 1
                                                  Alas, that didn't work. Same result as before.

                                                  I'm thinking the only thing to do is lose the stylesheet.
                                                  • 22. Re: Displaying results in a text column
                                                    kglad Adobe Community Professional & MVP
                                                    leave that code alone or else you'll encounter a problem when accessing your swf from a web server: your style sheet's loading is likely to be delayed enough that you'll be assigning an empty style sheet to your textfield and losing your formatting.

                                                    post the style sheet code. it's causing you to lose your embedded font.
                                                    • 23. Re: Displaying results in a text column
                                                      paulpsd7 Level 1
                                                      Stylesheet is attached.
                                                      • 24. Re: Displaying results in a text column
                                                        paulpsd7 Level 1
                                                        Maybe I should remove the font-family properties?

                                                        That worked fine the last time I attempted something like this. In fact, this is the identical stylesheet I used before, only with different colors.
                                                        • 25. Re: Displaying results in a text column
                                                          kglad Adobe Community Professional & MVP
                                                          yes, but you didn't need to embed your font because you weren't masking (most likely, but there are other reasons you would need to embed your font) the last time you attempted something like this.

                                                          just change all those font-families to verdanaBold for the bold fonts and verdanaReg for the non-bold fonts. there's no need for the hierarchy because you're going to embed the required fonts and so you can be sure everyone will be viewing verdana font in recommendations and falling back to arial etc is irrelevent.

                                                          click on the upper right of your library panel, click new font, pick verdana from the dropdown and give it a name like _verdanaReg.

                                                          at the top of your library you should see the font _verdanaReg. right click it, click linkage, tick export for actionscript and in the linkage id box enter: verdanaReg.

                                                          then do it all again from verdana bold: click on the upper right of your library panel, click new font, pick verdana from the dropdown, tick bold and give it a name like _verdanaBold.

                                                          at the top of your library you should see _verdanaBold. right click it, click linkage, tick export for actionscript and in the linkage id box enter: verdanaBold.

                                                          i don't think you'll need to embed the various font sizes. say a prayer and retest.
                                                          • 26. Re: Displaying results in a text column
                                                            paulpsd7 Level 1
                                                            Yes!!!!!!!

                                                            That worked!!!!!

                                                            kglad, you have well and truly saved my bacon. Thank you so much.

                                                            Now, if you are still feeling so generous with your time, there's another problem I'm having which probably has a very quick answer:
                                                            http://tinyurl.com/32dthk
                                                            • 27. Re: Displaying results in a text column
                                                              kglad Adobe Community Professional & MVP
                                                              that was an interesting path we took to the solution. and you're welcome.

                                                              (i'll check your link.)