Several methods to realize transparency effect of text field

Source: Internet
Author: User
Transparent

Flash Player 6 begins to support text field (TextField) Transparency Properties (alpha), but Textfield._alpha only supports text fields that are rendered using embedded font outlines (Textfield.embedfonts = true). The text field rendered for the default device font is not valid.

Here's how Textfield._alpha is implemented, and the following code sets the transparency of my_txt text to 20%. Click the library-> new font option, create a font symbol, and then set the font symbol link identifier to "my font."

var my_fmt:textformat = new TextFormat ();
My_fmt.font = "my font";//' My font ' is the link identifier for the font symbol in the library
This.createtextfield ("My_txt", This.getnexthighestdepth (), 10, 10, 100, 22);
My_txt.border = true;
My_txt.embedfonts = true;//Renders a text field with an embedded font outline
My_txt.text = "Hello World";
My_txt.settextformat (MY_FMT);
My_txt._alpha = 20;

The above method uses the font components, is not very convenient to use, and as a result of the packaging of fonts at the time the SWF file is relatively large. To learn more about font components, see Flash technotes:using font symbols,creating font symbols.

The following two methods discard Textfield._alpha and simulate the transparency of the text field.

  One, by setting the color simulation

function Setalpha (obj, Alpha) {
var rgb = "0x" + (255* (100-alpha)/100). toString (16);
RGB = RGB << 16 | RGB << 8 | Rgb
Obj.backgroundcolor |= RGB;
Obj.bordercolor |= RGB;
Obj.textcolor |= RGB;
}

  Second, by creating a film clip composition of the Mongolian layer

function Setalpha (obj, Alpha) {
var tmp_mc_name:string = obj._name+ "_ALPHAMASK_MC";
var tmp_mc:movieclip = eval (tmp_mc_name);
if (!TMP_MC) {
TMP_MC = This.createemptymovieclip (Tmp_mc_name,this.getnexthighestdepth ());
Tmp_mc.beginfill (0xFFFFFF);
Tmp_mc.moveto (0, 0);
Tmp_mc.lineto (20, 0);
Tmp_mc.lineto (20, 10);
Tmp_mc.lineto (0, 10);
Tmp_mc.lineto (0, 0);
Tmp_mc.endfill ();
}
tmp_mc._x = obj._x;
tmp_mc._y = obj._y;
Tmp_mc._width = (obj.border)? Obj._width+1:obj._width;
Tmp_mc._height = (obj.border)? Obj._height+1:obj._height;
Tmp_mc._alpha = 100-alpha;
}

How to use:

This.createtextfield ("My_txt", This.getnexthighestdepth (), 10, 10, 100, 22);
My_txt.text = "Hello World";
Setalpha (my_txt,50)//Set My_txt text transparency to 50%



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.