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
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
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
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.
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.