<?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; Workflow</title>
	<atom:link href="http://jansensan.net/category/workflow/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>Planning the production of an interactive project</title>
		<link>http://jansensan.net/planning-the-production-of-an-interactive-project</link>
		<comments>http://jansensan.net/planning-the-production-of-an-interactive-project#comments</comments>
		<pubDate>Mon, 03 May 2010 21:05:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://jansensan.net/?p=285</guid>
		<description><![CDATA[As a creative developer and an interaction designer, I need to either produce or guide the production of interactive projects. Needless to say, to non technical people such as designers, producers and account managers, we do some black magic and create the most amazing things. But what are the ingredients of this magic? Mostly organizational [...]]]></description>
			<content:encoded><![CDATA[<p>As a creative developer and an interaction designer, I need to either produce or guide the production of interactive projects. Needless to say, to non technical people such as designers, producers and account managers, we do some black magic and create the most amazing things. But what are the ingredients of this magic? Mostly organizational skills I would say.</p>
<p>I have originally planned to help and guide students and beginners with this blog, to use the posts as notes and references for some tutorials I have given at <a title="Concordia University - Computation Arts" href="http://computationarts.concordia.ca/" target="_blank">Concordia University</a> in Montréal. I strongly believe that it is the responsibility of senior developers and creatives to provide newcomers to this overwhelming field with the proper tools to learn to work efficiently and professionally.</p>
<p>Because, let's face it schools and universities fail in this domain. These institutions do not aim "to create mindless production drones for the interactive industry blah blah blah..." This is such a hypocritical argument that could be easily refuted by looking at how computer engineering or administration programs teach students how to be organized in their thoughts and workflow. Others have actually had confrontations much stronger than I and have lived to <a title="What’s Wrong with Ontario Colleges?" href="http://www.untoldentertainment.com/blog/2010/02/18/whats-wrong-with-ontario-colleges-part-1/" target="_blank">tell about it</a>.</p>
<p>For my part, I have chosen to provide <a title="Sid Lee" href="http://sidlee.com" target="_blank">Sid Lee</a>, where I currently work, with information and references to good practices in the form of a wiki. A wiki is easy to update and it is a well known way to organize information, so most people can navigate quickly.</p>
<p>Also, most things in many people's jobs do not need to be remembered by heart. Hell, I hope nobody says stuff without references, especially technical references necessary for a project! That is why such references are useful, especially for training newcomers and simply for keeping inline with company policies.</p>
<p>In the wiki, I presented what is needed for a project from many players in the process of the production, such as producers, designers and interactive developers. This is an internal tool not available to the public, but today I stumbled upon an article, <a title="What To Deliver A Flash Developer" href="http://evolve.reintroducing.com/2010/05/03/tips-n-tricks/what-to-deliver-a-flash-developer/" target="_blank">What to Deliver a Flash Developer</a>, which highlights a lot of the similar points that I have brought up to many kick off meetings. Since this blog is aimed at helping developers to learn good practices, I thought it would be a good idea to republish and comment on the post.</p>
<p>Note that I am careful in not utilizing the term "Flash developer" as the authors of the post did, as I believe this is plain wrong. Do we call designers "Photoshoppists"? Flash is just a tool currently used often in the creation of RIAs, but it is not and will not always be the case. Some of us work with ActionScript, some others with PHP, with CSS, with HTML, with Objective-C, with Android, with Java, with OpenFrameworks, etc. Specialists exist indeed in all fields, but workflows for RIAs, games and other interactive projects are not confined to Flash development.</p>
<p>Whatever rant or complaint I may seem to voice here, the article aforementioned is a great read for anybody who wishes to manage development of projects, or simply to make sure that parts are not forgotten along the way.</p>
]]></content:encoded>
			<wfw:commentRss>http://jansensan.net/planning-the-production-of-an-interactive-project/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flash Player Security Settings to Develop Locally</title>
		<link>http://jansensan.net/flash-player-security-settings-to-develop-locally</link>
		<comments>http://jansensan.net/flash-player-security-settings-to-develop-locally#comments</comments>
		<pubDate>Thu, 25 Feb 2010 21:28:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://jansensan.net/?p=143</guid>
		<description><![CDATA[When developing locally, you may encounter errors when loading data or classes dynamically. By default the Flash Player is set to only work in a certain sandbox, which limits its access.
Honestly, all that stuff is too complex for me to care.
What you and I really want, is to be able to develop our projects locally [...]]]></description>
			<content:encoded><![CDATA[<p>When developing locally, you may encounter errors when loading data or classes dynamically. By default the Flash Player is set to only work in a certain sandbox, which limits its access.</p>
<p>Honestly, all that stuff is too complex for me to care.</p>
<p>What you and I really want, is to be able to develop our projects locally without issues, because let's face it, we trust our own actions. The following simple steps will present how to set the Flash Player Security settings for you to be able to work without hinderance.</p>
<p>First, head to the <a title="Flash Player Security Settings" href="http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html" target="_blank">Flash Player Security Settings</a> page. Yes, it is online and you can only access it if you are connected to the Internet. It is ridiculous, I know, it should be available from other means, like right-clicking on a Flash Player object, but it is not so.</p>
<p>Then, you will encounter this:</p>
<p><img class="aligncenter" title="Flash Player Global Security Settings" src="http://jansensan.net/images/blog/post0009_security_settings.jpg" alt="Flash Player Global Security Settings" width="395" height="270" /></p>
<p>If it is not already, select the Global Security Settings tab (3rd one, as seen above).</p>
<p><img class="aligncenter" title="Edit Locations" src="http://jansensan.net/images/blog/post0009_edit_locations.jpg" alt="Edit Locations" width="169" height="83" /></p>
<p>Click on “Edit locations” and select “Add location...”</p>
<p><img class="aligncenter" title="Browse for Folder" src="http://jansensan.net/images/blog/post0009_browse_for_folder.jpg" alt="Browse for Folder" width="395" height="270" /></p>
<p>Select “Browse for folder” and select the folder to which you want Flash Player to have access. I chose the whole computer so I can work properly.</p>
<p>And voilà! You now can now load XML files and dynamic classes easily without facing unexpected errors.</p>
<p>Once you have done it you will not need to do it again, but when you change computers or reformat one, it's not necessarily something you think at first. This is when this post will become useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://jansensan.net/flash-player-security-settings-to-develop-locally/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>
		<item>
		<title>My setup</title>
		<link>http://jansensan.net/my-setup</link>
		<comments>http://jansensan.net/my-setup#comments</comments>
		<pubDate>Mon, 14 Sep 2009 04:30:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://jansensan.net/clients/jansensan/?p=1</guid>
		<description><![CDATA[
I've been thinking of what to write for my first post, other than "Welcome to this blog". I realized that since I intend to share my work habits and to make some tutorials out of what I have learned the past few years, I might as well present how I work.
I have tried different ways [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter" title="Jansensan's Eclipse Setup" src="http://jansensan.net/images/blog/post0001_setup_640x360.jpg" alt="Jansensan's Eclipse Setup" width="640" height="360" /></p>
<p>I've been thinking of what to write for my first post, other than "Welcome to this blog". I realized that since I intend to share my work habits and to make some tutorials out of what I have learned the past few years, I might as well present how I work.</p>
<p>I have tried different ways of writing ActionScript over the last years: the Flash IDE (not really efficient), <a href="http://www.flashdevelop.org/" target="_blank">FlashDevelop</a> (is a good start), <a href="http://www.adobe.com/products/flex/" target="_blank">Flex Builder</a> and finally <a href="http://www.eclipse.org/" target="_blank">Eclipse</a>. Ok, the last two are actually the same. Here is why I am now using Eclipse to write my ActionScript projects, and sometimes even other projets.</p>
<p>The Flash IDE is a great visual tool as it merges some parts of Photoshop, Illustrator, After Effects and a code editor. However, try as you might, you can be good at a lot of things, but rarely can you master them all. The code completion in the Flash IDE is less than optimal, I haven't found a way to create snippets and honestly, it's missing many customization options.</p>
<p>FlashDevelop is great. Honestly. But you have to have a Windows system. Ever since I bought my MacBook Pro, I don't have that anymore. Sure I could install Parallels, but I think it's a lot of time wasted in an efficient workflow.</p>
<p>When I started at Sid Lee, I switched to Flex Builder since this is the tool used there. At iCongo, where I worked previously, we were using Eclipse, so I kind of got used to that workflow. After Flash Builder's (or Gumbo's) release, I struggled with some bugs and decided to move back to Eclipse.</p>
<p>I now use Eclipse 3.4 with the <a href="http://labs.adobe.com/technologies/flashbuilder4/" target="_blank">Flash Builder 4 plugin</a>. I prefer Eclipse to Flash Builder as the base IDE since Eclipse already includes an XML and HTML editor. Another huge... ok, let me rephrase... HUGE advantage that Eclipse has over FlashDevelop is the fact that Eclipse has a plugin for dealing with <a href="http://en.wikipedia.org/wiki/Subversion_%28software%29" target="_blank">SVN</a>, which I think is crucial for teamwork. Oh yea, you can install <a href="http://tortoisesvn.tigris.org/" target="_blank">TortoiseSVN</a> on your machine and deal with SVN separately from your code, but let's face it, that offers more chances for your team to mess the SVN flow.</p>
<p>So, to sum it up, I added the <a href="http://subclipse.tigris.org/" target="_blank">Subclipse</a> plugin to my Eclipse setup.</p>
<p>I also added the <a title="FlexFormatter" href="http://sourceforge.net/projects/flexformatter/" target="_blank">FlexFormatter</a> plugin, which allows me to format my code automatically the way i want. Quite useful when you are a neat freak like me.</p>
<p>When working with Java developpers at iCongo, I have seen that they had a tab for tasks, which I found useful. When I code, I may not want to write all the code at once, so I need to sprinkle some reminders along the way. The TODO and FIXME tags are quite useful in that sense. The <a href="http://www.richinternet.de/blog/index.cfm?entry=911D4B57-0F0D-5A73-AF6F4D4D04099757" target="_blank">Flex Builder 2 task extension</a> does just the thing!</p>
<p>Finally, since I started to edit my WordPress blog, I added a <a href="http://www.phpeclipse.com/" target="_blank">PHP extension</a> to my Eclipse.</p>
<p>If I was only work oriented, that would be sufficient. But I like my work environment to look great. I remembered three articles that <a href="http://theflashblog.com/" target="_blank">Lee Brimelow</a> wrote about making your Eclipse look better (<a href="http://theflashblog.com/?p=483" target="_blank">Pimp my Eclipse part 1</a>, <a href="http://theflashblog.com/?p=484" target="_blank">part 2</a>, <a href="http://theflashblog.com/?p=486" target="_blank">part 3</a>). There is a lot of stuff from his articles I did not use, but that could be useful nevertheless.</p>
]]></content:encoded>
			<wfw:commentRss>http://jansensan.net/my-setup/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
