View Full Version : text field, alpha and special characters
aneta
September 5th, 2008, 04:57 PM
Hi all,
I’m pretty new to Flash, but form the start I have a big struggle with coding. Hope some smart, experienced flash coder can help me with that.
I want to create an empty text box in the actionScript. Then I want to pass a variable to it, and set up its alpha to 50% (I embedded the Verdana font and linkage it to actionScript).
This is my code:
var myTxt:String="Łódź, Poznań; Moscow:Москва; Minsk: Мінск";
var txt_fmt:TextFormat = new TextFormat();
txt_fmt.font = "myFont";
txt_fmt.size = 24;
txt_fmt.color = 0xBF0000;
this.createTextField("city_txt", this.getNextHighestDepth(), 25, 5, 200, 40);
city_txt.type = "dynamic";
city_txt.embedFonts=true;
city_txt.setNewTextFormat(txt_fmt);
city_txt.text = myTxt;
city_txt._alpha=50;
My problem is that it doesn’t want to display special characters like Polish or Russian letters. I know, that it is possible to embed characters, but I guess it is only possible to the text elements placed on the stage, and I need to create this text box dynamically in the code.
I tried to change the font into: Arial CYR, but still nothing. What I managed to discover so far is, if the line: "city_txt.embedFonts=true;" is removed, than everything is displayed correctly but than I can’t see my alpha.
Yuu
September 5th, 2008, 05:19 PM
Try this, you'll need a font embedded in your library with it's linkage Class set to _Harmony and Base class to flash.text.Font to just drop this in and have it work. But you can always swap out the font later.
An alternative would be to use a CSS style as opposed to the TextFormat I have in this example.
var harmony:Font = new _Harmony();
var body:TextField = new TextField();
// Formatting for the Body Field
var bodyText:TextFormat = new TextFormat();
bodyText.font = harmony.fontName;
bodyText.color = 0x000000;
bodyText.size = 8;
bodyText.leading = 3;
//// Apply the formatting to the fields
//Field Properties for text Field "body"
body.embedFonts = true;
body.defaultTextFormat = bodyText;
body.width = 380;
body.autoSize = TextFieldAutoSize.LEFT;
body.multiline
body.wordWrap = true;
body.border = false;
body.borderColor = 0xFFFFFF;
body.selectable = false;
body.antiAliasType = AntiAliasType.NORMAL;
addChild(body);
body.text = "Fooooo"
body.alpha = .5;
aneta
September 6th, 2008, 02:20 AM
Thanks for advise. I will check your solution and come back later.
Alex Lexcuk
September 6th, 2008, 05:15 AM
I am not using Embed, but alpha works
text to bitmap
http://www.dnadillo.dn.ua/fla/alpha_text.swf
var txt:TextField = new TextField();
txt.htmlText = "<font face='Times New Roman' color='#7777ff' size = '60'>Москва </font>\n "+
"<font face='Comic Sans MS' color='#ff0000' size = '60'>Донецк</font>\n "+
"<font face='Arial Cyr' color='#00aa00' size = '55'>Минск</font>\n "+
"<font face='Courier New' color='#0000ff' size = '60'><b>Baltimor</b></font>\n ";
txt.autoSize = TextFieldAutoSize.LEFT;
txt.multiline = true;
var t_shape = compress_text_to_shape(txt);
addChild(t_shape);
t_shape.alpha = 0.5;
function compress_text_to_shape(c_txt:TextField):Shape
{
var t_scale:int;
t_scale = 5;
var bd:BitmapData
= new BitmapData(txt.width*t_scale, txt.height*t_scale, true, 0x00000000);//width,height,transparent,color
var myMatrix:Matrix = new Matrix();
myMatrix.createBox(t_scale, t_scale, 0, 0, -30);//scaleX,scaleY,rotation,x,y
bd.draw(txt, myMatrix, null, null, null, true);//source, matrix, colorTransform, blendMode, clipRect, smoothing
var text_sh:Shape = new Shape();
text_sh.graphics.beginBitmapFill(bd,null, false, true);//bitmap, matrix, repeat, smooth
text_sh.graphics.drawRect(0, 0, txt.width*t_scale, txt.height*t_scale);
text_sh.graphics.endFill();
text_sh.scaleX = text_sh.scaleY = 0.25;
return text_sh;
}
http://www.dnadillo.dn.ua/fla/alpha_text.zip
aneta
September 6th, 2008, 05:58 AM
I tried both solutions and ....
Yuu: after defining Linkage to: “Class: _Harmony” and “Base class: flash.text.Font”, I get message: “A definition for this class could not be found in the classpath, so one will be automatically generated in the SWF file upon export”. I guess it’s nothing critical, but when I run the script I got a error list like:
Description: 1120:Access of undefined property bodyText. Source: bodyText.TextFormat = new TextFormat();. I don’t know if there is something that I’m missing on my maschine (flash classes)??
Alex Lexcuk: I tried the code briefly on some small example, and it works fine. Now I will just have to try and see how it works in my file. Thanks a lot for the solution. I will post later how it is going with it.
aneta
September 6th, 2008, 06:02 AM
Sorry Yuu, but I put line brakes in your code incorrectly. It works fine, but when I put body.text = "Москва", it doesn't display anything.
theCodeBot
September 6th, 2008, 09:21 AM
I tried both solutions and ....
Yuu: after defining Linkage to: “Class: _Harmony” and “Base class: flash.text.Font”, I get message: “A definition for this class could not be found in the classpath, so one will be automatically generated in the SWF file upon export”. I guess it’s nothing critical, but when I run the script I got a error list like:
Description: 1120:Access of undefined property bodyText. Source: bodyText.TextFormat = new TextFormat();. I don’t know if there is something that I’m missing on my maschine (flash classes)??
Alex Lexcuk: I tried the code briefly on some small example, and it works fine. Now I will just have to try and see how it works in my file. Thanks a lot for the solution. I will post later how it is going with it.
I think it just needs to be "Harmony" not "Class: _Harmony" here. It's trying to import something that doesn't exist, giving your first error, and your second error is because it's trying to work with that class it never imported.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.