Tutorial (AS3): Using Fonts Embedded At Compile-Time
Tutorial (AS3): Using Fonts Embedded At Compile-Time
I am continuing to explore the use of external assets embedded at compile time in AS3. Today we will look at how to embed and use a font in this manner. The Embed compile-time directive is available to users of the Flex SDK, Flex Builder, Flash Builder (if and when it comes out), and Flash IDE users (CS4 and beyond).
First, let's find a font
To test this properly you might want to use a font that you do not already have installed. I went to SearchFreeFonts.com and found a nice font that is free for commercial use (this isn't really a commercial use as I lose my shirt on this site, but just in case...). The name of the font is :01-10-00. I recommend that you donate to the creator of any font you find useful.
Let's start the project
I am going to use Flash Develop to do this small project. You don't have to use this. In any case, place all of the files we create in the same folder. This is the /src folder for a Flash develop project. So, for now you will have a single file (we'll use the True Type version of the font) "01-01-00.ttf". I know it is a strange name, but it is a pretty nice font.
Now we will create our main class file
In the same project folder, let's create a class file called: "FontEmbedTest.as". This will need to be the "always compile" class in Flash develop or the "document" class in the IDE.
1. First we will start off our class and import the other classes we need:
| [cc lang="javascript" width="550"] package { import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; import flash.text.TextFieldAutoSize; import Libary; public class FontEmbedTest extends Sprite { |
2. Next we will start the variable definition section of our code and create the TextField and TextFormat objects. We will also embed the font using the file name we downloaded and placed in the project folder. Notice that I set both the fontName and fontFamily to be 'font010100". I did this because when I just set fontName or just fontFamily (as I have seen in some other examples) I was not able to get the font to show up properly across all of the different players (Win and Mac) that I tried. We will not use the class that we create "Font010100:Class" but a class or some variable creation is required after the embed directive as the "linkage" name for the embedded asset. Notice that the embed line was broken to fit in the space alotted.
| [cc lang="javascript" width="550"] private var textField:TextField = new TextField(); private var textFormat:TextFormat = new TextFormat(); [Embed(source='01-01-00.ttf', fontFamily = 'font010100', fontName = 'font010100', |
3. Now we will create the constructor for our class. It will set all of the properties of the TextField and TextFormat instances as well as place the TextField on the screen. Notice that we also finish the class and package brackets to be complete.
| [cc lang="javascript" width="550"]
public function FontEmbedTest() { textField.defaultTextFormat = textFormat; textField.embedFonts = true; textField.text = "Embedded Font"; addChild(textField); } } } |
Here is a screen shot of this file working:

That's it. It is pretty simple actually.
Pingback: Webmaster Crap » Blog Archive » Tutorial (AS3): Using Fonts Embedded At Compile-Time | 8bitrocket
Pingback: vitamins for energy for women
Pingback: Cum
Pingback: Chiropractor Riverside CA
Pingback: jailbreak iphone 4s
Pingback: how to jailbreak iphone 4s
Pingback: czekoladowe fontanny
Pingback: bridgeport
Pingback: order theatre tickets
Pingback: Paintball
Pingback: starchim01
Pingback: live football stream
Pingback: discount theatre ticket
Pingback: Skyrim Strategy Guide
Pingback: Bad Credit car Lease
Pingback: speaker wall mounts
Pingback: wholesale wedding flowers
Pingback: reliable hosting
Pingback: school of autism
Pingback: youtube.com
Pingback: best exercises to lose weight
Pingback: janes
Pingback: Domain host
Pingback: Sauble Beach cottage rentals
Pingback: payday loans
Pingback: new york bankruptcy attorney
Pingback: Trophies
Pingback: gout home remedies
Pingback: work from home jobs
Pingback: educational
Pingback: Auto Repair Columbus GA
Pingback: newborn photographer Melbourne
Pingback: smart investing
Pingback: spy cameras
Pingback: starchim video
Pingback: speech for wedding
Pingback: Indianapolis Cosmetic Dentist
Pingback: cadillacs dallas
Pingback: binahong
Pingback: refund loans
Pingback: farm supplies
Pingback: bmw dealer dallas
Pingback: houston party bus
Pingback: how do i unlock iphone
Pingback: unlock for iphone 4 4.2.1
Pingback: www.realestatevancouver2010.com
Pingback: plndr promo codes
Pingback: Book of Ra
Pingback: natural horsemanship trainers
Pingback: hosting companies business
Pingback: Casas de Lujo en Miami
Pingback: keukenkasten
Pingback: free hosting website
Pingback: Laser teeth whitening
Pingback: Bet365
Pingback: Ile Maurice Location Vacances
Pingback: Injury lawyers San Francisco
Pingback: social security application form
Pingback: Smart Battery Chargers
Pingback: cheap sex toys
Pingback: norwich escorts
Pingback: innskuddbonuser
Pingback: diseno web
Pingback: jobsearch
Pingback: uniquesurroundings.biz
Pingback: http://www.hostingent.com
Pingback: Batterie Ladegerat
Pingback: http://xn--e-solglasgononline-l3b.se/
Pingback: ibuprofen site
Pingback: Sex webcam
Pingback: document shredding
Pingback: Kicks
Pingback: promotional codes
Pingback: Location Vacances Ile Maurice
Pingback: NH dental insurance
Pingback: Microwave Reviews
Pingback: buy a wow pen mouse
Pingback: Agra hotels
Pingback: veterinario perros o gatos
Pingback: tutor perth
Pingback: spay and neuter
Pingback: Mallorca Properties
Pingback: Kitchen Remodeling New York
Pingback: seo nashville
Pingback: Location Vacances Ile Maurice
Pingback: mujeres article
Pingback: auto repair rochester ny
Pingback: Location Villa Maurice
Pingback: appliance repair
Pingback: Aweber autoresponder
Pingback: jailbreak iphone 4 vodafone
Pingback: what stores sell pepper spray
Pingback: iphone jailbreaking
Pingback: mujeres
Pingback: jailbrack me
Pingback: paintball
Pingback: Affiloblueprint
Pingback: click here
Pingback: Awesome post! Hey, make sure you check out how I lost over 70 pounds:
Pingback: suffering from TMJ
Pingback: gratissex