?
Solved

How can I work with embedFonts in AS3?

Posted on 2009-07-08
14
Medium Priority
?
625 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 22

Expert Comment

by:rascalpants
ID: 24805093
take a look at this tutorial...

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


rp

0
 
LVL 9

Author Comment

by:jkunrein
ID: 24822552
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
ID: 24823741
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:jkunrein
ID: 24824472
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
ID: 24824536
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
ID: 24835717
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
ID: 24835782
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
 
LVL 22

Expert Comment

by:rascalpants
ID: 24841204
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
ID: 24841977
...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
ID: 24843017
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
ID: 24843304
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
ID: 24869837
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
ID: 24869898
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
ID: 24869932
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

777 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