{"id":100,"date":"2010-05-27T21:50:09","date_gmt":"2010-05-28T01:50:09","guid":{"rendered":"http:\/\/www.joebillman.com\/blog\/?p=100"},"modified":"2010-05-27T21:50:09","modified_gmt":"2010-05-28T01:50:09","slug":"how-to-embed-fonts-using-actionscript-3","status":"publish","type":"post","link":"https:\/\/www.joebillman.com\/blog\/?p=100","title":{"rendered":"How to embed fonts using actionscript 3"},"content":{"rendered":"<p>This was causing my to bang my head for a little while. There are different ways depending on \u00a0whether you are using Flash or Flash Builder (previously Flex Builder). If you are using Flash you can go here for a good example\/tutorial: <a href=\"http:\/\/www.adobe.com\/devnet\/flash\/quickstart\/embedding_fonts\/\">http:\/\/www.adobe.com\/devnet\/flash\/quickstart\/embedding_fonts\/<\/a>. Basically you add a font to the library by clicking the pop-up menu (in the upper-right corner of the Library panel), export it for actionscript and then give it a class name. After that your code looks something like this:<\/p>\n<pre style=\"background-color: #ebebeb;\">var myFont:Font = new Font1();\nvar myFormat:TextFormat = new TextFormat();\nmyFormat.font = myFont.fontName;<\/pre>\n<p>Embedding fonts in AS3 seems to be a big problem for many people out there especially if you are using Flash Builder\/Flex Builder. I know it was driving me crazy! I was following the examples, but still seemed to keep getting the same error: &#8220;An Embed variable must not have an existing value.&#8221;. Okay maybe it&#8217;s just me but that one was a little cryptic. Finally after a long time, but before having to do a Google search for straight jackets I figured out what I was missing. In all of the examples the embed line was right above a Class variable, but mine was not, so I added one and \u00a0cha ching it worked. Here is a sample:<\/p>\n<pre style=\"background-color: #ebebeb;\">[Embed(source=\"assets\/MONACO.TTF\", fontName=\"monaco\",\nmimeType=\"application\/x-font-truetype\")]\nprivate var MonacoFontEmbed:Class;<\/pre>\n<p>It may just be me but this was not obvious I must confess. You don&#8217;t use that variable at least I didn&#8217;t, you simple set the .font property to the fontName value. It looks something like this:<\/p>\n<pre style=\"background-color: #ebebeb;\">myFormat.font = \"monaco\";<\/pre>\n<p>monaco is what I named it. You can name that whatever you want along with the variable. I named it MonacoFontEmbed, but you can name it whatever. I hoped this helped. If you have any questions feel free to post them. Embedding fonts is very useful especially if you are planning to manipulate a text field. Manipulations like rotation will just cause your text field to\u00a0disappear\u00a0if created dynamically and without embedding the font.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This was causing my to bang my head for a little while. There are different ways depending on \u00a0whether you are using Flash or Flash Builder (previously Flex Builder). If you are using Flash you can go here for a good example\/tutorial: http:\/\/www.adobe.com\/devnet\/flash\/quickstart\/embedding_fonts\/. Basically you add a font to the library by clicking the pop-up &hellip; <a href=\"https:\/\/www.joebillman.com\/blog\/?p=100\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to embed fonts using actionscript 3&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,9,10,11,26,27],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-actionscript","category-flash","category-flash-builder","category-flex","category-problem-solved","category-programming"],"_links":{"self":[{"href":"https:\/\/www.joebillman.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.joebillman.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joebillman.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joebillman.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joebillman.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100"}],"version-history":[{"count":0,"href":"https:\/\/www.joebillman.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.joebillman.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joebillman.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joebillman.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}