# Embedding Fonts problem

**URL:** <https://forum.kirupa.com/t/embedding-fonts-problem/305869>\
**Category:** Uncategorized\
**Created:** [March 4, 2010, 7:19pm UTC](https://forum.kirupa.com/t/embedding-fonts-problem/305869 "2010-03-04T19:19:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wonsong82](https://avatars.discourse-cdn.com/v4/letter/w/22d042/32.png) [@wonsong82](https://forum.kirupa.com/u/wonsong82)\
**Post date:** [March 4, 2010, 7:19pm UTC](https://forum.kirupa.com/t/embedding-fonts-problem/305869/1 "2010-03-04T19:19:27Z")

</div>

HI i am trying to make a FontEmbed Class that embeds the .ttf font that its URL is passed in as a string variable.

Embeding a font directly with strict source attribute is easy like this

```auto

Embed(source="orca.ttf", fontName="ocrAAA", mimeType="Application/x-font",unicodeRange="U+0020-U+007E")]
var OcrAStd:Class;
Font.registerFont(OcrAStd);

```

after i do this, i can access the font by using TextFormat.font=“ocrAAA”  
with TextField.embed=true

but i would like to send in the source attribute to make it dynamic.  
this way i dont have to convert every single fonts to .swf for later use.

so i simply tried

```auto

var fn:String="ocra.ttf";
Embed(source=fn, fontName="ocrAAA", mimeType="Application/x-font",unicodeRange="U+0020-U+007E")]

```

and of course did not work. it would read source as fn  
so i tried

```auto

this["fn"]="ocra.ttf";
Embed(source=this["fn"], fontName="ocrAAA", mimeType="Application/x-font",unicodeRange="U+0020-U+007E")]

```

i dont know if this is the same thing but since my lack of programming knowledge, i gave it a shot and did not work.

so my next try was to construct a string according to a variable sent in.  
and make the string to byteArray and load the byteArray in.

```auto

var str:String='Embed(source=this["ocra.ttf"], fontName="ocrAAA", mimeType="Application/x-font",unicodeRange="U+0020-U+007E")]';
var ba:ByteArray=new ByteArray();
ba.writeUTFBytes(str);
var l:Loader=new Loader();
l.loadBytes(ba);

```

this gives me an error saying that loaded file is an unknown type since its  
just a plain texts.

so my next try was to write a swf in binary and insert the binaried embeding code inside it, but later figured that this won’t work because  
after compilation, these command arent the same commands i type in as3.  
plus to write a binary code to embed a font using the .ttf file, its going to be way beyond what my knowledge permits.

so, please help me here.
