<?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>Bugshake</title>
	<atom:link href="http://bugshake.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://bugshake.com</link>
	<description>This is developer Stijn Raaijmakers' weblog.</description>
	<lastBuildDate>Thu, 10 Dec 2009 14:58:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A custom preloader in Unity part 3/3</title>
		<link>http://bugshake.com/?p=141</link>
		<comments>http://bugshake.com/?p=141#comments</comments>
		<pubDate>Thu, 10 Dec 2009 14:29:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[preloader]]></category>
		<category><![CDATA[swfobject]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[u3dobject]]></category>
		<category><![CDATA[unity3d]]></category>

		<guid isPermaLink="false">http://bugshake.com/?p=141</guid>
		<description><![CDATA[The third and final alternative. Lemme warn you, its complicated, but its worth it. Because you will be able to make a flash preloader for a unity scene, which basicly gives you the ultimate freedom (well unless you wanna have a 3D preloader, then refer to part 2 of this tutorial).

There&#8217;s 4 components to this [...]]]></description>
			<content:encoded><![CDATA[<p>The third and final alternative. Lemme warn you, its complicated, but its worth it. Because you will be able to make a flash preloader for a unity scene, which basicly gives you the ultimate freedom (well unless you wanna have a 3D preloader, then refer to part 2 of this tutorial).<br />
<span id="more-141"></span><br />
There&#8217;s 4 components to this solution.</p>
<ul>
<li>main unity file &#8211; the actual, 100 MB unity file which contains your awesome game</li>
<li>unity preloader file &#8211; this is a very, very minimal preloader written in unity, which receives a query parameter containing the movie to load and will use <a href="http://unity3d.com/support/documentation/ScriptReference/Application.ExternalCall.html">Application.ExternalCall</a> to inform it&#8217;s html page of the loading progress. It&#8217;s reusable and you can download it <a href="http://bugshake.com/unity3d/preloader.unity3d">here</a>.</li>
<li>swf preloader file &#8211; this is a relatively small flash movie, which will show the graphics of your preloader. It will use <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00001653.html">ExternalInterface.addCallback</a> to listen to the events the unity-preloader fires.</li>
<li>javascript/html framework &#8211; you&#8217;ll need some javascript to receive calls from unity and relay those to flash. You&#8217;ll also need to hide and show the swf and unity files when it&#8217;s appropriate</li>
</ul>
<p>Once you downloaded the preloader and you have a little flash preloader animation which listens to ExternalInterface, your biggest problem will be to make the hosting html page a bit organized.</p>
<div style="float:right; margin:1em">
<img height="20" src="http://www.aquiris.com.br/img/u3dobj_logo.png" alt="u3d logo" /></p>
<p><img height="20" src="http://www.bobbyvandersluis.com/swfobject/img/swfobject_logo.gif" alt="swf logo" /></div>
<div style="float:left; margin:1em"><img src="http://bugshake.com/img/swfpreloaderflow.png" alt="Component lifetime" /></div>
<p>What I did, was use <a href="http://code.google.com/p/swfobject/">swfobject</a> to load the flash movie and <a href="http://code.google.com/p/aquiris-u3dobject/">u3dobject</a> to load the unity movie.</p>
<p>u3dobject offers loads of premade functionality to communicate between flash and unity, which I am not using because this wrapper is more complex then the original code (for this purpose) and it&#8217;s extra bytes which we don&#8217;t want in a preloader. I imagine for larger applications it&#8217;s invaluable because it allows flash movies to listen to unity events and visa versa in a very elegant way.</p>
<p>To the left here, you can see a little diagram of the lifetime of these 4 components. Made with the most time-saving UML tool out there: mspaint.</p>
<p>You can see an example of this method here:</p>
<p><a href="http://kominski.net/demo/unityswfpreloader/">http://kominski.net/demo/unityswfpreloader/</a></p>
<p>It&#8217;s actually a bit of a bad example, since in this version you have to click the image to see the preloader (or if its loaded the unity scene directly).<br clear="both" /></p>
<p>So, to make the flash preloader, add the following code to your <a href="http://www.actionscript.org/resources/articles/683/1/Using-Document-Classes-in-Flash-CS3-Professional/Page1.html">document class</a> constructor:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">ExternalInterface</span>.<span style="color: #004993;">addCallback</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onPreloadStart&quot;</span>, onPreloadStart<span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">ExternalInterface</span>.<span style="color: #004993;">addCallback</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onPreloadProgress&quot;</span>, onPreloadProgress<span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">ExternalInterface</span>.<span style="color: #004993;">addCallback</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onPreloadCompleted&quot;</span>, onPreloadCompleted<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>and then the definitions for those functions:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onPreloadStart<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #009900;">// called when the preloader.unity3d starts actually loading the main unity file</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onPreloadProgress<span style="color: #000000;">&#40;</span><span style="color: #004993;">progress</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #009900;">// progress contains a number from 0.0 to 1.0 indicating progress</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onPreloadCompleted<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #009900;">// called when the preloader.unity3d finished loading and is about to call stream.LoadUnityWeb()</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Your html page will not look much like the generated unity template, but it&#8217;s based on the u3dobj template. Here&#8217;s the short version of what it will look like:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;script src=&quot;js/jquery.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;js/u3dobject.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;	
	&lt;script src=&quot;js/unitydetect.vbs&quot; language='VBScript'&gt;&lt;/script&gt;
	&lt;script src=&quot;js/swfobject.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
&nbsp;
	function initialize()
	{
		load_flash();
		load_unity();
	}
&nbsp;
	function load_flash()
	{
		var flashvars = { root_url: &quot; &quot;};
		var params = { 'allowScriptAccess': 'always'};
		var attributes = {};
		attributes.id = &quot;flash_content&quot;;
		swfobject.embedSWF(&quot;swf/preloader.swf&quot;, &quot;flash_content&quot;, &quot;600&quot;, &quot;450px&quot;, &quot;9.0.0&quot;, &quot;swf/expressInstall.swf&quot;, flashvars, params, attributes);	
	}
&nbsp;
	function load_unity()
	{
		var options = {
			width:600,
			height:450,
		};
		$(&quot;#div_unity&quot;).embedUnity('unity/preloader.unity3d?file=unity/main.unity3d', options);
		hide_unity();
	}
&nbsp;
	function hide_unity()
	{		
		$.u3dobject.hide(&quot;div_unity&quot;); // doesnt work in jquery syntax
	}	
&nbsp;
	function show_unity()
	{	
		$(&quot;#flash_content&quot;).hide();
		$.u3dobject.show(&quot;div_unity&quot;); // doesnt work in jquery syntax
	}
&nbsp;
	function onPreloadStart()
	{	
		var el = document.getElementById(&quot;flash_content&quot;);		
		if( el ) el.onPreloadStart();
	}
&nbsp;
	function onPreloadProgress(progress)
	{
		var el = document.getElementById(&quot;flash_content&quot;);
		if( el ) el.onPreloadProgress(progress);
	}
&nbsp;
	function onPreloadCompleted()
	{
		// todo: wait just 2 sec before running the next line to give unity time to unpack
		show_unity();
	}
    &lt;/script&gt;
    &lt;link href=&quot;css/default.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;/head&gt;
&nbsp;
&lt;body onload=&quot;initialize();&quot;&gt;
&lt;div id=&quot;flash_content&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;div_unity&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>And that should do it. I have not elaborated too much on stuff because it&#8217;s an advanced topic so you don&#8217;t want too much clutter. If you have questions, just post a comment, I&#8217;ll be happy to answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://bugshake.com/?feed=rss2&amp;p=141</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A custom preloader in Unity part 2/3</title>
		<link>http://bugshake.com/?p=128</link>
		<comments>http://bugshake.com/?p=128#comments</comments>
		<pubDate>Thu, 10 Dec 2009 10:42:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[preloader]]></category>
		<category><![CDATA[swfobject]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[u3dobject]]></category>
		<category><![CDATA[unity3d]]></category>

		<guid isPermaLink="false">http://bugshake.com/?p=128</guid>
		<description><![CDATA[The second way to do it resembles very much how it works in flash: first you load a small movie, which is just the preloader, which will load the big movie.

A completely empty unity scene compiles to about a 7kB .unity3d file. Very small and very nice for making a preloader. If you&#8217;re preloader gets [...]]]></description>
			<content:encoded><![CDATA[<p>The second way to do it resembles very much how it works in flash: first you load a small movie, which is just the preloader, which will load the big movie.<br />
<span id="more-128"></span><br />
A completely empty unity scene compiles to about a 7kB .unity3d file. Very small and very nice for making a preloader. If you&#8217;re preloader gets larger, you might wanna consider having a look at part 1 of this tutorial to skin it with a back color and logo matching your website.</p>
<p>So, to use this method, I am assuming you have a working project, say myProject.unity3d which is 15MB in size. Now, make a new unity scene, create en empty game object named &#8220;application&#8221; and attach a behaviour script to it named &#8220;main.cs&#8221; or &#8220;main.js&#8221;. (Or whatever language you prefer). This scene will need to have some sort of animation to show the loading progress. In this example I will be fading a GUITexture from 0 to 100% opacity.</p>
<p>Here&#8217;s what it could look like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">var</span> fileUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://www.unity3d.com/webplayers/Lightning/lightning.unity3d&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">var</span> progressImage<span style="color: #339933;">:</span>GUITexture<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> Start <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	progressImage.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Color<span style="color: #009900;">&#40;</span>.5<span style="color: #339933;">,</span> .5<span style="color: #339933;">,</span> .5<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> stream <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> WWW <span style="color: #009900;">&#40;</span>fileUrl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>stream.<span style="color: #660066;">isDone</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		progressImage.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Color<span style="color: #009900;">&#40;</span>.5<span style="color: #339933;">,</span> .5<span style="color: #339933;">,</span> .5<span style="color: #339933;">,</span> stream.<span style="color: #660066;">progress</span> <span style="color: #339933;">*</span> .5<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		yield<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	stream.<span style="color: #660066;">LoadUnityWeb</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I used it for <a href="http://kominski.net/demo/3druimte/">this preloader</a> (shown when you click the image).</p>
<p>If you want to reuse the same preloader, you can choose to simply pass the name of the main unity file you wish to load as a parameter. The html embed will look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;param name=&quot;src&quot; value=&quot;unity/preloader.unity3d?file=unity/main.unity3d&quot; /&gt;</pre></div></div>

<p>And your unity file will have a bit of code like this (in C# this time):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> url <span style="color: #008000;">=</span> Application.<span style="color: #0000FF;">srcValue</span>.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">'?'</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>url.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args <span style="color: #008000;">=</span> url<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">'&amp;'</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
   <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> arg <span style="color: #0600FF;">in</span> args<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
     <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> keyvalue <span style="color: #008000;">=</span> arg.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">'='</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
     <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>keyvalue<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;file&quot;</span><span style="color: #000000;">&#41;</span> fileUrl <span style="color: #008000;">=</span> keyvalue<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bugshake.com/?feed=rss2&amp;p=128</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A custom preloader in Unity part 1/3</title>
		<link>http://bugshake.com/?p=114</link>
		<comments>http://bugshake.com/?p=114#comments</comments>
		<pubDate>Thu, 10 Dec 2009 10:06:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[preloader]]></category>
		<category><![CDATA[swfobject]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[u3dobject]]></category>
		<category><![CDATA[unity3d]]></category>

		<guid isPermaLink="false">http://bugshake.com/?p=114</guid>
		<description><![CDATA[Unity 2.6 is now out and they made the indie version free! Thanks unity team!
Unity is used a lot for offline and iphone content and perhaps not so much as a 3D replacement for flash. As a flash programmer, there&#8217;s certain things you wanna know, like how to make a preloader.
I will describe 3 ways [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://unity3d.com/">Unity 2.6</a> is now out and they made the indie version free! Thanks unity team!</p>
<p>Unity is used a lot for offline and iphone content and perhaps not so much as a 3D replacement for flash. As a flash programmer, there&#8217;s certain things you wanna know, like how to make a preloader.</p>
<p>I will describe 3 ways to make a preloader, the last being the most complex and most impressive <img src='http://bugshake.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The first way is just to customize the default preloader.<br />
<span id="more-114"></span><br />
Here&#8217;s what the preloader looks like by default:</p>
<p><img src="http://bugshake.com/img/unity_preloader.png" alt="Default Unity Preloader" /></p>
<p>There&#8217;s 5 elements in there, that you can customize by passing parameters to the <em>object</em> and <em>embed</em> tags in html:</p>
<ul>
<li>bordercolor : the border is always there and its always 1 pixel</li>
<li>backgroundcolor</li>
<li>logoimage : will replace the unity logo, will be centered, and will never stretch till the edges, it will leave a 10pixel margin</li>
<li>progressbarimage : the image of the actual bar, it will be stretched and it shows what the empty bar looks like</li>
<li>progressframeimage : what a full progress bar looks like, it&#8217;s not stretched, just covered by the progressbarimage</li>
</ul>
<p>Here&#8217;s where those elements go:</p>
<p><img src="http://bugshake.com/img/unity_elements.png" alt="Unity Preloader Elements" /></p>
<p>This is what it looks like in code:</p>
<div style="text-align:left">
<code><br />
&lt;object id=&quot;UnityObject&quot; classid=&quot;clsid:444785F1-DE89-4295-863A-D46C3A781394&quot; width=&quot;600&quot; height=&quot;450&quot; codebase=&quot;http://webplayer.unity3d.com/download_webplayer-2.x/UnityWebPlayer.cab#version=2,0,0,0&quot;&gt;<br />
&lt;param name=&quot;src&quot; value=&quot;myProject.unity3d&quot; /&gt;<br />
<strong>&lt;param name=&quot;bordercolor&quot; value=&quot;337af1&quot; /&gt;<br />
&lt;param name=&quot;backgroundcolor&quot; value=&quot;ffcc99&quot; /&gt;<br />
&lt;param name=&quot;logoimage&quot; value=&quot;logo.png&quot; /&gt;<br />
&lt;param name=&quot;progressbarimage&quot; value=&quot;bar.png&quot; /&gt;<br />
&lt;param name=&quot;progressframeimage&quot; value=&quot;frame.png&quot; /&gt;</strong><br />
&lt;embed id=&quot;UnityEmbed&quot; src=&quot;myProject.unity3d&quot; width=&quot;600&quot; height=&quot;450&quot; type=&quot;application/vnd.unity&quot; <strong>bordercolor=&quot;337af1&quot; backgroundcolor=&quot;ffcc99&quot; logoimage=&quot;logo.png&quot; progressbarimage=&quot;bar.png&quot; progressframeimage=&quot;frame.png&quot; </strong>pluginspage=&quot;http://www.unity3d.com/unity-web-player-2.x&quot; /&gt;<br />
&lt;/object&gt;<br />
</code>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bugshake.com/?feed=rss2&amp;p=114</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Custom tween in Tweener</title>
		<link>http://bugshake.com/?p=87</link>
		<comments>http://bugshake.com/?p=87#comments</comments>
		<pubDate>Tue, 18 Aug 2009 11:40:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[tweener]]></category>

		<guid isPermaLink="false">http://bugshake.com/?p=87</guid>
		<description><![CDATA[
I recently needed a tween that is different from the ones you see on the cheat sheet. All tweens you&#8217;ll find there have the property that the movement hardly goes outside the bounds of begin-to-endpoint (0&#8230;1). What I needed, was a tween that swings completely beyond its target, almost as far as the begin point [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/img/custom-tween.gif" align="right" alt="Custom Tween" /><br />
I recently needed a tween that is different from the ones you see on the <a href="http://hosted.zeh.com.br/tweener/docs/en-us/misc/transitions.html">cheat sheet</a>. All tweens you&#8217;ll find there have the property that the movement hardly goes outside the bounds of begin-to-endpoint (0&#8230;1). What I needed, was a tween that swings completely beyond its target, almost as far as the begin point (0&#8230;-1&#8230;1).</p>
<p><span id="more-87"></span></p>
<p>So what you do is use a custom function, here&#8217;s how:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">Tweener.addTween<span style="color: #000000;">&#40;</span>mc,
   <span style="color: #000000;">&#123;</span><span style="color: #004993;">rotation</span><span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">100</span>, <span style="color: #004993;">time</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">1</span>, transition<span style="color: #000000; font-weight: bold;">:</span>myFunc<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>The <a href="http://hosted.zeh.com.br/tweener/docs/en-us/parameters/transition.html">tweener documentation</a> will tell you this function needs 4 params, it actually needs 5, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> easeOutSwing<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Function</span> = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>
      t<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, <span style="color: #004993;">b</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, <span style="color: #004993;">c</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, <span style="color: #004993;">d</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,
      p_params<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>
   <span style="color: #000000;">&#123;</span>
      ...
   <span style="color: #000000;">&#125;</span>;</pre></div></div>

<p>Where</p>
<ul>
<li>t = time from 0&#8230;1</li>
<li>b = begin value</li>
<li>c = change to value (delta)</li>
<li>d = total duration (ms)</li>
<li>not used</li>
</ul>
<p>To make one yourself, you can use the tool the tweener documentation suggests, <a href="http://timotheegroleau.com/Flash/experiments/easing_function_generator.htm">the easing generator</a>. A quintic bezier is not the only option, but its handy for most purposes I imagine.</p>
<p>For my purpose i entered the values 7, -9, 7 and -.17 for P1,2,3,4, resulting in a function like this (with extra param):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> myFunc<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Function</span> = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>
      t<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, <span style="color: #004993;">b</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, <span style="color: #004993;">c</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, <span style="color: #004993;">d</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,
      p_params<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>
   <span style="color: #000000;">&#123;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> ts<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000;">&#40;</span>t<span style="color: #000000; font-weight: bold;">/</span>=<span style="color: #004993;">d</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">*</span>t;
      <span style="color: #6699cc; font-weight: bold;">var</span> tc<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=ts<span style="color: #000000; font-weight: bold;">*</span>t;
      <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">b</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #004993;">c</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">175.7</span><span style="color: #000000; font-weight: bold;">*</span>tc<span style="color: #000000; font-weight: bold;">*</span>ts <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">499.7</span><span style="color: #000000; font-weight: bold;">*</span>ts<span style="color: #000000; font-weight: bold;">*</span>ts <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">510</span><span style="color: #000000; font-weight: bold;">*</span>tc <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">220</span><span style="color: #000000; font-weight: bold;">*</span>ts <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">35</span><span style="color: #000000; font-weight: bold;">*</span>t<span style="color: #000000;">&#41;</span>;
   <span style="color: #000000;">&#125;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bugshake.com/?feed=rss2&amp;p=87</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Digging into CS4 perspective</title>
		<link>http://bugshake.com/?p=76</link>
		<comments>http://bugshake.com/?p=76#comments</comments>
		<pubDate>Mon, 13 Jul 2009 11:41:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Showcase]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flex4]]></category>

		<guid isPermaLink="false">http://bugshake.com/?p=76</guid>
		<description><![CDATA[I finally managed to completely copy the flash internal perspective with a manual perspective.

In flash cs4, you can make a plane, say, a 100&#215;100 plane sitting on (0,0). Then, you can rotate it in 3D, using the properties rotationX, rotationY and rotationZ. Say you would rotate it by x and y by 20 degrees each, [...]]]></description>
			<content:encoded><![CDATA[<p>I finally managed to completely copy the flash internal perspective with a manual perspective.</p>
<p><a href="http://bugshake.com/pages/cs4perspective/"><img src="http://bugshake.com/pages/cs4perspective/cs4perspective.jpg" alt="CS4 perspective with manual perspective overlay in red" /></a></p>
<p>In flash cs4, you can make a plane, say, a 100&#215;100 plane sitting on (0,0). Then, you can rotate it in 3D, using the properties <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/DisplayObject.html#rotationX">rotationX</a>, rotationY and rotationZ. Say you would rotate it by x and y by 20 degrees each, you end up with a nice plane in perspective.</p>
<p>Now this is really cool, but if would be quite a pain to display a 3D mesh in such a way.<br />
<span id="more-76"></span><br />
Now I have been digging into how to display a 3D mesh using the two new functions <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/geom/Matrix3D.html#transformVectors()">transformVectors</a> and <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/Graphics.html#drawTriangles()">drawTriangles</a>. Without z-sorting, I could render a 1500 poly textured mesh in 3 miliseconds. Which is very, very fast and certainly opens op possibilities. Here&#8217;s a screenshot:</p>
<p><img src="http://bugshake.com/pages/cs4perspective/meshviewer.jpg" alt="Screenshot from my core cs4 direct X mesh viewer" /></p>
<p>Basicly, what you do, is you have an array of world coordinates in 3D, you transform them using transformvectors, and then you add a sort of perspective function to make stuff smaller when its further away:</p>
<p><img src="http://upload.wikimedia.org/wikipedia/en/3/3a/Perspective_Transform_Diagram.png" alt="perspective on wikipedia" /></p>
<p>The big problem was, getting the standard flash rotationX / rotationY to work with this, more lowlevel method of getting perspective. The solution was surprisingly simple. You get the focal length from the main <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/geom/Transform.html#perspectiveProjection">perspective transform</a> like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> f<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">parent</span>.<span style="color: #004993;">transform</span>.perspectiveProjection.focalLength;</pre></div></div>

<p>Then, you will have some z-coord, which should not be lower then -f (-f is where your eye is in real life, focal length is the distance from your eye to the physical piece of glass that you call your screen). The scaling for any point (x,y,z) will then be:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> s<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = f <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">&#40;</span>f <span style="color: #000000; font-weight: bold;">+</span> z<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>In my sample code, I create a bunch of 20&#215;20 squares, randomly placed in 3d. I allow you to rotate them using the mouse. This part is all using standard rotationX and rotationY.</p>
<p>Then I have something which I called an &#8216;overlay&#8217;, which is a series of 3d points and connecting lines, which I make sure are the exact same squares.</p>
<p>Finally, I rotate both according to the mouse movements and voila! the overlay (red lines) matches the movieclips (blue/white shapes).</p>
<p><a href="http://bugshake.com/pages/cs4perspective/src.zip">Download the source code here.</a></p>
<p><a href="http://bugshake.com/pages/cs4perspective/">View the result here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bugshake.com/?feed=rss2&amp;p=76</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rtmp protocol released</title>
		<link>http://bugshake.com/?p=72</link>
		<comments>http://bugshake.com/?p=72#comments</comments>
		<pubDate>Tue, 16 Jun 2009 08:12:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[rtmp]]></category>

		<guid isPermaLink="false">http://bugshake.com/?p=72</guid>
		<description><![CDATA[Adobe finally released the RTMP protocol to the developer community, so reverse engineering it should no longer be needed if you wanna work with the flash networking protocol, but cannot afford Flash Media Server or are not working with a flash client.
http://www.adobe.com/devnet/rtmp/
This is great news, because now we (programmers) can all use the more difficult [...]]]></description>
			<content:encoded><![CDATA[<p>Adobe finally released the RTMP protocol to the developer community, so reverse engineering it should no longer be needed if you wanna work with the flash networking protocol, but cannot afford Flash Media Server or are not working with a flash client.</p>
<p><a href="http://www.adobe.com/devnet/rtmp/">http://www.adobe.com/devnet/rtmp/</a></p>
<p>This is great news, because now we (programmers) can all use the more difficult AMF0 and media streaming features of it!</p>
<p>We should be seeing an increase in live streaming applications now.</p>
]]></content:encoded>
			<wfw:commentRss>http://bugshake.com/?feed=rss2&amp;p=72</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a 3D map with google maps and flex4</title>
		<link>http://bugshake.com/?p=67</link>
		<comments>http://bugshake.com/?p=67#comments</comments>
		<pubDate>Tue, 02 Jun 2009 16:42:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Showcase]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[google maps]]></category>

		<guid isPermaLink="false">http://bugshake.com/?p=67</guid>
		<description><![CDATA[It has been ages since I last posted cause I have been really busy working on a 3d world in Unity3D to which I cannot yet show you a link, but you can see the presentation Paul gave on it here: http://www.adobeusergroup.nl/site/list_messages/270
Anyway as most flash developers know, in flash player 10 any sprite can have [...]]]></description>
			<content:encoded><![CDATA[<p>It has been ages since I last posted cause I have been really busy working on a 3d world in Unity3D to which I cannot yet show you a link, but you can see the presentation Paul gave on it here: <a href="http://www.adobeusergroup.nl/site/list_messages/270" target="_blank">http://www.adobeusergroup.nl/site/list_messages/270</a></p>
<p>Anyway as most flash developers know, in flash player 10 any sprite can have a 3D rotation and position to create the illusion of 3D. Now, I wanted to test out the latest version of the google maps flash api, so I figured why not throw the google map on a plane in 3D space and see if it still works.</p>
<p>Amazingly enough: it does!</p>
<p>Here it is: <a href="http://bugshake.com/pages/googleflex4/">http://bugshake.com/pages/googleflex4/</a></p>
<p><span id="more-67"></span><br />
The fact that it works is quite positive. It shows how thorough adobe has been with the new 3D rotations, since I am quite certain the google api does not know it it&#8217;s map is displayed on a 3d plane. Even scrolling and clicking markers work fine.</p>
<p>In the above application you should see the map of amsterdam, focussed on the outdoor theatre that is in the center of the Vondelpark. You should be able to scroll the map around in 3D. A white circle should be projected on the map, right around your cursor and a blue &#8217;streetsign&#8217; should also be visible under your cursor. Using the mouse wheel you should be able to zoom in and out.</p>
<p>Using the geocoding api, I am showing the lowest level zoom address of the cursor location on the blue sign.</p>
<p>Source code later!</p>
]]></content:encoded>
			<wfw:commentRss>http://bugshake.com/?feed=rss2&amp;p=67</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>c# style trace</title>
		<link>http://bugshake.com/?p=60</link>
		<comments>http://bugshake.com/?p=60#comments</comments>
		<pubDate>Tue, 14 Apr 2009 15:51:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[code snippet]]></category>

		<guid isPermaLink="false">http://bugshake.com/?p=60</guid>
		<description><![CDATA[Hi, just a little handy AS3 snippet I thought I&#8217;d share. It simulates the string.format from dotnet in a trace statement. I decided to name it tracef like printf in c (f = format)

tracef&#40;&#34;my location = ({0}, {1}), my name is {2}&#34;, x, y, name&#41;

Here&#8217;s the debug function:

private function tracef&#40;msg:String, ...arguments&#41;:void
&#123;
   for&#40; var [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, just a little handy AS3 snippet I thought I&#8217;d share. It simulates the string.format from dotnet in a trace statement. I decided to name it tracef like printf in c (f = format)</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">tracef<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;my location = ({0}, {1}), my name is {2}&quot;</span>, <span style="color: #004993;">x</span>, <span style="color: #004993;">y</span>, <span style="color: #004993;">name</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Here&#8217;s the debug function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> tracef<span style="color: #000000;">&#40;</span>msg<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>, ...<span style="color: #004993;">arguments</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #004993;">arguments</span>.<span style="color: #004993;">length</span>; <span style="color: #000000; font-weight: bold;">++</span>i <span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
      msg = msg.<span style="color: #004993;">split</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;{&quot;</span><span style="color: #000000; font-weight: bold;">+</span>i<span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot;}&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">arguments</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
   <span style="color: #000000;">&#125;</span>
   <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> msg <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Btw, <a href="http://en.wikipedia.org/wiki/Monosodium_glutamate">msg</a>&#8217;s are bad for you, at least in your food, but that&#8217;s a different story.</p>
]]></content:encoded>
			<wfw:commentRss>http://bugshake.com/?feed=rss2&amp;p=60</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HP Service</title>
		<link>http://bugshake.com/?p=52</link>
		<comments>http://bugshake.com/?p=52#comments</comments>
		<pubDate>Wed, 11 Mar 2009 15:12:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[Corporate Terror]]></category>
		<category><![CDATA[Drivers]]></category>
		<category><![CDATA[Fail]]></category>
		<category><![CDATA[Hardware]]></category>

		<guid isPermaLink="false">http://bugshake.com/?p=52</guid>
		<description><![CDATA[Allow me to flame the Hewlet Packard helpdesk a bit while helping others with the same problem. This issue should be in their FAQ, but&#8230; well&#8230; it isn&#8217;t.
The problem is that you get random reboots, hangups or BSOD&#8217;s (blue screen of death). It happens on my HP Pavilion Media PC (8170.nl), which comes with Microsoft [...]]]></description>
			<content:encoded><![CDATA[<p>Allow me to flame the Hewlet Packard helpdesk a bit while helping others with the same problem. This issue should be in their FAQ, but&#8230; well&#8230; it isn&#8217;t.</p>
<p>The problem is that you get random reboots, hangups or BSOD&#8217;s (blue screen of death). It happens on my HP Pavilion Media PC (8170.nl), which comes with Microsoft Vista.</p>
<p>The cause, or at least part of the cause, became apparent after I completely reinstalled the computer, including a hardrive format. It worked fine, but after installing the windows auto update nvidia drivers, the problem came back.</p>
<p>Turns out, nvidia offers much newer drivers on their website then windows update does.</p>
<p><span id="more-52"></span></p>
<p>Something else I changed has to do with IRQ&#8217;s, and this might have helped as well. Googling the message on my BSOD resulted in lots of posts about IRQ&#8217;s (interrupts) conflicting. Now you really, <em>really</em> have to look for those settings in windows vista. I never found where to change the IRQ some driver uses, but I did find a list of devices, organised by IRQ, in which it was possible to &#8216;disable&#8217; a device. Lucky for me, the 2 devices that shared IRQ 14 were 2 things i don&#8217;t use: tv tuner and wireless lan. Also lucky for me, microsoft didn&#8217;t forget to put that disable button there.</p>
<p>Anyway, does that sounds like an issue HP should know about? I&#8217;d say so. &#8220;Windows autoupdate will make your computer crash every 10 minutes&#8221;. Applies to: pavilion 8170.nl, with default software and hardware installed. Maybe I am the only one who bought this model. Who knows.</p>
<p>But they didn&#8217;t know. Nor is it in the FAQ. It took me 35minutes of telephone time (24 euro&#8217;s) to get to the point where the dude on the phone promised me I would be called back with a price indication of having my computer picked up and brought back, working again. Needless to say, I never received that call.</p>
<p>Luckily, I am the guy in my family and in my group of friends who people ask which computer to buy. Well: not HP! HAHA, revenge!</p>
]]></content:encoded>
			<wfw:commentRss>http://bugshake.com/?feed=rss2&amp;p=52</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Textfield with custom font</title>
		<link>http://bugshake.com/?p=46</link>
		<comments>http://bugshake.com/?p=46#comments</comments>
		<pubDate>Wed, 18 Feb 2009 14:51:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://bugshake.com/?p=46</guid>
		<description><![CDATA[I noticed a little bug in flash (at least, in my version), for which I wanted to share the fix.
The bug is as follows: you create a TextField, you change it&#8217;s text and then it looks empty.
Here&#8217;s the code that triggers the bug:

// create
var fmt = new TextFormat&#40;&#34;Arial&#34;, 10, 0x000000&#41;; // make sure you embedded [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed a little bug in flash (at least, in my version), for which I wanted to share the fix.</p>
<p>The bug is as follows: you create a TextField, you change it&#8217;s text and then it looks empty.</p>
<p><span id="more-46"></span>Here&#8217;s the code that triggers the bug:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">// create</span>
<span style="color: #6699cc; font-weight: bold;">var</span> fmt = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Arial&quot;</span>, <span style="color: #000000; font-weight:bold;">10</span>, 0x000000<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// make sure you embedded this</span>
<span style="color: #6699cc; font-weight: bold;">var</span> label = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span>;
label.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Default text&quot;</span>;
label.<span style="color: #004993;">setTextFormat</span><span style="color: #000000;">&#40;</span>fmt<span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>label<span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">// use</span>
label.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Custom text&quot;</span>;</pre></div></div>

<p>You&#8217;d expect it to say &#8220;Custom text&#8221; but instead the label is empty. What worked for me is to first call the replace function and replace the first character with the first character. Like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">// create</span>
<span style="color: #6699cc; font-weight: bold;">var</span> fmt = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Arial&quot;</span>, <span style="color: #000000; font-weight:bold;">10</span>, 0x000000<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// make sure you embedded this</span>
<span style="color: #6699cc; font-weight: bold;">var</span> label = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span>;
label.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Default text&quot;</span>;
label.<span style="color: #004993;">setTextFormat</span><span style="color: #000000;">&#40;</span>fmt<span style="color: #000000;">&#41;</span>;
label.<span style="color: #004993;">replaceText</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #990000;">&quot;D&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>label<span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">// use</span>
label.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Custom text&quot;</span>;</pre></div></div>

<p>Now it will say &#8220;Custom text&#8221;. Speaking of bugs, there&#8217;s a related one, where your text doesn&#8217;t show up at all. This is when you assign the text after the textformat. So this will not work:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">label.<span style="color: #004993;">setTextFormat</span><span style="color: #000000;">&#40;</span>fmt<span style="color: #000000;">&#41;</span>;
label.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Default text&quot;</span>;</pre></div></div>

<p>But this will:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">label.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Default text&quot;</span>;
label.<span style="color: #004993;">setTextFormat</span><span style="color: #000000;">&#40;</span>fmt<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Go figure.</p>
]]></content:encoded>
			<wfw:commentRss>http://bugshake.com/?feed=rss2&amp;p=46</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
