Answered
Displaying results in a text column
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.
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.