PDA

View Full Version : Problem setting alpha to a Textfield....



richierich1125
February 12th, 2008, 11:21 PM
I want to dynamically pull text from a XML file and load it into a Textfield. I have added the text and applied styles to it via TextFormat. However, I can't change the alpha to zero. I have no idea why. I even tried adding it into a sprite and setting the sprite's alpha to zero. Can anyone help? Here is the code.

var txtName:TextField = new TextField;
var myFormat:TextFormat = new TextFormat();
var sprName:Sprite = new Sprite();
sprName.addEventListener(Event.ADDED_TO_STAGE, AddComplete);

BuildFormat();
BuildName();

function BuildFormat():void
{
myFormat.font = "Arial";
myFormat.color = 0x990000;
myFormat.size = 22;
}

function BuildName():void
{
txtName.autoSize = TextFieldAutoSize.LEFT;
txtName.text = "This is a test.";
txtName.setTextFormat(myFormat);
sprName.addChild(txtName);
addChild(sprName);
}

function AddComplete(event:Event):void
{
sprName.x = stage.stageWidth - sprName.width;
sprName.y = stage.stageHeight - sprName.height;
sprName.alpha = 0;
}

McGuffin
February 12th, 2008, 11:38 PM
Have you tried setting txtName.embedFonts to true? This is normally the issue.

richierich1125
February 12th, 2008, 11:46 PM
Have you tried setting txtName.embedFonts to true? This is normally the issue.

Yes. When I do that nothing is displayed. I lose the text.

McGuffin
February 12th, 2008, 11:48 PM
Yes. When I do that nothing is displayed. I lose the text.

That means you haven't embedded the font in the library. Go to the Library panel, right click, select "Add font..." (or something along the lines of that, I don't have Flash open), and then add the font (in this case, Arial) and give it an instance name of say, EmbeddedArial and then use that as your format's font.

This is just one of those quirks in Flash's typography engine, without embedding the font and setting embedFont to true, alpha's will not display correctly and masking the text won't work either.:worried:

richierich1125
February 13th, 2008, 12:32 AM
That means you haven't embedded the font in the library. Go to the Library panel, right click, select "Add font..." (or something along the lines of that, I don't have Flash open), and then add the font (in this case, Arial) and give it an instance name of say, EmbeddedArial and then use that as your format's font.

This is just one of those quirks in Flash's typography engine, without embedding the font and setting embedFont to true, alpha's will not display correctly and masking the text won't work either.:worried:

Dude!!!! It worked! Why does flash make you do that just to change the crusty little alpha property. I can manipulate any of the others except that. Weird. Whatever, it works. Thanks a ton!

McGuffin
February 13th, 2008, 10:11 AM
Basically it has to do with having the font outlines embedded in the SWF. Without them embedded, Flash won't be able to render the font properly. Seems like extra work, and it is, but it makes sense when you think about it. Flash's rendering engine would have no idea what the characters in your font would look like if it's not embedded, so how is it supposed to display things like alphas and masks?

Anyway, cheers! Happy to help!