Groups | Blog | Home
all groups > flash (macromedia) > june 2005 >

flash (macromedia) : changing text formatting in a dynamic text box


kasnani
6/17/2005 7:22:35 PM
I have a dynamic text box in which I want to enter some text, but I want certain words to appear in a different color, and bolded or italicized. Any one know how I could achieve that?

beatricethecat
6/17/2005 7:31:50 PM
yeah, you'll have to use HTML code. for example, if you want it a different
color, use <font color="FFFFFF">. then after that word, if you want the color
to change or go back to the original color, use</font>. its the same for bold
or italics, i.e. <B></B>, or <I></I>. the font color has to be numeric, not a
word. i've found that using HTMLin the the text box can be a little tricky,
not everything will work. this is all really basic HTML stuff, you can
probably look up a HTML page that lists a bunch of stuff to try.

good luck!

j
kasnani
6/17/2005 7:41:06 PM
Thanks for your answer...i have one more small doubt - so to use HTML, do I
need to activate or enable a special feature of some sort, or do I just type in
my actionscript:

text_box.text = "blah blah <b> more </b> blah" ?
robva155
6/17/2005 10:17:34 PM
kasnani,

the feature you're asking about refers to the "render text as HTML" button on
the property inspector. There are actually 2 methods of using the rendering
feature; but only one of them allows for a great deal more of formatting
control. (The following assumes that you're not going to use CSS with this,
but rather straight HTML...)

the first technique is rather simple: create a dynamic text box, check the
"render as HTML" option in the property inspector and assign it an instance
name. Then create an action on a frame with the following code as an example:

dtb.htmlText = "this is <b>bold</b>and this is <i>italics</i>.";

where "dtb" is the instance name of the dynamic text box and ".htmlText" is a
property available to elements of this nature. The biggest limitation to this,
however, is the inability to use <font> tags. So that pretty much eliminates
any chance of using font color, size, ect, but the line of code above will
populate your text box with the string as seen above.

A richer way to incorporate html formatting is to hook up the dynamic text box
to an external text file that uses the dtb's variable/instance name. What you
would do is format your .txt document with all the html markup you want to use
(i.e.: <p>, <b>, <i>, <font>, etc) which would render at run-time. And again,
you need to have the "render text as HTML" feature turned on for your dtb in
flash.

Bottom line, assign an instance name to a dtb, like myVariable for example.
In the text file (yes, that means a .txt file!) that you want to load, make
sure that the variable you use for your dtb appears at the beginning of your
document so that it reads:

myVariable= (then the rest of your text info appears here....and yes, you must
use the "=" sign following your variable with no spaces between the two!)

Then, back in flash, include the following code on a frame:

loadVariablesNum("url of your text file", 0);

the first parameter (in quotes) is for you to tell flash where your text file
is stored. the second tells flash to load it on level 0, and that's where your
dtb is assuming that it's on the main timeline. You could also opt for loading
your external text file into a target, which is what I use almost exclusively.
There are a ton of resources/tutorials on what I meagerly mentioned here; but
hopefully this will give you a better glimpse of what you can do with html
formatted docs.

Hope this helps!

Rob
Der_Zählmeister
6/18/2005 11:59:10 AM
[quoted text, click to view]


you must change the text box's settings to display HTML code (look for
the button with "<>"), and you use the ".htmlText" property instead of
the ".text" property, like this:-

text_box.htmlText = "blah blah <b> more </b> blah";

-----
The Count, Singapore
kasnani
6/20/2005 1:16:20 PM
AddThis Social Bookmark Button