LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-17-2007, 01:56 AM
Scottae's Avatar
Scottae Scottae is offline
God Moderator
 
Join Date: Oct 2003
Location: United States
Posts: 6,532
Rep Power: 16
Scottae is on a distinguished road
Thumbs Up A way around having to embed fonts

Many of my projects require me to embed fonts in order to do alpha fade effects with text. Since most of my work is class based, I have to dynamically create text fields. And to embed fonts for dynamic fields, you have to create font symbols. And font symbols are always big. To simply embed Arial for example is about 20K. That is only one style of the font. That doesn't include bold or italics. Those would be another 20K each. That sucks big time. But there is a work around for this.

I don't know why I didn't think of this sooner, but I came to a realization that you can use filters on the text field in order to get around the need for embedding to set text alpha. You can create a filter object that has everything set to zero so it's not visible that a filter is being used on the text. Once you set the filter object to the filters property, you can tween the alpha as if the font were embedded for the text field.

Here's some example code of what happens when you try to tween the alpha of a text field without embedding the font:

Actionscript:
import mx.transitions.easing.None;
import mx.transitions.Tween;

// Create dynamic text field
var txt:TextField = _root.createTextField("txt", 0, 20, 20, 200, 30);
txt.border = true;
txt.text = "The alpha is now : 100";

// Set up tween object to fade the alpha of the text field
var tween:Tween = new Tween(txt, "_alpha", None.easeNone, 100, 0, 3, true);
tween.onMotionChanged = tween.onMotionFinished = onAlphaChanged;
tween.FPS = 60;
tween.stop();

// Triggered when tween is changing, this will update the text field
function onAlphaChanged(pTween:Tween):Void {
	txt.text = "The alpha is now : " + Math.floor(pTween.position).toString();
}

// Click to start
onMouseUp = function(){
	tween.start();
}

When you run this and click the stage, the text field will show the alpha counting down, but the text field does not fade out. But now if you add this little bit of code at the bottom of the above code:

Actionscript:
// Adds a drop shadow to the text field
import flash.filters.DropShadowFilter;
var ds:DropShadowFilter = new DropShadowFilter(0, 0, 0, 0, 0, 0);
txt.filters = [ds];

Now when you run it and click the stage, the text field will fade out as expected.

After I tried this, I searched around and this is a known thing, but I've never run across this fact. Very nice little trick. But there are down sides to this. Most noticeable is that the font looks very aliased. But if you want your text to look like bitmap fonts, then this is a benefit.
__________________
Our greatest glory is not in never falling but in rising everytime we fall. - Confucius

Blog | Shared Items
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Embed fonts in multiple text fields? Coss Newbies 6 11-18-2008 06:25 PM
embed fonts in dynamic htmlText flds? elliottg Flash MX 2004 2 05-03-2005 03:03 PM
Embed fonts with Style Sheet d60eba Flash MX 2004 2 11-05-2004 10:55 AM
To embed fonts for use in HTML formatted text fields Scottae Flash MX ActionScript 5 12-21-2003 08:15 AM
embed fonts in scripted textfiled?? Vayu Flash MX ActionScript 9 03-24-2003 08:39 PM




All times are GMT. The time now is 07:24 AM.