flashgameblog.at

05.07.2010
22:40

flash's font hell 3 - Accessing the embedded font

Today we will fill a textfield and let it use an embedded font.

To fill a textfield it provides us two properties text and htmlText. It doesn't matter how the text field was created(in the WYSIWYG editor of programatically.)

Text with directly embedded font


This is the easiest way to asign a text. But it is less flexible too. We can't format the text at runtime. We just can change the textfield's properties in Flash and export the film again.

  1. textField.text = "Today is a wonderful day!";

 

Text property with font from the library

 

This is basically working in the same way as the example above. But to asign a Font we need some additional lines of code.

  1. textField.text = "Today is a wonderful day!";
  2.  
  3. var newFormat:TextFormat = new TextFormat();
  4. newFormat.color = 0xFF0000;
  5. newFormat.size = 18;
  6. newFormat.underline = true;
  7. newFormat.italic = true;
  8. newFormat.font = "Arial";
  9.  
  10. textField.setTextFormat( newFormat );

HtmlText with directly embedded font

 

This is simply not possible to do.

 

HtmlText with font from the library

 

This is the most flexible way and it needs surprisingly less lines of code. There are just some points to care about when using this methode:

  1. All formatting issues has to be done in html.
  2. The embedFont property of the text field has to be set to true.
  1. textField.embedFonts = true// if we forget this line the text field wont show anything.
  2. textField.htmlText = "<font face='Arial' size='12' >Today <i>is a </i> <b>wonderful</b> <font color='red'>day!</font></font>";

So I think that's it. This was a small series with the results of the five day studies about the text field. I hope it saves you the time I invested in finding this out. And hopefully you will find it that usefull that you link to it :-)

Oh wait! There is just one more thing!

 

Font name

 

When we embed a font into the library we have to activate the checkbox "export for actionscript". This says flash to put the font into the swf file. With activating this option we have to give this library item an export name too. Unfortunately this isn't the name of the font we have to use in actionscript. While compiling the swf file flash generates new names for the embedded fonts. So at authoring time of the swf file we don't know the name flash will generate for a font.

How do we know the names of the embedded fonts? We have to write a small script that traces all font names. After executing it one time we can go back to our source code and access our font with its name.

  1. var embeddedFonts:Array = Font.enumerateFonts(false);
  2. for ( var i:int = 0; i < embeddedFonts.length; i++)
  3.    trace( "'"+embeddedFonts[i].fontName+"'", embeddedFonts[i].fontStyle, embeddedFonts[i].fontType );

In most cases the ordinary font name and the name flash generates to access it via actionscript will be the same. As soon as we embed a font as bitmap font its guaranteed a generic name. So keep it in mind.

 

Well, that's it.

 

Here you can download a zip file containing three flas to see all the stuff working.

fontEmbedding.zip

  •  
  • 0 Comments
  •  

Your comment

Notify me when someone adds another comment to this post

back

< < July 2010 > >
S M T W T F S
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Blog rolls

Latest Comments

Blur Filter
17.01.2011 11:01
ISO FTW!
18.09.2010 20:17
ISO Blender Camera Setup
24.04.2010 06:58
update
21.03.2010 01:15

Archive

  • [-]2010(9)
    • [-]November(1)
    • [-]August(1)
    • [-]July(1)
    • [-]June(2)
    • [-]April(1)
    • [-]March(2)
    • [-]February(1)
  • [-]2009(13)
    • [-]December(4)
    • [-]November(8)
    • [-]October(1)

Copy and paste this link into your RSS news reader

RSS 0.91Posts
RSS 2.0Posts

Social Bookmarking

Bookmark bei: Mr. Wong Bookmark bei: Webnews Bookmark bei: Icio Bookmark bei: Oneview Bookmark bei: Linkarena Bookmark bei: Favoriten Bookmark bei: Seekxl Bookmark bei: Favit Bookmark bei: Social Bookmarking Tool Bookmark bei: Power Oldie Bookmark bei: Bookmarks.cc Bookmark bei: Newskick Bookmark bei: Newsider Bookmark bei: Linksilo Bookmark bei: Readster Bookmark bei: Folkd Bookmark bei: Yigg Bookmark bei: Digg Bookmark bei: Del.icio.us Bookmark bei: Reddit Bookmark bei: Simpy Bookmark bei: StumbleUpon Bookmark bei: Slashdot Bookmark bei: Netscape Bookmark bei: Furl Bookmark bei: Yahoo Bookmark bei: Spurl Bookmark bei: Google Bookmark bei: Blinklist Bookmark bei: Blogmarks Bookmark bei: Diigo Bookmark bei: Technorati Bookmark bei: Newsvine Bookmark bei: Blinkbits Bookmark bei: Ma.Gnolia Bookmark bei: Smarking Bookmark bei: Netvouz Information