Skip to main content
Inspiring
April 9, 2007
Answered

Displaying results in a text column

  • April 9, 2007
  • 15 replies
  • 1352 views
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.
This topic has been closed for replies.
Correct answer kglad
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.

15 replies

kglad
Community Expert
Community Expert
April 9, 2007
you don't want to assign htmlText to recommendations until all_recs is defined and no longer undergoing concatenation.
paulpsd7Author
Inspiring
April 9, 2007
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.

paulpsd7Author
Inspiring
April 9, 2007
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.
kglad
Community Expert
Community Expert
April 9, 2007
that line is incorrect. leave it as it was before and add the initialization.
kglad
Community Expert
Community Expert
April 9, 2007
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.
paulpsd7Author
Inspiring
April 9, 2007
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.
kglad
Community Expert
Community Expert
April 9, 2007
where have you initialized all_recs? you need:

all_recs=""; // outside your recs.onLoad() handler.
paulpsd7Author
Inspiring
April 9, 2007
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:

all_recs.text = all_recs + recs;


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.