PDA

View Full Version : dynamic textfield alpha problem



icekube12jr
July 12th, 2007, 08:50 PM
Hi,
I created a textfield dynamically through actionscript 3.0 code. The bizarre things is, is that when I call my textfield (it's var is pmlabel), I am able to use other properties properly, but not alpha. For example:

pmlable.visible = false;

That works and makes the textfield invisible. Another example:

pmlabel.text = "Something";

That works and fills the textfield with the word Something. But when I try this:

pmlabel.alpha = 0.5;

Nothing appears to change. I have run a trace statement like this before and after the statement as follows:

trace(pmlable.alpha);
pmlabel.alpha = 0.5;
trace(pmlable.alpha);

output is:
1
0.5

Why won't it actually fade my textfield? Thanks.

icekube12jr

fishbulb
July 12th, 2007, 08:53 PM
I'm not exactly sure, but my guess would be that it is not a movieclip and and text in the textbox is not rasterized yet.

A more technical answer should follow mine shortly.

devonair
July 13th, 2007, 05:55 AM
is the font embedded?

paularmstrong
July 13th, 2007, 09:39 AM
I've found that the text needs to be embedded in a dynamic text field in order to use the alpha channel. Why does it need to be embedded. It's just another way to add too much to the filesize for no real gain.

thatguythatsme
July 13th, 2007, 10:53 AM
I'm not exactly sure, but my guess would be that it is not a movieclip and and text in the textbox is not rasterized yet.

A more technical answer should follow mine shortly.

That sounds about right to me, you couldn't fade a text box out in time line animation unless the textbox is contained within a movie clip. Perhaps try loading it into a movieclip first then setting the alpha on that?

Dave

SquirtGun
July 13th, 2007, 11:46 AM
devonair is correct. The font must be embedded in order for the alpha property to work. it will not matter if you place the text inside another container object. Embedding a font stores its vector information, which is used for this type of action.

Things like rotating your text will also not work unless it is embedded.

You can limit the characters that are embedded to help keep the file size down. Also, fonts can very quite a bit in file size. The more complicated the font, the more "vector" information it needs. So choose a small font if you can.

If you have a bunch of dynamic text fields in your project that you need this for, I would suggest creating a shared font object and then use it for all of your text fields. This will allow you to embed the font once, rather than for each text field individually.

~squirt

icekube12jr
July 13th, 2007, 12:16 PM
Thank you all very much for the replies. And quickly too. I have yet to try the suggestions but they sound very intelligent to me. I'll give them a shot.

icekube12jr

icekube12jr
July 13th, 2007, 02:09 PM
Awesome, you were correct. Fonts need to be embedded. It took me awhile to figure out how to do it dynamically cause there isn't really any proper documentation about this. I was helped by this link:

http://www.nivas.hr/blog/2007/06/06/font-embedding-problems-in-flash-cs3-ide/

darwinkid
November 5th, 2007, 06:24 PM
I am not sure if this is quite what you are looking for but here is a solution I found for adjusting alpha on a TextField object.



// this is obviously not php code. I thought it would help for legibility
// create an empty sprite
var rect:Sprite = new Sprite();
rect.blendMode = BlendMode.LAYER;

addChild(rect);

var txtField:TextField = new TextField();
txtField.txtColor = 0x000000;
txtField.alpha = .5;
txtField.appendText("SOME TEXT");

rect.addChild(txtField);


the key is to set the blendMode property on the sprite to LAYER.

Hope this helps!

kingscooty
November 6th, 2007, 09:09 AM
Interesting :) Is there a way to dynamically declare which characters to embed so the whole font file isnt embeded?

darwinkid
November 6th, 2007, 10:53 PM
I haven't tried. With the code above I am not explicitly embedding any fonts.


Interesting :) Is there a way to dynamically declare which characters to embed so the whole font file isnt embeded?

Superb
March 12th, 2008, 12:35 PM
thank you for this great sollution darwin
beats dynamicly embedding fonts!

if you get errors using this method which look like this:

1120: Access of undefined property BlendMode.

you probably forgot to import the class:

import flash.display.BlendMode;

cheers!

Anogar
March 12th, 2008, 01:36 PM
is the font embedded?

Ding ding ding. Non-embedded fonts cause all kinds of nutty problems. :sigh: Exporting without embedding fonts should really throw a warning or something.