Solved

How can I work with embedFonts in AS3?

Posted on 2009-07-08
14
613 Views
Last Modified: 2013-11-11
I am trying to wrap my head around the embedFonts property.  It looks to be interfering with my formatting of dynamic text.  

I have included some sample text.  What happens on my end (which I hope is duplicated on your end) is that the text shows up with the word "quick" italicized.  Unfortunately, the text field is not anti-aliased.  To fix this, I remove the comment and set embedFonts to true (per the Flash CS3 help file).  This completely kills the text, and now it doesn't show at all.

I haven't had problems with embedFont in my current project, but this example kind of terrifies me because it's not all that different from my main project.

How am I using embedFonts incorrectly, and how can I use it more effectively?
stop();

test_txt.text = "The quick brown fox jumps over the lazy dog.";
 

var italicFormat:TextFormat = new TextFormat();

italicFormat.italic = true;

italicFormat.font = "Arial";
 

test_txt.setTextFormat(italicFormat, 4, 8);
 

//test_txt.embedFonts = true;

test_txt.antiAliasType = AntiAliasType.ADVANCED;

Open in new window

0
Comment
Question by:jkunrein
  • 8
  • 6
14 Comments
 
LVL 22

Expert Comment

by:rascalpants
Comment Utility
take a look at this tutorial...

http://www.tink.ws/blog/embedding-fonts-in-as3/


rp

0
 
LVL 9

Author Comment

by:jkunrein
Comment Utility
I'm not savvy with classes, unfortunately. I would need to save this to a separate .as file and import it?

In any case, do I need to embed Arial?  It is a native font to Flash.
0
 
LVL 22

Expert Comment

by:rascalpants
Comment Utility
You have to embed any font that you want to show up exactly as you intend.  Arial is standard on most PCs and Macs, but you never know.


If you follow that tutorial, you should be able to create what ever you need for this.


rp
0
 
LVL 9

Author Comment

by:jkunrein
Comment Utility
Unfortunately, I ran into a problem with that tutorial.  At compile, Flash throws out this error for Line 2 (which is just the brace, oddly enough):

1037: Packages cannot be nested.

But, it seems to match the syntax in the help file.
0
 
LVL 22

Expert Comment

by:rascalpants
Comment Utility
it probably means you have a brace that is not supposed to be there or is missing...  make sure they all match up.


rp
0
 
LVL 9

Author Comment

by:jkunrein
Comment Utility
There are exactly four left braces and exactly four right braces.  If I am missing one, then it is definitely part of a syntax that I do not understand.  

Are you not getting this error too when you paste this tutorial's code?
0
 
LVL 9

Author Comment

by:jkunrein
Comment Utility
More specifically, when I paste the code I posted originally and then add the code in the tutorial you presented, I get the attached code.  This throws an error on Line 2 before I can even look at the rest of the instructions (which aren't that clear to me as a newbie anyway; this author's writing style is not the most conducive for learning).
package

{

        

        

        import flash.display.Sprite;

        import flash.display.TextField;

        import flash.display.TextFieldAutoSize;

        

        import flash.text.TextFormat;

        import flash.text.AntiAliasType;

        

        

        

        public class EmbedFontTest extends Sprite

        {

                

                

                

                [Embed(source="C:\WINDOWS\Fonts\ARIAL.TTF", fontFamily="Arial")]

                private var _arial_str:String;

                

                private var _arial_fmt:TextFormat;

                private var _text_txt:TextField;

                

                

                

                public function EmbedFontTest()

                {

                        super();

                        

                        this.initEmbedFontTest();

                }

                

                

                

                private function initEmbedFontTest():Void

                {

                        this._arial_fmt = new TextFormat();

                        this._arial_fmt.font = "Arial";

                        this._arial_fmt.size = 40;

                                                

                        this._text_txt = new TextField();

                        this._text_txt.embedFonts = true;

                        this._text_txt.autoSize = TextFieldAutoSize.LEFT;

                        this._text_txt.defaultTextFormat = this._arial_fmt;

                        this._text_txt.text = "Test Arial Format";

                  

                        this.addChild(this._text_txt);

                }

        }

        

        

        

} 
 
 

stop();

test_txt.text = "The quick brown fox jumps over the lazy dog.";

 

var italicFormat:TextFormat = new TextFormat();

italicFormat.italic = true;

italicFormat.font = "Arial";

 

test_txt.setTextFormat(italicFormat, 4, 8);

 

//test_txt.embedFonts = true;

test_txt.antiAliasType = AntiAliasType.ADVANCED;

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:rascalpants
Comment Utility
wait, are you trying to combine framescript into an AS file below the package?

I would not do that.

that or actually it looks like you are putting a package and using this code in the IDE.  you can't do that...

a package must be in an external AS file.


rp
0
 
LVL 9

Author Comment

by:jkunrein
Comment Utility
...which is exactly what I was asking 3 days ago.  These instructions that you suggested I follow on this guy's site are not at all intuitive to someone who is not all that experienced with AS3.

So, I have copied his code and saved it to a file called embedfont.as.  I then modified my code as attached.

The text still does not show as I expected.  How am I importing this incorrectly?
import embedfont;

stop();

test_txt.text = "The quick brown fox jumps over the lazy dog.";
 

var italicFormat:TextFormat = new TextFormat();

italicFormat.italic = true;

italicFormat.font = "Arial";

test_txt.setTextFormat(italicFormat, 4, 8);

test_txt.embedFonts = true;

test_txt.antiAliasType = AntiAliasType.ADVANCED;

Open in new window

0
 
LVL 22

Expert Comment

by:rascalpants
Comment Utility
if you don't know how to swing a hammer, how can you build a house?  AS 3 is based off of a much more advance programming model like Java, so if you don't have any experience in programming these types of languages, you can't expert someone, not even an expert, to be able to walk you thru what you need to do.

and no, you only import classes... and unless you have a class called embedfont, then what you are doing is not correct.

the easiest thing for you to do is to copy the example in the tut into a text file, and name it  EmbedFontTest.as

then in your application, do this...

import EmbedFontTest;

var newEmbedFontTest:EmbedFontTest = new EmbedFontTest();



rp



0
 
LVL 9

Author Comment

by:jkunrein
Comment Utility
1. copy the example in the tut into a text file, and name it  EmbedFontTest.as
-- Created the .as file within the same folder as my .fla.

2. in your application, do this...
-- Pasted those two lines at the beginning of my code.

I did run into an error:  1046: Type was not found or was not a compile-time constant: Void.

Okay, so I assume that it's because the example has a typo, so I assumed I needed to do the following:

3. Correct case in line 36 of EmbedFontTest.as.
-- Changed "Void" to "void".

Then I ran into other errors.  Based on those errors, I assumed that I needed to do the following:

4. Correct importing the TextField.
-- Changed flash.display.TextField to flash.text.TextField.

5. Correct importing the TextFieldAutoSize.
-- Changed flash.display.TextFieldAutoSize to flash.text.TextFieldAutoSize

Unfortunately, when I run my code, the text is still not showing.  I'm not sure why these 2 steps are not working for me when they worked for you.  I did add steps 3, 4, and 5, but only after erroring out after step 2.  Since you did not need to do those steps, I'm afraid that I did step 1 or 2 incorrectly, but I'm not seeing how.  I've done it as best as I can three times, and I still got the same error.
0
 
LVL 9

Accepted Solution

by:
jkunrein earned 0 total points
Comment Utility
I have found my solution at:
http://www.adobe.com/devnet/flash/quickstart/embedding_fonts/

Defining a font in the library allows the text to show up when using embedFonts.  It's not the most intuitive route, but it does the job.
0
 
LVL 22

Expert Comment

by:rascalpants
Comment Utility
I was under the impression that you only wanted to do this with code...  

If i would have known that the library method was an option, I would have recommended that a while back...


rp
0
 
LVL 9

Author Comment

by:jkunrein
Comment Utility
Don't get me wrong; I wanted the embedFonts property to work.  I was open to code or library. I just did not know that the antiAlias property could be set through this method.  

I've only had 3 days of training in ActionScript, so I'm kludging through what I can.  The whole thing is a trial by fire for me.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to record live broadcast.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now