<?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>mat janson blanchet &#187; Projects</title>
	<atom:link href="http://jansensan.net/category/projects/feed" rel="self" type="application/rss+xml" />
	<link>http://jansensan.net</link>
	<description></description>
	<lastBuildDate>Tue, 10 Aug 2010 12:29:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Communication between AS3 and Max/MSP/Jitter</title>
		<link>http://jansensan.net/communication-between-as3-and-max-msp-jitter</link>
		<comments>http://jansensan.net/communication-between-as3-and-max-msp-jitter#comments</comments>
		<pubDate>Thu, 27 May 2010 21:37:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Max/MSP/Jitter]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://jansensan.net/?p=298</guid>
		<description><![CDATA[
A while back, I thought of adding a touch screen film onto my laptop's screen, so I could use Max/MSP/Jitter's incredible sound processing tools and interface more easily than keyboard and mouse in the context of an installation or a performance. It turns out that a couple of years later, screens are touchable more easily, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" title="Communication between AS3 and Max/MSP/Jitter" src="http://jansensan.net/images/blog/post0014_001.jpg" alt="Communication between AS3 and Max/MSP/Jitter" width="640" height="128" /></p>
<p>A while back, I thought of adding a touch screen film onto my laptop's screen, so I could use <a title="Max" href="http://cycling74.com/products/maxmspjitter/" target="_blank">Max/MSP/Jitter</a>'s incredible sound processing tools and interface more easily than keyboard and mouse in the context of an installation or a performance. It turns out that a couple of years later, screens are touchable more easily, although I have yet to find a tablet that will be interesting enough for me to buy and want to use with Max.</p>
<p>Nevertheless, I had fiddled around with AS3 to communicate with Max. I had planned for a while to write a post about this, but I thought it was more important to present how to start and manage a project. What I will present here is how to communicate data between the two software, and since Max is a desktop installation, I will create a pure AS3 <a title="Adobe Air" href="http://www.adobe.com/products/air/" target="_blank">Air</a> project.</p>
<p>Just to give credit where credit is due, steps to create the Air project are mostly taken from <a title="Easily Create a Pure AS3 AIR Project in Flash Builder 4" href="http://swfhead.com/blog/?p=380" target="_blank">here</a>. Let's have at it now!</p>
<p><strong>Create an Air Project</strong></p>
<p style="text-align: center;"><img class="aligncenter" title="Create an Air Project (step 1)" src="http://jansensan.net/images/blog/post0014_002.jpg" alt="Create an Air Project (step 1)" width="640" height="709" /></p>
<p>Let's first create a Flex project in Flash Builder 4. Right-click in the package explorer window, select "New &gt; Flex Project". Make sure that you check the "Desktop (runs in Adobe Air)" option in the "Application type" subsection, you do not want to make a web project.</p>
<p style="text-align: center;"><img class="aligncenter" title="Create an Air Project (step 2)" src="http://jansensan.net/images/blog/post0014_003.jpg" alt="Create an Air Project (step 2)" width="640" height="818" /></p>
<p>In the next window, leave the "Output folder" field as is and click "Next". Then, in the "Main application" field, change the .MXML extension to .AS and click "Finish."</p>
<p>As a habit, I always have a initStage() function. In Air, you need to spawn an actual window, something we never do for the web. This is the perfect place to do so.</p>
<p>ActionScript 3.0:</p>
<blockquote>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initStage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// first, spawn a window</span>
	<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">nativeWindow</span>.<span style="color: #006600;">activate</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">// then set stage params</span>
	<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span> = StageAlign.<span style="color: #006600;">TOP_LEFT</span>;
	<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">scaleMode</span> = StageScaleMode.<span style="color: #006600;">NO_SCALE</span>;
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>In order to communicate with Max, we need to create an <a title="XMLSocket - AS3 Documentation" href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/XMLSocket.html" target="_blank">XMLSocket</a>.</p>
<p>ActionScript 3.0:</p>
<blockquote>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _socket:<span style="color: #0066CC;">XMLSocket</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _host:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;127.0.0.1&quot;</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _port:uint = <span style="color: #cc66cc;">8080</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initSocket<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	_socket = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XMLSocket</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	_socket.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>IOErrorEvent.<span style="color: #006600;">IO_ERROR</span>, xmlSocketEventsHandler<span style="color: #66cc66;">&#41;</span>;
	_socket.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #0066CC;">CONNECT</span>, xmlSocketEventsHandler<span style="color: #66cc66;">&#41;</span>;
	_socket.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #0066CC;">CLOSE</span>, xmlSocketEventsHandler<span style="color: #66cc66;">&#41;</span>;
	_socket.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>DataEvent.<span style="color: #0066CC;">DATA</span>, xmlSocketDataHandler<span style="color: #66cc66;">&#41;</span>;
	_socket.<span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span>_host, _port<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> xmlSocketEventsHandler<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">&quot;--- xmlSocketEventsHandler ---&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;ioError&quot;</span>:
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>could not connect&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;connect&quot;</span>:
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>socket connected&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;close&quot;</span>:
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>socket closed&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #000000; font-weight: bold;">default</span>:
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> + event.<span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>There are a couple of things to go through here. At the top of this code block, I instantiate the XMLSocket. I also create variables for the host and the port, which are both necessary to connect the XMLSocket.</p>
<p>Then, the initSocket() function takes care of initializing the XMLSocket, also adding some listeners to it and finally connecting it. For the connection, you may want to read about your platform (whether it's Windows, Mac OS or other) to see what is the host IP and what ports can be used locally. You may also read up a bit on the Flash Player security, in case you need a cross domain XML file, although since this project is desktop-based and not going through a browser, I did not need it.</p>
<p>The xmlSocketEventsHandler() simply traces what events the XMLSocket receives.</p>
<p><strong>Create a Max patch</strong></p>
<p>Max files are called patches. It goes back to patching cords, but I won't go too deep into the Max language, you may read all about it yourself on the Internet.</p>
<p>By default, Max does not communicate with Flash, but just like AS3, there are some "libraries" that can be added to Max, they are called externals. A couple of years back, the Flashserver external was easy to obtain from the <a title="Flashserver - Olaf Matthes" href="http://www.nullmedium.de/dev/flashserver/" target="_blank">author's website</a> or from the <a title="Flashserver - Max Object Database" href="http://www.maxobjects.com/?v=objects&amp;id_objet=2487&amp;requested=FLASH&amp;operateur=AND&amp;id_plateforme=0&amp;id_format=0" target="_blank">Max Objects Database</a>, but it is sadly not the case anymore. I still have it and it is bundled with the source files for this tutorial, I hope I am not infringing anyone's copyrights by making it available again.</p>
<p>Then let's create a new patch and add the Flashserver object. This post is unfortunately not about how to use Max, thus I will not explain how to use the software here. I may in some future post, but this is way out of scope for this post.</p>
<p style="text-align: center;"><img class="aligncenter" title="Max patch" src="http://jansensan.net/images/blog/post0014_004.jpg" alt="Max patch" width="451" height="578" /></p>
<p>Simply look at the help for the Flashserver object if you need to, but quickly, after the name is the argument for what port to connect to ("8080") , and the last argument ("256") is the amount of clients or Flash applications that can connect to this Max patch.</p>
<p><strong>Talking with Max</strong></p>
<p>When Flash needs to communicate with other languages and software, the other software usually has the role of a server, therefore it needs to be opened before the Flash/Air app. Thus, make sure you open the Max patch before attempting to communicate with Flash.</p>
<p>First, let's look at receiving what Max may send to Flash. Earlier, there was one event handler that I did not define, here it is:</p>
<p>ActionScript 3.0:</p>
<blockquote>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> xmlSocketDataHandler<span style="color: #66cc66;">&#40;</span>event:DataEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p><strong><span style="font-weight: normal;">So the data is actually what Max sends to Flash. To send multiple values to Flash, you'll need to create a pack in Max and send it as a string and then parse it in Flash.</span></strong></p>
<p><strong><span style="font-weight: normal;">Let's look at the code to send data to Max:</span></strong></p>
<p>ActionScript 3.0:</p>
<blockquote>
<pre class="actionscript">_socket.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;hello max;&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre>
</blockquote>
<p><strong><span style="font-weight: normal;">It's as simple as that! Note that the data always has to end with a semicolon (";"). In the case where there are multiple values that need to be sent, separate them all with a semicolon, like so:</span></strong></p>
<p>ActionScript 3.0:</p>
<blockquote>
<pre class="actionscript">_socket.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;hello max; from flash;&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre>
</blockquote>
<p>On Max's side, simply use the unpack object to be able to parse the values into your patch.</p>
<p><strong>Source files</strong></p>
<p>As promised, <a href="http://jansensan.net/compressed/Tutorial_CommunicationWithMax.zip">here are the files</a> that I used to create this project. The Air project was created in Eclipse with the Flash Builder 4 plugin, and the Max patch with Max 5, with the Flashserver external installed.</p>
]]></content:encoded>
			<wfw:commentRss>http://jansensan.net/communication-between-as3-and-max-msp-jitter/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>adidas Originals publishes Women&#8217;s Lookbook</title>
		<link>http://jansensan.net/adidas-originals-womens-lookbook-ss10</link>
		<comments>http://jansensan.net/adidas-originals-womens-lookbook-ss10#comments</comments>
		<pubDate>Wed, 17 Mar 2010 18:19:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Commercial Works]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Localization]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://jansensan.net/?p=167</guid>
		<description><![CDATA[


After two arduous months of work—and during the hassle of me moving to Amsterdam nonetheless!—we finally managed complete the production of the adidas Originals Women's Lookbook SS10!
Lots of thought went into the architecture of that project so it would be easy to debug. I chose a homebrew MVC pattern for the structure, which worked well. [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: center;">
<div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="351" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="FlashVars" value="culture=us" /><param name="allowScriptAccess" value="always" /><param name="flashvars" value="culture=us" /><param name="src" value="http://www.adidas.com/campaigns/originals_ss10/content/microsites/womenslookbook/embed/AdidasWLB_Loader.swf" /><embed type="application/x-shockwave-flash" width="480" height="351" src="http://www.adidas.com/campaigns/originals_ss10/content/microsites/womenslookbook/embed/AdidasWLB_Loader.swf" allowscriptaccess="always" flashvars="culture=com"></embed></object></div>
</div>
<p>After two arduous months of work—and during the hassle of me moving to Amsterdam nonetheless!—<a title="Sid Lee" href="http://www.sidlee.com/" target="_blank">we</a> finally managed complete the production of the <a title="adidas Originals Women's Lookbook SS10" href="http://www.adidas.com/originals/womenslookbook" target="_blank">adidas Originals Women's Lookbook SS10</a>!</p>
<p>Lots of thought went into the architecture of that project so it would be easy to debug. I chose a homebrew <a title="MVC pattern" href="http://en.wikipedia.org/wiki/Model–view–controller" target="_blank">MVC pattern</a> for the structure, which worked well. Looking at <a title="My colleague, Antti Kupila" href="http://www.anttikupila.com/" target="_blank">my colleague</a> working with <a title="Robot Legs" href="http://www.robotlegs.org/" target="_blank">RobotLegs</a>, I believe this is what I'll look into next.</p>
<p>The localization worked like a charm with the <a title="Of localization and locale mapping" href="http://jansensan.net/locale-mapping" target="_blank">locale mapping logic I wrote about before</a>. The only issue I found is that since there were no specific fonts for non latin languages, there had to be a check to see what alphabet was used, to  make sure that the fonts were not embedded if said alphabet was non latin.</p>
<p>The video had to stream in this case since we needed to jump at any moment in time in the video. Also, we faced an inconvenience when <a title="BitmapData.draw() AS3 Documentation" href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/BitmapData.html#draw()" target="_blank">trying to get a bitmap from a streaming video</a>, the <a title="Fixing BitmapData.draw() Security Sandbox Violation" href="http://www.thebluepipe.com/Developer/tutorials/as3/Crossdomain-Video-Snapshot-Fixing-BitmapData-draw-Security-Sandbox-Violation.html" target="_blank">solutions were on the server side</a>.</p>
<p>Integrating the whole project into an existing parent SWF was also a challenge, since the class definitions would be kept in the appdom memory and causing issues when loading the site a second time. The solution to this was to apply an application domain when loading the microsite (<a title="Being a Successful Development Team in Flash with Application Domains" href="http://codeendeavor.com/archives/468" target="_blank">link 1</a>, <a title="Application Domain and External SWF Loading" href="http://annafilina.com/blog/application-domain-and-external-swf-loading/" target="_blank">link 2</a>).</p>
<p>As I was looking for solutions, I found that <a title="maashaack - ActionScript 3 framework, tools, libraries and utilities" href="http://code.google.com/p/maashaack/wiki/Main" target="_blank">wiki</a> that is discussing about things like thinking in AS3, metadata, singletons, application domains and all sorts of interesting subjects.</p>
<p>All in all, that project was a good challenge, one I had been looking forward to for a while now.</p>
<p>The embeddable version seen in this post actually has been produced by <a title="Département" href="http://www.departement.ca/" target="_blank">Département</a> in Montréal.</p>
]]></content:encoded>
			<wfw:commentRss>http://jansensan.net/adidas-originals-womens-lookbook-ss10/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Of localization and locale mapping</title>
		<link>http://jansensan.net/locale-mapping</link>
		<comments>http://jansensan.net/locale-mapping#comments</comments>
		<pubDate>Sun, 21 Feb 2010 20:06:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Localization]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://jansensan.net/?p=132</guid>
		<description><![CDATA[When creating web content for international clients, it is more than likely that you will have to think of localized versions of your website. This mostly means that the copy has to be translated into multiple languages.
In this post I will try to present what I believe is a simple way to deal with localization [...]]]></description>
			<content:encoded><![CDATA[<p>When creating web content for international clients, it is more than likely that you will have to think of localized versions of your website. This mostly means that the copy has to be translated into multiple languages.</p>
<p>In this post I will try to present what I believe is a simple way to deal with localization and minimize file copying etc.</p>
<p>I learned of localization when I was working at an e-commerce production shop previously. That company had most of its clients in Canada and in the US, meaning that we only had to deal with a minimal amount of localization, namely "en-US", "en-CA" and "fr-CA".</p>
<p>If you have no idea what those codes are about, the first two letters represent the language (following the <a title="ISO 639-2" href="http://en.wikipedia.org/wiki/ISO_639-2" target="_blank">ISO 639-2</a> codes) and the las two letters represent the country (following the <a title="ISO 3166-1" href="http://en.wikipedia.org/wiki/ISO_3166-1" target="_blank">ISO 3166-1</a> codes).</p>
<p>Recently I had to complete projects for an employee that left the company I currently work for. I had actually never dealt with localization in Europe and obviously, that means a lot more languages. I also discovered that some countries reuse copy. For example, the swedish and greek localization of one of our client's site reuse the english copy. The way the project was set up at that moment was to have one directory per country, meaning that we had to remember to duplicate the english copy into all the directories that used that language as well.</p>
<p>A recipe for disasters.</p>
<p>Here is where the idea of mapping becomes useful. In the site's config file, I simply thought of adding a node that would contain the locale mapping, meaning what country is associated to what language etc.</p>
<p>XML:</p>
<blockquote>
<pre class="actionscript">&lt;localeMapping&gt;
     &lt;locale country=<span style="color: #ff0000;">&quot;ca&quot;</span> <span style="color: #0066CC;">language</span>=<span style="color: #ff0000;">&quot;en&quot;</span> alphabet=<span style="color: #ff0000;">&quot;latin&quot;</span> /&gt;
     &lt;locale country=<span style="color: #ff0000;">&quot;cf&quot;</span> <span style="color: #0066CC;">language</span>=<span style="color: #ff0000;">&quot;fr&quot;</span> alphabet=<span style="color: #ff0000;">&quot;latin&quot;</span> /&gt;
     &lt;locale country=<span style="color: #ff0000;">&quot;fr&quot;</span> <span style="color: #0066CC;">language</span>=<span style="color: #ff0000;">&quot;fr&quot;</span> alphabet=<span style="color: #ff0000;">&quot;latin&quot;</span> /&gt;
     &lt;locale country=<span style="color: #ff0000;">&quot;jp&quot;</span> <span style="color: #0066CC;">language</span>=<span style="color: #ff0000;">&quot;ja&quot;</span> alphabet=<span style="color: #ff0000;">&quot;japanese&quot;</span> /&gt;
     &lt;locale country=<span style="color: #ff0000;">&quot;kr&quot;</span> <span style="color: #0066CC;">language</span>=<span style="color: #ff0000;">&quot;ko&quot;</span> alphabet=<span style="color: #ff0000;">&quot;korean&quot;</span> /&gt;
     &lt;locale country=<span style="color: #ff0000;">&quot;se&quot;</span> <span style="color: #0066CC;">language</span>=<span style="color: #ff0000;">&quot;en&quot;</span> alphabet=<span style="color: #ff0000;">&quot;latin&quot;</span> /&gt;
     &lt;locale country=<span style="color: #ff0000;">&quot;uk&quot;</span> <span style="color: #0066CC;">language</span>=<span style="color: #ff0000;">&quot;en&quot;</span> alphabet=<span style="color: #ff0000;">&quot;latin&quot;</span> /&gt;
     &lt;locale country=<span style="color: #ff0000;">&quot;us&quot;</span> <span style="color: #0066CC;">language</span>=<span style="color: #ff0000;">&quot;en&quot;</span> alphabet=<span style="color: #ff0000;">&quot;latin&quot;</span> /&gt;
&lt;/localeMapping&gt;</pre>
</blockquote>
<p>The alphabet tag is not relative to any specific standard, but just actually the logic part of what I use to load the fonts and the CSS (see <a title="Loading assets dynamically (part 4: fonts and CSS)" href="http://jansensan.net/loading-assets-dynamically-part-4" target="_self">previous post</a>).</p>
<p>So far as the logic goes, once the config file is loaded it is easy to associate a country with a language and load the related files. If a user comes to a website and there a script that detects France, it is then possible to know what to load: the french copy, the latin font set and the latin CSS. Same goes for any country.</p>
<p><a title="Antti Kupila" href="http://www.anttikupila.com/" target="_blank">Antti Kupila</a>, a colleague of mine, believes that it is kind of cheating to reload a a whole website to change the locale. I agreed when he explained how to realize this.</p>
<p>Whenever a TextField is added in the application, it is registered and a reference to it is kept in memory somewhere. When the user changes the locale, there is no need to reload all assets, just the necessary copy, the font set and the CSS (or TextFormat, depending). Once all is loaded, update the TextFields.</p>
<p>Here you go Internets, another way to organize and simplify your life.</p>
]]></content:encoded>
			<wfw:commentRss>http://jansensan.net/locale-mapping/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Loading assets dynamically (part 4: fonts and CSS)</title>
		<link>http://jansensan.net/loading-assets-dynamically-part-4</link>
		<comments>http://jansensan.net/loading-assets-dynamically-part-4#comments</comments>
		<pubDate>Thu, 28 Jan 2010 16:32:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://jansensan.net/?p=110</guid>
		<description><![CDATA[One of the great promises of Flash, back when it was introduced, was that finally designers would not have to worry anymore about the limitation of web fonts. But Flash developers all around had to find different way to use and implement the designers’ choice efficiently.
Lots of websites done with static content or localized only [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great promises of Flash, back when it was introduced, was that finally designers would not have to worry anymore about the limitation of <a href="http://en.wikipedia.org/wiki/Web_typography" target="_blank">web fonts</a>. But Flash developers all around had to find different way to use and implement the designers’ choice efficiently.</p>
<p>Lots of websites done with static content or localized only in one language did not need to worry much about fonts, however as Flash grew in popularity and demand, projects became more complex and required text to be dynamic and localized. That’s when the party started.</p>
<p>What is presented here is a workflow that I have been using with my team for quite some time, and it has proven efficient. I do not dare to say it is the best, especially since dealing with fonts in Flash is such a pain that many people have probably lots of different ways to import and use fonts properly.</p>
<p><strong>Creating a SWF Font File</strong></p>
<p>The idea is to create a SWF file that contains the fonts necessary to the website and pair it with whatever little <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/text/StyleSheet.html" target="_blank">CSS ActionScript can handle</a>. Lee Brimelow has a great <a href="http://www.gotoandlearn.com/play?id=102" target="_blank">video tutorial</a> on how to create such a SWF. Dominic Gelineau from <a href="http://www.zedia.net/" target="_blank">Zedia Flash Blog</a> also <a href="http://www.zedia.net/2010/fonts-are-my-bane-not-anymore/" target="_blank">posted something quite similar</a> to what I explain here, he just posted before me, while my text was still a draft.</p>
<p>When I was working on a project for a client that needed all sorts of different languages (Chinese,  Japanese, Russian, English, French, etc.), I made different SWF files and named them according to the alphabet they contained:</p>
<ul>
<li>chineseFonts.swf</li>
<li>cyrillicFonts.swf</li>
<li>japaneseFonts.swf</li>
<li>latinFonts.swf</li>
</ul>
<p>Using the unicodeRange parameter is quite interesting, especially for Chinese characters, so you can considerably reduce the size of your embedded font.</p>
<p>I noticed recently with the update to Flash Builder 4 beta 2 that the embedAsCFF parameter was now set to true by default. This is quite annoying, because unless you use the new Flash Player 10 <a href="http://labs.adobe.com/technologies/textlayout/" target="_blank">Text Layout Framework</a>, <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/text/FontType.html#EMBEDDED_CFF" target="_blank">text will not render on screen</a>. I now always set the embedAsCFF as false.</p>
<p>In your project, load the SWF file that contains the font just like I explained <a href="http://jansensan.net/loading-assets-dynamically-part-2" target="_self">how to load SWF files whose library contain classes that are meant to be exported for ActionScript</a>. Here as well, the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/system/LoaderContext.html" target="_blank">LoaderContext</a>'s application domain parameter must be set to <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/system/ApplicationDomain.html#currentDomain" target="_blank">ApplicationDomain.currentDomain</a> so that the loaded fonts are available to the whole application.</p>
<p>It may be useful to test if the fonts are indeed embedded once the file has loaded. Here is a little function that will trace all embedded fonts in your app:</p>
<p>ActionScript:</p>
<blockquote>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> traceEmbeddedFonts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">&quot;--- traceEmbeddedFonts ---&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> embeddedFonts:<span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">Font</span>.<span style="color: #006600;">enumerateFonts</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">font</span>:<span style="color: #0066CC;">Font</span>
	<span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> numLoops:<span style="color: #0066CC;">int</span> = embeddedFonts.<span style="color: #0066CC;">length</span>;
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span>i; i &amp;lt; numLoops; i++<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">font</span> = embeddedFonts<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;[&quot;</span> + i + <span style="color: #ff0000;">&quot;]<span style="color: #000099; font-weight: bold;">\n</span>fontName:&quot;</span> + <span style="color: #0066CC;">font</span>.<span style="color: #006600;">fontName</span> + <span style="color: #ff0000;">&quot;,<span style="color: #000099; font-weight: bold;">\n</span>style: &quot;</span> + <span style="color: #0066CC;">font</span>.<span style="color: #006600;">fontStyle</span> + <span style="color: #ff0000;">&quot;,<span style="color: #000099; font-weight: bold;">\n</span>type: &quot;</span> + <span style="color: #0066CC;">font</span>.<span style="color: #006600;">fontType</span> + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>I strongly suggest that developpers always include the font files they use in their assets directory, for it is a great pain to discover that the version of the font used for developement differs than the one we may actually have in hand. Font may have different kerning and leading from version to version, which sometimes leads to completely redoing the design. Keep that in mind people.</p>
<p><strong>Using CSS</strong></p>
<p>Now that we know we have our needed font loaded into our application, let's look at the CSS part of it. Here as well, I named the CSS files according to alphabet, since not all fonts were laid out the same.</p>
<ul>
<li>chineseFonts.css</li>
<li>cyrillicFonts.css</li>
<li>japaneseFonts.css</li>
<li>latinFonts.css</li>
</ul>
<p>In the CSS, I made sure that the font tag would use the font name I gave my font in the SWF file created earlier.</p>
<p>CSS:</p>
<blockquote>
<pre class="css"><span style="color: #6666ff;">.someCSSClass</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span>:<span style="color: #ff0000;">&quot;CustomFontName&quot;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>Once the CSS is loaded into my application, I <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/text/StyleSheet.html#parseCSS()" target="_blank">convert it to a StyleSheet</a>. Then, I can use it like this:</p>
<p>ActionScript:</p>
<blockquote>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> styleSheet:StyleSheet = <span style="color: #000000; font-weight: bold;">new</span> StyleSheet<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
styleSheet.<span style="color: #0066CC;">parseCSS</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>the-loaded-CSS-goes-here<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> t:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
t.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">320</span>;
t.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">240</span>;
t.<span style="color: #0066CC;">embedFonts</span> = <span style="color: #000000; font-weight: bold;">true</span>;
t.<span style="color: #006600;">styleSheet</span> = styleSheet;
t.<span style="color: #0066CC;">htmlText</span> = <span style="color: #ff0000;">&quot;&amp;lt;span class='someCSSClass'&amp;gt;&lt;span class=&quot;</span>customCSSClass<span style="color: #ff0000;">&quot;&gt;Some text goes here&amp;lt;/span&amp;gt;&lt;/span&gt;&quot;</span>;</pre>
</blockquote>
<p>I believe in using CSS rather than AS3's native <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/text/TextFormat.html" target="_blank">TextFormat</a> for it is possible to change the text layout without having to recompile the application every time. Do make sure to check what tags are actually supported as it is quite limited.</p>
<p><strong>Pixel Fonts</strong></p>
<p>I recently created a game in which I wanted to make sure I could use pixels, which</p>
<p>meant I needed a pixel font. After looking googling and reading many blogs and tutorials, it became clear that Lee’s technique would not be useful this time, since there was no way to choose bitmap when embedding the font.</p>
<p>Instead, I found a workaround that did just the trick. In the Flash IDE, I created a symbol, which I named BitmapTextFieldAsset and gave it the exact same class name. In that symbol, I created a textfield into which I embedded the whole bitmap font like we did back when sites could be static. I then created a class that would be the one I used as a textfield whenever I needed the bitmap font in the game, and voilà! A dynamic custom textfield class that would use a Bitmap font. CSS does work as well in this case.</p>
<p><strong>Conclusion</strong></p>
<p>It would be presomptuous from me so say I covered all there is to say about fonts and CSS in Flash, but I do believe that in a nutshell, this workflow is efficient.</p>
<p>What say you?</p>
]]></content:encoded>
			<wfw:commentRss>http://jansensan.net/loading-assets-dynamically-part-4/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Loading assets dynamically (part 3: images)</title>
		<link>http://jansensan.net/loading-assets-dynamically-part-3</link>
		<comments>http://jansensan.net/loading-assets-dynamically-part-3#comments</comments>
		<pubDate>Sat, 10 Oct 2009 17:26:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://jansensan.net/?p=91</guid>
		<description><![CDATA[In many projects, you will be faced with the necessity to load images dynamically. Oftentimes I have been requested to use a loaded image as a background for a website that took the full viewport area. What you need in such a case is to know that you have to resize your image proportionnally, and [...]]]></description>
			<content:encoded><![CDATA[<p>In many projects, you will be faced with the necessity to load images dynamically. Oftentimes I have been requested to use a loaded image as a background for a website that took the full viewport area. What you need in such a case is to know that you have to resize your image proportionnally, and even though that seems obvious and simple, people often ask me how to deal with that. I provide the sources for this tutorial at the end of the post. Read more after the jump.</p>
<p>The first part is obviously loading your image. Create our loader and add listeners to it.</p>
<p>ActionScript:</p>
<blockquote>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _loader:Loader;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadImage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> urlRequest:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	urlRequest.<span style="color: #0066CC;">url</span> = <span style="color: #ff0000;">&quot;image.jpg&quot;</span>;
&nbsp;
	_loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	_loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ProgressEvent.<span style="color: #006600;">PROGRESS</span>, loaderProgressHandler, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
	_loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, loaderCompleteHandler, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
	_loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>urlRequest<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>The loaderProgressHandler will serve to display the percentage of the load of your image. Here I will simply show how to trace the percentage. This is where you can get creative with what you do with said percentage.</p>
<p>ActionScript:</p>
<blockquote>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loaderProgressHandler<span style="color: #66cc66;">&#40;</span>event:ProgressEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> ratio:<span style="color: #0066CC;">Number</span> = event.<span style="color: #0066CC;">bytesLoaded</span> / event.<span style="color: #0066CC;">bytesTotal</span>; <span style="color: #808080; font-style: italic;">// this division will give us a ratio out of one</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">loaded</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;Loaded: &quot;</span> + <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span>ratio * <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;%&quot;</span>; <span style="color: #808080; font-style: italic;">// we cast the number to an int (integer) so its floating points get truncated</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">loaded</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>Next up is handling the loaded image. Prior to eveything, in the variables declarations, create a placeholder for the image to be added onto. It has to be done outside of the function so that said holder may be available throughout the class.</p>
<p>ActionScript:</p>
<blockquote>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _imageHolder:Sprite;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loaderCompleteHandler<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// always remember to remove your listeners when you are done with them</span>
	_loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>ProgressEvent.<span style="color: #006600;">PROGRESS</span>, loaderProgressHandler<span style="color: #66cc66;">&#41;</span>;
	_loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, loaderCompleteHandler<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// handle the content of the loader</span>
	<span style="color: #808080; font-style: italic;">// pass the data to a bitmap object</span>
	<span style="color: #000000; font-weight: bold;">var</span> bitmap:Bitmap = Bitmap<span style="color: #66cc66;">&#40;</span>_loader.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// make sure you add smoothing to the bitmap, so the resizing is not pixelated</span>
	bitmap.<span style="color: #0066CC;">smoothing</span> = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// add the bitmap to the display list</span>
	_imageHolder = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	_imageHolder.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>bitmap<span style="color: #66cc66;">&#41;</span>;
	addChild<span style="color: #66cc66;">&#40;</span>_imageHolder<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>To handle the resizing of the image, listen to the resize event from the stage. However, that is not sufficient, you need to make sure that your stage is aligned in the top left to make sure that it is locked in place.</p>
<p>ActionScript:</p>
<blockquote>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initStage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span> = StageAlign.<span style="color: #006600;">TOP_LEFT</span>;
	<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">scaleMode</span> = StageScaleMode.<span style="color: #006600;">NO_SCALE</span>;
	<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">RESIZE</span>, stageResizeHandler, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> stageResizeHandler<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// calls this function everytime the stage is resized</span>
	<span style="color: #808080; font-style: italic;">// in this case, the browser window</span>
	resize<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>In the following example, the image is resized to always view the whole image. I also usually create _width and _height variables, if i ever need those values called at other moments than when the stage is resized.</p>
<p>ActionScript:</p>
<blockquote>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_width</span>:<span style="color: #0066CC;">int</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_height</span>:<span style="color: #0066CC;">int</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> resize<span style="color: #66cc66;">&#40;</span>newWidth:<span style="color: #0066CC;">int</span>, newHeight:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">_width</span> = newWidth;
	<span style="color: #0066CC;">_height</span> = newHeight;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_imageLoaded<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// assign a new width to the image</span>
		_imageHolder.<span style="color: #0066CC;">width</span> = <span style="color: #0066CC;">_width</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// give the height the same scale as the width, so the image is proportionnal</span>
		_imageHolder.<span style="color: #006600;">scaleY</span> = _imageHolder.<span style="color: #006600;">scaleX</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// if the image is too high, rely on the height</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_imageHolder.<span style="color: #0066CC;">height</span> &amp;gt; <span style="color: #0066CC;">_height</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// assign a new height to the image</span>
			_imageHolder.<span style="color: #0066CC;">height</span> = <span style="color: #0066CC;">_height</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// dont forget to give the width the same scale as the new height, so the image stays proportionnal</span>
			_imageHolder.<span style="color: #006600;">scaleX</span> = _imageHolder.<span style="color: #006600;">scaleY</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// center the image</span>
		_imageHolder.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> * <span style="color: #cc66cc;">0.5</span> - _imageHolder.<span style="color: #0066CC;">width</span> * <span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">&#41;</span>;
		_imageHolder.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> * <span style="color: #cc66cc;">0.5</span> - _imageHolder.<span style="color: #0066CC;">height</span> * <span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>You may need to cover the whole background rather than see the whole image. In that case, let's take the resize functionality and put it into different functions, so we may test their different uses.</p>
<p>ActionScript:</p>
<blockquote>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> resize<span style="color: #66cc66;">&#40;</span>newWidth:<span style="color: #0066CC;">int</span>, newHeight:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">_width</span> = newWidth;
	<span style="color: #0066CC;">_height</span> = newHeight;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_imageLoaded<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//resizeImageToViewAllOfIt();</span>
	resizeImageToFillBackground<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// center the image</span>
	_imageHolder.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> * <span style="color: #cc66cc;">0.5</span> - _imageHolder.<span style="color: #0066CC;">width</span> * <span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">&#41;</span>;
	_imageHolder.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> * <span style="color: #cc66cc;">0.5</span> - _imageHolder.<span style="color: #0066CC;">height</span> * <span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> resizeImageToViewAllOfIt<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// assign a new width to the image</span>
	_imageHolder.<span style="color: #0066CC;">width</span> = <span style="color: #0066CC;">_width</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// give the height the same scale as the width, so the image is proportionnal</span>
	_imageHolder.<span style="color: #006600;">scaleY</span> = _imageHolder.<span style="color: #006600;">scaleX</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// if the image is too high, rely on the height</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_imageHolder.<span style="color: #0066CC;">height</span> &amp;gt; <span style="color: #0066CC;">_height</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// assign a new height to the image</span>
		_imageHolder.<span style="color: #0066CC;">height</span> = <span style="color: #0066CC;">_height</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// dont forget to give the width the same scale as the new height, so the image stays proportionnal</span>
		_imageHolder.<span style="color: #006600;">scaleX</span> = _imageHolder.<span style="color: #006600;">scaleY</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> resizeImageToFillBackground<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// assign a new width to the image</span>
	_imageHolder.<span style="color: #0066CC;">width</span> = <span style="color: #0066CC;">_width</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// give the height the same scale as the width, so the image is proportionnal</span>
	_imageHolder.<span style="color: #006600;">scaleY</span> = _imageHolder.<span style="color: #006600;">scaleX</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// if the image does not cover the whole height, change the scale</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_imageHolder.<span style="color: #0066CC;">height</span> &amp;lt; <span style="color: #0066CC;">_height</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// assign a new height to the image</span>
		_imageHolder.<span style="color: #0066CC;">height</span> = <span style="color: #0066CC;">_height</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// dont forget to give the width the same scale as the new height, so the image stays proportionnal</span>
		_imageHolder.<span style="color: #006600;">scaleX</span> = _imageHolder.<span style="color: #006600;">scaleY</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>Notice the subtlety: when you need to see the whole image, you check if the image height is higher than the available height to make sure it does not exceed it, while when you want to cover the whole background with your image, you check if the height is lower than the available height so that there is no moment when one side of the image is too small.</p>
<p>I hope this helps, here are <a href="http://jansensan.net/compressed/Tutorial_LoadingAssetsDynamicallyPart3.zip">the sources for this tutorial</a>. Simply comment either resizeImageToViewAllOfIt() or resizeImageToFillBackground() to test the different behaviors.</p>
]]></content:encoded>
			<wfw:commentRss>http://jansensan.net/loading-assets-dynamically-part-3/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Loading assets dynamically (part 2: using SWCs)</title>
		<link>http://jansensan.net/loading-assets-dynamically-part-2</link>
		<comments>http://jansensan.net/loading-assets-dynamically-part-2#comments</comments>
		<pubDate>Sat, 26 Sep 2009 03:09:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://jansensan.net/?p=34</guid>
		<description><![CDATA[In the last post, I thought I would be able to start explaining a bit, but I got lost in my ramblings about the different ways to use assets into an ActionScript project. This time, I will get my hands dirty playing with code–and show you step by step how to get yours dirty as [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://jansensan.net/loading-assets-dynamically-part-1" target="_self">last post</a>, I thought I would be able to start explaining a bit, but I got lost in my ramblings about the different ways to use assets into an ActionScript project. This time, I will get my hands dirty playing with code–and show you step by step how to get yours dirty as well. We will see how to use third party SWCs, how to create our own SWCs from the Flash IDE and how to load them efficiently. This tutorial requires you to have access to either Flash Builder, Flex Builder or a <a href="http://jansensan.net/my-setup" target="_self">setup similar to mine</a> with Eclipse and to Adobe Flash. I provide the sources for this tutorial at the end of the post.</p>
<p><img class="alignleft" style="border: 1px solid #d5d5d5; margin-right: 16px;" src="http://jansensan.net/images/blog/post0004_folder_structure.gif" alt="Typical ActionScript project folder structure" width="262" height="364" />Let's start by <a href="http://livedocs.adobe.com/flex/gumbo/html/WS6f97d7caa66ef6eb1e63e3d11b6c4d0d21-7ffb.html#WS6f97d7caa66ef6eb1e63e3d11b6c4ce749-7ff0" target="_blank">creating an ActionScript project</a>. The image on the left is a screenshot of how I usually create my folder structure inside an ActionScript project.</p>
<p><strong>Importing an SWC into an ActionScript project</strong></p>
<p>The easiest thing we can start with is importing an SWC from a third party into our project. We can either use <a href="http://code.google.com/p/papervision3d/" target="_blank">Papervision</a> or <a href="http://www.fisixengine.com/downloads.asp" target="_blank">FisixEngine</a>, as <a href="../loading-assets-dynamically-part-1" target="_blank">I stated before</a>. Once you downloaded the sources, locate the SWC file and copy it into the "swc" directory, either with Finder if you are on Mac, or with Windows Explorer if you use Windows.</p>
<p>Once the file is placed, go back to Eclipse (or Flash/Flex Builder) and refresh your entire project so that the added file may be taken into account. You may right-click onto the folder and select "Refresh", or simply click on the folder and hit F5 on your keyboard.</p>
<p>On a side note, it is actually a good habit to take to always refresh your project folder when you go back to your IDE after adding files into said project. It will save you some headaches.</p>
<p>Right-click on the project folder and go to "Properties", and then select the "ActionScript Build Path" tab on the left. At the right of that window, click on the button "Add SWC..." and browse to the SWC you just added into your project.</p>
<p style="text-align: center;"><img class="aligncenter" style="border: 1px solid #d5d5d5;" src="http://jansensan.net/images/blog/post0004_merged_into_code.gif" alt="SWC merged into code" width="550" height="722" /></p>
<p>The link type is set to "Merged into code" by default. What this means is that the SWC is added to your code at compile time, adding some size to your project. In the case of third party code libraries, you cannot modify this since they do not provide an SWF to load at runtime (more on this below).</p>
<p><img class="alignright" style="border: 1px solid #d5d5d5; margin-left: 16px;" src="http://jansensan.net/images/blog/post0004_referenced_libraries.gif" alt="Referenced Libraries" width="288" height="308" />Now all the classes from that are included into that SWC are available to you in your code, and you can get code complete as well. Also, another folder has been added to your project folder, "Referenced Libraries". If you expand this icon, you will see the libraries you imported and all their API.</p>
<p><strong>Creating an SWC from Flash and loading it dynamically</strong></p>
<p>As you can see from the first screenshot in this post, I made a distinction between embedded assets and authoring assets.</p>
<p>What I mean by that is that the embedded assets are visual assets created in Flash, exported as an SWC and merged into the code (as seen in the previous point). The authoring assets are planned to be loaded at runtime, to ligthen the size of my final SWF. Let's see how this goes.</p>
<p>In the embedded assets, I usually just have the preloader, since this is something we always need. In the Flash library, check the properties of the preloader MovieClip. Make sure to check the "Export for ActionScript" box. Also, give it the "Preloader" class name. No association to any .AS file, a simple class. Flash will alert that no class is associated and that it will create one on its own, which is all good.</p>
<p>What this means is that the Preloader class is available to you in code complete in your IDE since you will be able to see it in the Referenced Libraries.</p>
<p>Referenced Libraries:</p>
<p><img style="border: 1px solid #d5d5d5;" title="Referenced Librairies - Assets merged into code" src="http://jansensan.net/images/blog/post0004_embedded_assets.gif" alt="" width="232" height="96" /></p>
<p>Since this class you created extends MovieClip, the said class inherits of all the functions and variables. If you were to nest MovieClips into the one created and give them name, they will appear in the autocomplete as well. Quite useful, let me tell you!</p>
<p>ActionScript:</p>
<blockquote>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> preloader:Preloader = <span style="color: #000000; font-weight: bold;">new</span> Preloader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span>preloader<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;preloader.fillMC.width: &quot;</span> + preloader.<span style="color: #006600;">fillMC</span>.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span>;</pre>
</blockquote>
<p>That's all fine and dandy, but it's just a repeat of the previous point. What we need is actually to take some weight off of the filesize, load the assets dynamically and still be able to work as we did so far. Let's first create MovieClips in the authoringAssets.fla with classes names and then export the SWF and the SWC. Then, once you imported the SWC, change the link type to "External". Simply double click on the "Link type" and change it from the combo box.</p>
<p style="text-align: center;"><img class="aligncenter" style="border: 1px solid #d5d5d5;" title="External assets" src="http://jansensan.net/images/blog/post0004_external.gif" alt="" width="550" height="722" /></p>
<p>Referenced librairies:</p>
<p><img class="alignnone" style="border: 1px solid #d5d5d5;" title="Referenced Libraries - External assets" src="http://jansensan.net/images/blog/post0004_referenced_libraries_external.gif" alt="" width="224" height="74" /></p>
<p>However in this case it is important that you do not create an instance of these classes before the external assets are loaded, otherwise you would get an error during the compilation.</p>
<p>ActionScript:</p>
<blockquote>
<pre class="actionscript">package
<span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Loader</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite
<span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _loader:Loader;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
_loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
_loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, loaderCompleteHandler<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> loaderContext:LoaderContext = <span style="color: #000000; font-weight: bold;">new</span> LoaderContext<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span>, ApplicationDomain.<span style="color: #006600;">currentDomain</span><span style="color: #66cc66;">&#41;</span>;
_loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;../assets/swf/authoringAssets.swf&quot;</span><span style="color: #66cc66;">&#41;</span>, loaderContext<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loaderCompleteHandler<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #000000; font-weight: bold;">var</span> whiteSquare:WhiteSquare = <span style="color: #000000; font-weight: bold;">new</span> WhiteSquare<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> blackSquare:BlackSquare = <span style="color: #000000; font-weight: bold;">new</span> BlackSquare<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
blackSquare.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">32</span>;
addChild<span style="color: #66cc66;">&#40;</span>whiteSquare<span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span>blackSquare<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre>
</blockquote>
<p>The LoaderContext is essential here. What this does is to make sure that once the SWF is loaded, its contents, namely the classes you put in it, are available everywhere in the application. Once the SWF is loaded, then you can create as many instances as you need. If you end up having tons of classes and a huge assets file, at least it's easy to use a preloader to deal with them.</p>
<p>Here are <a href="http://jansensan.net/compressed/Tutorial_LoadingAssetsDynamicallyPart2.zip">the sources for this tutorial</a>. Thanks to <a href="http://www.presstube.com/" target="_blank">James Paterson</a> for showing me this useful technique!</p>
]]></content:encoded>
			<wfw:commentRss>http://jansensan.net/loading-assets-dynamically-part-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading assets dynamically (part 1: a primer)</title>
		<link>http://jansensan.net/loading-assets-dynamically-part-1</link>
		<comments>http://jansensan.net/loading-assets-dynamically-part-1#comments</comments>
		<pubDate>Thu, 24 Sep 2009 00:15:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://jansensan.net/?p=22</guid>
		<description><![CDATA[Over the years, we have seen multiple ways to import our visuals and sounds into our projects. Some of these ways would have our assets included into the SWF, which meant the published file could end up quite big. Some other ways would have us load everything dynamically, which could be practical for some assets, [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years, we have seen multiple ways to import our visuals and sounds into our projects. Some of these ways would have our assets included into the SWF, which meant the published file could end up quite big. Some other ways would have us load everything dynamically, which could be practical for some assets, but not necessarily flexible enough for all situations. Through all these options, how can we have our assets related to our ActionScript classes? Let's see and compare what is feasible and what is ideal.</p>
<p>When I first got into Flash in 1999-2000, I only knew one way to import my assets into Flash: File &gt; Import &gt; Import to Stage/Import to Library. It's actually quite practical, since you can place your elements as you would in Photoshop or Illustrator and create all sorts of MovieClips easily. And it's actually still the best way to create banners and quick projects.</p>
<p>In order to call the <a href="http://help.adobe.com/ru_RU/AS2LCR/Flash_10.0/help.html?content=00001283.html#368157" target="_blank">attachMovieClip</a> function (remember this was with AS2), an identifier name was given when the "Export for ActionScript" box was checked. After a while, I learned that I could relate ActionScript classes to that specific MovieClip in the library, so I would end up also a class name like com.clientname.ui.SomeClass, a habit I kept until recently, even in AS3.</p>
<p>This presented some inconvenients, mainly beefing up the size of the file. Also, creating variable names in the class that had the same names as in the MovieClip associated to the said class would cause some namespace issues in AS3.</p>
<p>With Flex Builder, now Flash Builder, you can embed image files in your code and make them act as classes (<a href="http://www.bit-101.com/blog/?p=853" target="_blank">example 1</a>, <a href="http://actionscriptexamples.com/2008/10/26/embedding-images-into-a-flash-document-using-the-embed-metadata/" target="_blank">example 2</a>). Quite useful, but again, it just makes your file size bigger. Having a preloader that would stop the timeline until all is loaded, or having two separate SWFs with one that loads the other, both those two options seemed a bit unclean and inefficient, especially if you eventually want to hand the project to someone else.</p>
<p>There is also the option of loading everything at runtime. And I mean everything, all images, sounds, etc. It's a step towards making the file lighter, but sometimes you do need to edit your assets à la Photoshop, have multiple MovieClips, and basically using the Flash IDE at this point would help. Sure you could recreate everything in code, place all your elements, TextFields, MovieClips and the likes in code, but sometimes you may want to use components too, and I've faced moments where I could create components dynamically. And doing all that just in code is time consuming, and let's face it, this industry is based on efficiency and speed of delivery.</p>
<p>Enter <a href="http://livedocs.adobe.com/flex/gumbo/html/WS2db454920e96a9e51e63e3d11c0bf69084-7fd3.html">SWC</a> files. These files are either a compiled library of code–just like <a href="http://code.google.com/p/papervision3d/">Papervision</a> or <a href="http://www.fisixengine.com/" target="_blank">Fisix Engine</a> do–or a compiled FLA file that includes a library of assets built in the Flash IDE. There are different ways to use these files and when possible, it is even possible to load them dynamically.</p>
<p>In the next tutorials, I will show how to use and create these files and how to import and use fonts and CSS. All these things may be basic, but I think it is worth it to summarize all the different ways I have learned about on the web and while working in producton teams.</p>
]]></content:encoded>
			<wfw:commentRss>http://jansensan.net/loading-assets-dynamically-part-1/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
