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 12, 2007
that was an interesting path we took to the solution. and you're welcome.

(i'll check your link.)
paulpsd7Author
Inspiring
April 12, 2007
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
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
April 12, 2007
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.
paulpsd7Author
Inspiring
April 12, 2007
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.
kglad
Community Expert
Community Expert
April 12, 2007
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.
paulpsd7Author
Inspiring
April 12, 2007
Stylesheet is attached.
kglad
Community Expert
Community Expert
April 10, 2007
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.
paulpsd7Author
Inspiring
April 11, 2007
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?
kglad
Community Expert
Community Expert
April 11, 2007
remove your duplicate code that was outside the ss.onLoad method and use:



paulpsd7Author
Inspiring
April 10, 2007
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!
kglad
Community Expert
Community Expert
April 10, 2007
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:

paulpsd7Author
Inspiring
April 10, 2007
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!)
kglad
Community Expert
Community Expert
April 9, 2007
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.
paulpsd7Author
Inspiring
April 10, 2007
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.
kglad
Community Expert
Community Expert
April 10, 2007
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
kglad
Community Expert
Community Expert
April 9, 2007
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?
paulpsd7Author
Inspiring
April 9, 2007
Good question. However, I've already embedded the fonts. I did your "this is a test" test, and that text appeared fine.
paulpsd7Author
Inspiring
April 9, 2007
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?