<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ninetynine.be &#187; CSS</title>
	<atom:link href="http://ninetynine.be/blog/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://ninetynine.be/blog</link>
	<description>Just another blog with no useful content on it at all.</description>
	<lastBuildDate>Sun, 08 Jan 2012 10:39:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Flex: Runtime font embedding using compiled CSS with loader</title>
		<link>http://ninetynine.be/blog/2009/04/flex-runtime-font-embedding-using-compiled-css-with-loader/</link>
		<comments>http://ninetynine.be/blog/2009/04/flex-runtime-font-embedding-using-compiled-css-with-loader/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 19:57:52 +0000</pubDate>
		<dc:creator>michiel</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://ninetynine.be/blog/?p=118</guid>
		<description><![CDATA[A missing feature in Flex is the ability to load fonts at runtime. &#8216;Why is this useful?&#8217;, you could ask. Well one situation is you&#8217;re creating an online rich text editor, and you want to add a font to the font list. You would only have to edit the css and upload the new swf [...]]]></description>
			<content:encoded><![CDATA[<p>A missing feature in Flex is the ability to load fonts at runtime. </p>
<p>&#8216;Why is this useful?&#8217;, you could ask. Well one situation is you&#8217;re creating an online rich text editor, and you want to add a font<br />
to the font list. You would only have to edit the css and upload the new swf instead of the whole application. Or you want a client<br />
to be able to add fonts without him having the source code from the application.</p>
<p><br/>Luckily it&#8217;s possible in Flex to load runtime CSS compiled as an SWF with the StyleManager class.<br />
<a href="http://livedocs.adobe.com/flex/gumbo/langref/mx/styles/StyleManager.html">StyleManager on LiveDocs</a></p>
<p>Fonts.css Example :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@font-face {</span>
    src<span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;fonts/Arial.ttf&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
    fontFamily<span style="color: #00AA00;">:</span><span style="color: #ff0000;">&quot;Arial&quot;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p><strong>How to compile the CSS to SWF?</strong><br/><br />
<span id="more-118"></span><br />
<img src="http://ninetynine.be/blog/wp-content/uploads/2009/04/compile-css-to-swf.png" alt="Flex Builder Compile CSS to SWF" title="Flex Builder Compile CSS to SWF" width="216" height="59" class="alignleft size-full wp-image-131"   style="border:1px solid #C0C0C0"/><br />
In Flex Builder you can right click any CSS inside your source and check the &#8220;compile CSS to SWF&#8221; option.<br />
<br/><br />
An alternative way to compile the CSS to SWF is using the command line :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">mxmlc Fonts.css</pre></td></tr></table></div>

<p><br/><br />
<strong>Loading the compiled stylesheet</strong></p>
<p>For the example where we just compiled the Fonts.css to Fonts.swf</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">styles</span>.<span style="color: #006600;">StyleManager</span>;
&nbsp;
StyleManager.<span style="color: #006600;">loadStyleDeclarations</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Fonts.swf&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>It&#8217;s as simple as that&#8230;  you can now start using the font.<br />
The nice thing about this is you can now load your fonts visually using an intermediate loader or animation.<br />
<br/><br />
<strong>Loading the stylesheet visually with intermediate loader</strong></p>
<p>First thing we do is create a custom titlewindow with a preloader in it to show the loading.<br />
We can catch the <strong>StyleEvent.COMPLETE</strong> with an <strong>IEventDispatcher</strong>.<br />
Right click the example for the source code.</p>
<p>
<object width="500" height="100">
<param name="movie" value="http://ninetynine.be/blog/wp-content/uploads/2009/04/fontEmbedding.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="500" height="100" src="http://ninetynine.be/blog/wp-content/uploads/2009/04/fontEmbedding.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p><br/><br />
You can use this to &#8216;preload&#8217; any stylesheet.</p>
<p>Compiling CSS to SWF and loading it runtime is also used for application with theme support.<br />
You can read more about that and view an example here : <a href="http://onflash.org/ted/2007/01/flex-201-understand-runtime-css.php">Understanding runtime CSS</a><br />
<br/></p>
<p>Happy coding!</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://ninetynine.be/blog/2009/04/flex-runtime-font-embedding-using-compiled-css-with-loader/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

