all groups > flash actionscript > april 2007 >
You're in the

flash actionscript

group:

Displaying results in a text column



Displaying results in a text column paulpsd7
4/9/2007 6:42:47 PM
flash actionscript: 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.
Re: Displaying results in a text column kglad
4/9/2007 7:42:12 PM
where have you initialized all_recs? you need:

Re: Displaying results in a text column paulpsd7
4/9/2007 7:53:39 PM
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.
Re: Displaying results in a text column kglad
4/9/2007 7:58:27 PM
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.
Re: Displaying results in a text column paulpsd7
4/9/2007 8:05:30 PM
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.
Re: Displaying results in a text column kglad
4/9/2007 8:26:41 PM
Re: Displaying results in a text column paulpsd7
4/9/2007 8:32:44 PM
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.
Re: Displaying results in a text column kglad
4/9/2007 8:36:11 PM
Re: Displaying results in a text column paulpsd7
4/9/2007 8:39:48 PM
[q][i]Originally posted by: [b][b]kglad[/b][/b][/i]
you don't want to assign htmlText to recommendations until all_recs is defined
and no longer undergoing concatenation.[/q]

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.


Re: Displaying results in a text column paulpsd7
4/9/2007 8:41:03 PM
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?
Re: Displaying results in a text column kglad
4/9/2007 9:03:37 PM
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?
Re: Displaying results in a text column paulpsd7
4/9/2007 9:39:29 PM
Re: Displaying results in a text column kglad
4/9/2007 11:35:40 PM
on frame 2 just after recommendations has its htmlText property defined, use:

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

Re: Displaying results in a text column paulpsd7
4/10/2007 1:37:10 AM
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.
Re: Displaying results in a text column kglad
4/10/2007 1:58:00 AM
Re: Displaying results in a text column paulpsd7
4/10/2007 2:45:00 AM
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!
Re: Displaying results in a text column kglad
4/10/2007 4:52:26 AM
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:



setInterval(testF,1);
function testF(){
trace(recommendations.text.substring(0,50));
}
Re: Displaying results in a text column paulpsd7
4/10/2007 7:20:49 PM
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!)
Re: Displaying results in a text column kglad
4/10/2007 7:39:20 PM
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.
Re: Displaying results in a text column paulpsd7
4/11/2007 10:11:47 PM
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?
Re: Displaying results in a text column kglad
4/11/2007 10:30:10 PM
remove your duplicate code that was outside the ss.onLoad method and use:





var ss:TextField.StyleSheet = new TextField.StyleSheet();
ss.onLoad=function(){
recommendations.multiline = true;
recommendations.wordWrap = true;
recommendations.html = true;
recommendations._quality = "HIGH";
recommendations.styleSheet = ss;
recommendations.htmlText = all_recs;
}
ss.load("kaiser_hra.css");
Re: Displaying results in a text column paulpsd7
4/11/2007 11:18:11 PM
Alas, that didn't work. Same result as before.

Re: Displaying results in a text column kglad
4/12/2007 12:17:06 AM
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.
Re: Displaying results in a text column paulpsd7
4/12/2007 12:22:40 AM
Stylesheet is attached.

body {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 14px;
color: #666549;
}

body_text {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 14px;
color: #666549;
}

a:link {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
text-decoration: underline;
color: #1A7486;
}

a:visited {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
text-decoration: underline;
color: #0A505E;
}

a:hover {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
text-decoration: none;
color: #000000;
}

h1 {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 16px;
color: #0A2634;
font-weight: bold;
margin-top: 10px;
}

h2 {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
color: #0A2634;
font-weight: bold;
margin-top: 5px;
margin-bottom: 0px;
}
Re: Displaying results in a text column paulpsd7
4/12/2007 12:23:51 AM
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.
Re: Displaying results in a text column kglad
4/12/2007 12:33:21 AM
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.
Re: Displaying results in a text column paulpsd7
4/12/2007 12:49:49 AM
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
Re: Displaying results in a text column kglad
4/12/2007 2:22:21 AM
that was an interesting path we took to the solution. and you're welcome.

AddThis Social Bookmark Button