all groups > flash actionscript > june 2005 >
You're in the

flash actionscript

group:

Background for Text, not Text field


Background for Text, not Text field Richard Ragon
6/18/2005 5:06:58 PM
flash actionscript:
Is there a way to place Dynamic text with a background on the fonts, and
not on the text field. Kind of like the same way line 21 text comes up
on a TV.

I'm creating an application that will have white letters of text with
black foreground on the screen, but I don't want a background showing if
there is NO text on the screen.

Re: Background for Text, not Text field kglad
6/19/2005 12:00:00 AM
you'd have to put each letter in its own textfield. you could create a
movieclip and add a textfield to it.

this movieclip could be duplicated with the duplicates positioned and assigned
text yielding the effect, i think, that you want.
Re: Background for Text, not Text field Rothrock
6/19/2005 12:00:00 AM
What is line 21 text?

If you are using MX04, you can make use of getTextExtent();. It is available
in MX, but is not terribly useful.

You can use that to either make a textbox just the size you need. Or to give
coordinates to the drawing API and draw your own background.

Or you could take kglad's advice. It seems really ambitious, but it could also
lead to a real nice text engine.
Re: Background for Text, not Text field rlc5611
6/19/2005 12:00:00 AM
Rothrock,

My getTextExtent in MX 2004 is still off by a few pixels. Did you ever solve
this and, if so, how? I seem to be off somewhere between two and four pixels
(i.e. getTextExtent always comes in a smidge low on its calculation). I should
add that if you use the numbers it returns for the drawing API, I don't have
any complaints but if you use it to set the text box size when you
createTextField, it fails. What I do is use the text I want to place and
getTextExtent against the format I plan to use and then create the text field
according to its parameters but I always have to add a bit for some reason. I
think I remember you saying you had sorted this out so I was just curious.
Re: Background for Text, not Text field Rothrock
6/19/2005 12:00:00 AM
That was so long ago. :) I didn't seem to see the really awful problem that the
other poster had. I remember that I was able to make something that exactly
lined up with the text I typed, but of course I can't find that little test
file now! I also seem to recall something about embedding the font or not
embedding the font and alias/anti-alias. But over all I've found it to be very
easy to work with.

From the metrics object, you are using textFieldWidth and not width?

And Richard, I forgot to mention TextField.autosize. I've never used it, so I
don't know the ins and outs.
Re: Background for Text, not Text field rlc5611
6/19/2005 12:00:00 AM
I am using textFieldWidth and textField Height. I get them to return values
close but just shy. If I use getTextExtent and then create the text field based
on textFieldHeight alone and I have multiline text, the last line is not
displayed. Also the width cuts off.

For example, take a look at the following. Is this simply because I have not
embedded fonts that I am having this problem? (I have been working very hard to
avoid having to embed fonts).



my_text = new TextFormat();
my_text.bold = false;
my_text.align = "left";
my_text.font = "Arial";
my_text.color = 0xFF0000;
my_text.underline = false;
my_text.size = 6;
my_text.italic = false;

var textinfo = my_text.getTextExtent("hello world");


this.createTextField("my_label1",1,50,50,textinfo.textFieldWidth,textinfo.textFi
eldHeight);
this["my_label1"].setNewTextFormat(my_text);
this["my_label1"].selectable = false;
this["my_label1"].text = "hello world";

textinfo = my_text.getTextExtent("how are you?\ni am fine",50);

//this won't work:

this.createTextField("my_label2",2,50,100,textinfo.textFieldWidth,textinfo.textF
ieldHeight);
this["my_label2"].setNewTextFormat(my_text);
this["my_label2"].selectable = false;
this["my_label2"].multiline = true;
this["my_label2"].text = "how are you?\ni am fine";

//this will work:

this.createTextField("my_label2",2,50,100,textinfo.textFieldWidth,textinfo.textF
ieldHeight+2);
this["my_label2"].setNewTextFormat(my_text);
this["my_label2"].selectable = false;
this["my_label2"].multiline = true;
this["my_label2"].text = "how are you?\ni am fine";

//why do I have to add 2?
Re: Background for Text, not Text field Rothrock
6/19/2005 12:00:00 AM
kglad I looked up line 21 text and it is what I would call "closed captioning."
As I remember it (I can't find the button on my TV to turn it on at the
moment.) the spaced between words have a background, but the background is only
as big as needed for the line.

So I'll go with my original idea or autosize. But until Richard comes back...


Re: Background for Text, not Text field kglad
6/19/2005 12:00:00 AM
Re: Background for Text, not Text field NSurveyor
6/19/2005 12:00:00 AM
Richard, I believe that using autoSize will work for your purpose (like
Rothrock suggested). If you use a background color for your textfield, and set
autoSize to true, then the background should only be seen behind all the text.

BTW rlc5611,
http://groups-beta.google.com/group/macromedia.flash.actionscript/msg/a4996ee912
2313d2
Re: Background for Text, not Text field kglad
6/19/2005 12:00:00 AM
Re: Background for Text, not Text field rlc5611
6/19/2005 12:00:00 AM
Re: Background for Text, not Text field rlc5611
6/19/2005 12:00:00 AM
Well actually I think it is very germane to the orignal poster if he were to
choose to use Rothrock's suggestion of getTextExtent. Rothrock advised that it
did not work well in MX (with which I agree) but he said it worked well in MX
2004 (of which I am not sure). Based on what I have seen with getTextExtent (in
MX 2004), I am not sure it is the best suggestion to solve the OP's problem. If
it is a valid solution, there is more to it than is explained in the help file.
In other words, it will not return the textfield size of the correct
dimensions. If all you are doing is using the drawing API to draw a box behind
it, it is moot. If you are using it to fill the textfield with a background
color, it is very relevant to the OP. In other words, your original concept may
be the better alternative - at least the one with the fewest complications.
Re: Background for Text, not Text field kglad
6/19/2005 6:44:41 AM
it was my impression that he wanted characters to appear on an colored
background, but not have a colored background where no characters were
positioned. ie, spaces between characters would not have a background color.
that's why i made my suggestion.

i've done some work with this in the past when creating gaming clan websites,
where you can achieve some nifty text effects by rotating and moving the
movieclip containing the textfield.

but for rr's purpose that wouldn't be necessary. you'd just parse the text
string and allocate each character to a distinct textfield. textfield's
containing a space would not have a background color assigned. the other's
would.
Re: Background for Text, not Text field rlc5611
6/19/2005 7:10:47 AM
Re: Background for Text, not Text field mandingo
6/19/2005 7:27:32 AM
hey rlc, last night he told me I was right and STILL wrong... so go figure...
then he wonders why we trash him ... j/k :)

I noticed with getTextExtent too that it isn't a precise science but it has
never had to be that exact for me.

On a personal note and unrelated to this thread, where would one find a copy
of those old publications? I googled for them last night but couldn't get
anymore than the SIAM bibliographical listing.
Re: Background for Text, not Text field rlc5611
6/19/2005 10:54:52 AM
Mandingo,

Maybe you could look here:


https://www1.lib.purdue.edu/cgi-bin/Pwebrecon.cgi?v1=1&hd=1,1&CallBrowse=36&SEQ=
20050619055004&PID=13007&SID=4

I think that particular family name represents about half the student body.
They are prolific authors.
Re: Background for Text, not Text field Richard Ragon
6/19/2005 12:49:34 PM
[quoted text, click to view]

Yes.. It's closed captioning... or the look of it that I wanted to do.
The text MUST remain the same size, and I can have up to 5 lines. The
closed captioning on the TV only have max 2 lines.

But, yes.. this is what I wanted to do. I wanted a background on each
of the letter only, and no background where there is no text.

Lets say, I have no text at the moment on my Movie. I don't want to see
a black background without text. If I line is placed, I want just that
line to have white lettering, background only around the letters. If a
second line gets placed, I want that line to also have white letters,
black background only around those letters.. and so on.

I haven't tried any of those suggestions yet. I'll do that tonight when
I get a change to sit down. Thanks all for the suggestions.

Re: Background for Text, not Text field kglad
6/19/2005 1:34:17 PM
i don't know if any of use now what the thread originator really wants. i just stated what i thought he wanted and that explained my suggested solution.

Re: Background for Text, not Text field knut_einar_skjær
6/19/2005 2:51:05 PM
[quoted text, click to view]

I think it still would work with autoSize, using 'my_txt.autoSize =
"right";' and using newlines in the text (\n) wich, I guess, also will
make it possible to count lines...

--
Knut Einar Skjær
Re: Background for Text, not Text field kglad
6/19/2005 9:41:01 PM
Re: Background for Text, not Text field mandingo
6/19/2005 11:08:39 PM
If this is "tele-texting" i.e. trying to emulate the close captioning that
hearing impaired people can get on a tv set box, then the appearance is that
each word has a background and the spaces between don't. (Well that is how it
works here anyway).

Kglad's idea still holds however split the text into an array splitting on the
spaces to create the required number of text fields with each element appearing
in it's own field. Space them out by so many pixels to get the appearance of
the spacing that won't have a background.

The hardest part in doing this is keeping track of the length of the lines,
but that isn't too difficult as you count the length of the array items...

my two cents worth if interested.

cheers,
Re: Background for Text, not Text field rlc5611
6/20/2005 12:00:00 AM
Well having done captioning and having fought getTextExtent extensively, my
preferred method is not to use a background color for the textbox itself but
rather use the drawing API to draw a rectangle behind the text. The
getTextExtent method works well enough and accurately enough to allow that and
it has the added convenience that I can use an alpha less than 100% (like the
Discovery channel does). A little bit like this:



my_text = new TextFormat();
my_text.bold = false;
my_text.align = "left";
my_text.font = "myfont";
my_text.color = 0xFF0000;
my_text.underline = false;
my_text.italic = false;
this.createTextField("myinput",1,50,50,100,20);
this["myinput"].setNewTextFormat(my_text);
this.myinput.type = "input";
this.myinput.border = true;
this.myinput.text = "your text here";

my_text.color = 0xFFFFFF;
this.createTextField("my_label1",2,50,100,300,20);
this["my_label1"].setNewTextFormat(my_text);
this["my_label1"].selectable = false;

this.createEmptyMovieClip("mybackground",0);
this.mybackground._x = 50;
this.mybackground._y = 100;
this.mybackground.lineStyle(0,0x000000,0);
this.myinput.onChanged = function() {
var textinfo = my_text.getTextExtent(this.text);
this._parent.mybackground.clear();
this._parent.mybackground.beginFill(0x000000,50);
this._parent.mybackground.moveTo(0,0);
this._parent.mybackground.lineTo(0,textinfo.textFieldHeight);

this._parent.mybackground.lineTo(textinfo.textFieldWidth,textinfo.textFieldHeig
ht);
this._parent.mybackground.lineTo(textinfo.textFieldWidth,0);
this._parent.mybackground.lineTo(0,0);
this._parent.my_label1.text = this.text;
}
AddThis Social Bookmark Button