Solved

How to embed fonts in an AS3 project with CSS

Posted on 2010-11-17
13
801 Views
Last Modified: 2012-05-10
Hey,

I'm trying to embed a font in my AS3 project but the text keeps disappearing if I set embed-fonts to true. I'm using FlashDevelop and Flex SDK 3 to compile the application.

This is how I am defining the font in the external CSS file:

@font-face
{
    src: url( "../../resource/font/frutiger.ttf" ) ;
    fontFamily: defaultFontFamily ;
    advancedAntiAliasing: true ;
}

p
{
      font-family: defaultFontFamily ;
      font-size: 12 ;
      color: #ffffff ;
}

The styling works, but fonts won't show up. What am I missing here?
0
Comment
Question by:eCat12
[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
13 Comments
 
LVL 5

Expert Comment

by:GarrettChristopherson
ID: 34157891
Here is a tutorial on embedding fonts in Flex:

http://livedocs.adobe.com/flex/3/html/help.html?content=fonts_04.html

In the tutorial, I saw that there are some additional commands, although I haven't worked this out myself.  Hopefully the tutorial will fill in the blanks for you!
0
 

Author Comment

by:eCat12
ID: 34157907
Thanks! This seems to be exactly how I am doing it though, and it still doesn't work. Do I need to embed  the font in both CSS and AS or is CSS enough?
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34161173
Did you register the fonts in AS while using CS3.

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com 
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:eCat12
ID: 34162638
Hi,

Yes, I tried embedding the font in AS as well using the [Embed] metatag. Didn't make any difference.
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34162673
I mean Registering the fonts.

Here are the steps:
1. Add the font in library.
2. Register the fonts using this script:
var FontClass:Class = getDefinitionByName( "FontName" ) as Class;
Font.registerFont( FontClass );

And you are done.

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com 
0
 

Author Comment

by:eCat12
ID: 34162685
Thanks, but I can't use the library as this is a pure AS3 project and not a Flash one... can you think of another way of doing this?
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34162693
So you can just use an SWF which contains the fonts only, load it as a library and register the font in your code using AS3.0


Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com 
0
 

Author Comment

by:eCat12
ID: 34163082
Ok, thanks, I tried that. I now have the font in a SWC library with the linkage name Frutiger. However, I still can't get it to work. I'm trying this:

var FontClass:Class = getDefinitionByName( "Frutiger" ) as Class;
Font.registerFont( FontClass );

and I get this error:

[Fault] exception, information=ReferenceError: Error #1065: Variable Frutiger is not defined.


0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34163458
It seems you have not entered its linkage name.

In the font fla, select the font from library and open its linkage.

Then click Export for ActionScript.

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com
0
 

Author Comment

by:eCat12
ID: 34163839
I've already done that. I'm out of ideas here. :/
0
 
LVL 1

Accepted Solution

by:
PankajRai earned 500 total points
ID: 34172144
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 34824197
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

690 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