<?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>blog.betabong.com &#187; Actionscript</title>
	<atom:link href="http://blog.betabong.com/category/tech/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.betabong.com</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 10:45:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Binary Fun &#8211; Bits in Bed with Actionscript</title>
		<link>http://blog.betabong.com/2009/09/22/binary-fun-bits-in-bed-with-actionscript/</link>
		<comments>http://blog.betabong.com/2009/09/22/binary-fun-bits-in-bed-with-actionscript/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 23:19:40 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=297</guid>
		<description><![CDATA[<p><img src="http://blog.betabong.com/wp-content/uploads/2009/09/betabits.png" alt="betabits" title="betabits" width="503" height="191" class="alignright size-full wp-image-299" /></p>
<p>I went down a few algorithmic roads recently, digging into path finding and – for some obscure reasons – bit manipulations. Or byte. Whatever.</p>
<p>Along this way some utility methods (or functions) were born, and I thought: May be&#8230; <a href="http://blog.betabong.com/2009/09/22/binary-fun-bits-in-bed-with-actionscript/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/09/01/speed-parsing-string-in-as3/' rel='bookmark' title='Simplicity follows Performance – parsing Strings in Actionscript 3'>Simplicity follows Performance – parsing Strings in Actionscript 3</a></li>
<li><a href='http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/' rel='bookmark' title='Metatunnel 1k Demo: AS vs. JS'>Metatunnel 1k Demo: AS vs. JS</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.betabong.com/wp-content/uploads/2009/09/betabits.png" alt="betabits" title="betabits" width="503" height="191" class="alignright size-full wp-image-299" /></p>
<p>I went down a few algorithmic roads recently, digging into path finding and – for some obscure reasons – bit manipulations. Or byte. Whatever.</p>
<p>Along this way some utility methods (or functions) were born, and I thought: May be some day some of them may be in use to any of you ;)</p>
<p>For my dear non-geeky readers: A bit is the smallest part in software. It&#8217;s either this or that, either 0 or 1, either false or true. With a group of 2 bits you already have 4 states: 00, 01, 10 and 11. With 8 it&#8217;s 256 and so on (2^n).</p>
<p>As it would be too boring to just type 0 or 1, and because we have more than 2 fingers, man invented numbers to accumulate these bits: so 9 stands for 1001, and because 9 is shorter than 1001, we prefer 9. Some even write AB for 10101011, but that&#8217;s where we come back to geeky world.</p>
<p>So after this highly informative introduction, let&#8217;s get to some code. First, let&#8217;s count bits:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> countBits<span style="color: #66cc66;">&#40;</span> value : uint <span style="color: #66cc66;">&#41;</span> : uint <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> count:uint = <span style="color: #cc66cc;">0</span>;
	<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> value <span style="color: #66cc66;">&amp;</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			count++;
		<span style="color: #66cc66;">&#125;</span>
		value <span style="color: #66cc66;">&gt;&gt;&gt;</span>= <span style="color: #cc66cc;">1</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> count;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Example:<br />
countBits( 0xAB ) -> 5</p>
<p>Now sometimes you might wanna know: Does this data contain no more than 1 bit? We could just ask countBits( value ) == 1. But that&#8217;s not as speedy as it should be, right? So here we go:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> is_1_bit<span style="color: #66cc66;">&#40;</span> value : uint <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Boolean</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> count:uint = <span style="color: #cc66cc;">0</span>;
	<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> value <span style="color: #66cc66;">&amp;</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>count == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
			count++;
		<span style="color: #66cc66;">&#125;</span>
		value <span style="color: #66cc66;">&gt;&gt;&gt;</span>= <span style="color: #cc66cc;">1</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> count == <span style="color: #cc66cc;">1</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Examples:<br />
is_1_bit( 0xAB ) -> false<br />
is_1_bit( 0&#215;400 ) -> true</p>
<p>uint are by the way 32bit data, so a maximum of 32 of these bits we&#8217;re talking about can be turned on or off. That&#8217;s a lot of data. 4&#8217;294&#8217;967&#8217;296 combinations (though not that high compared to the numbers we read every day in the newspapers recently). Anyway, sometimes we might wanna access and set only a group of bits (usually 4 or 8) within this quite large row of bits:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getBitGroup<span style="color: #66cc66;">&#40;</span> value : uint , group : uint , len : uint = <span style="color: #cc66cc;">4</span> <span style="color: #66cc66;">&#41;</span> : uint <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span> value <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #66cc66;">&#40;</span>group<span style="color: #66cc66;">*</span>len<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">%</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&lt;&lt;</span> len<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setBitGroup<span style="color: #66cc66;">&#40;</span> value : uint , groupValue :uint , group : uint , len : uint = <span style="color: #cc66cc;">4</span> <span style="color: #66cc66;">&#41;</span> : uint <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> pos:uint = group <span style="color: #66cc66;">*</span> len;
	<span style="color: #000000; font-weight: bold;">var</span> mask:uint = n_bits<span style="color: #66cc66;">&#40;</span>pos<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> right_bits:uint = value <span style="color: #66cc66;">&amp;</span> mask;
	value <span style="color: #66cc66;">&gt;&gt;&gt;</span>= pos + len;
	value <span style="color: #66cc66;">&lt;&lt;</span>= len;
	value <span style="color: #66cc66;">|</span>= groupValue;
	value <span style="color: #66cc66;">&lt;&lt;</span>= pos;
	value <span style="color: #66cc66;">|</span>= right_bits;
	<span style="color: #b1b100;">return</span> value;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Don&#8217;t they look just groovy?! Yeah baby!</p>
<p>Anyway, that&#8217;s all for now. Stay tuned for some crazy path finding. If I find time (sometimes I wonder how all those bloggers find their time to write so much..) Not to mention Twitter. Boohaa.</p>
<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/09/01/speed-parsing-string-in-as3/' rel='bookmark' title='Simplicity follows Performance – parsing Strings in Actionscript 3'>Simplicity follows Performance – parsing Strings in Actionscript 3</a></li>
<li><a href='http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/' rel='bookmark' title='Metatunnel 1k Demo: AS vs. JS'>Metatunnel 1k Demo: AS vs. JS</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2009/09/22/binary-fun-bits-in-bed-with-actionscript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Garbage Collection, Dictionaries and Listeners</title>
		<link>http://blog.betabong.com/2009/09/09/garbage-collection-dictionary-listener/</link>
		<comments>http://blog.betabong.com/2009/09/09/garbage-collection-dictionary-listener/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 17:06:03 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=286</guid>
		<description><![CDATA[<p><a href="http://blog.betabong.com/wp-content/uploads/2009/09/031609_garbage_can.jpg" rel="lightbox[286]"><img src="http://blog.betabong.com/wp-content/uploads/2009/09/031609_garbage_can-211x300.jpg" alt="031609_garbage_can" title="031609_garbage_can" width="211" height="300" class="alignright size-medium wp-image-290" style="float:right; margin-left: 10px;" /></a>As we all know Flash&#8217;s garbage collector is a hell of a beast. It tries to free memory from &#8220;unused&#8221; objects (aka objects not somehow cross-referenced by the root). <strong>So from time to time our garbage collector checks for those</strong>&#8230; <a href="http://blog.betabong.com/2009/09/09/garbage-collection-dictionary-listener/" class="read_more">Read more</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.betabong.com/wp-content/uploads/2009/09/031609_garbage_can.jpg" rel="lightbox[286]"><img src="http://blog.betabong.com/wp-content/uploads/2009/09/031609_garbage_can-211x300.jpg" alt="031609_garbage_can" title="031609_garbage_can" width="211" height="300" class="alignright size-medium wp-image-290" style="float:right; margin-left: 10px;" /></a>As we all know Flash&#8217;s garbage collector is a hell of a beast. It tries to free memory from &#8220;unused&#8221; objects (aka objects not somehow cross-referenced by the root). <strong>So from time to time our garbage collector checks for those objects and kicks them out of memory.. at least some of them.</strong></p>
<p>There are lots of articles written about the garbage collector and I&#8217;m not going into it any deeper. Let&#8217;s just summarize that no developer likes that kind of behaviour &#8212; it&#8217;s totally <strong>unpredictable</strong>. System.gc() would help a little, but it&#8217;s only available to debug players.</p>
<p>You may say: what do you care about memory handling! And I&#8217;d answer: not that much actually! :-) But what I really care about is false behaviour that can result.</p>
<p>Within Flash we have two ways to keep weak references to objects: Dictionary and weak listeners (weak method closures). We use weak references so that objects will be collected by the garbage collector. Now when it comes to Dictionaries, they behave as I&#8217;d expect. A &#8220;dead&#8221; object won&#8217;t be listed in a for each loop. But events events events&#8230;. <strong>they&#8217;ll be dispatched to each and every &#8220;dead&#8221; object residing in memory!! Which is such a pain in the ass really!</strong></p>
<p>After a lot of testing I can give only the advice you&#8217;ve probably heard many times before:</p>
<p><strong>Always remove listeners! Even the weak ones!</strong></p>
<p>Otherwise you have to potentially deal with unexpected behaviour. I may gonna create some utility class for that that deals with this problem.</p>
<p><span id="more-286"></span></p>
<p>Here my testing code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</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;">events</span>.<span style="color: #006600;">MouseEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">TimerEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">system</span>.<span style="color: #0066CC;">System</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">TextFieldAutoSize</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextFormat</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Dictionary</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Timer</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> net.<span style="color: #006600;">hires</span>.<span style="color: #006600;">debug</span>.<span style="color: #006600;">Stats</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MemoryLeakTest <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> counter : uint;
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> dict:Dictionary = <span style="color: #000000; font-weight: bold;">new</span> Dictionary<span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> t:<span style="color: #0066CC;">TextField</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> makeGC:<span style="color: #0066CC;">Boolean</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> switcher:uint;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MemoryLeakTest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			t = <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: #006600;">defaultTextFormat</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextFormat</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #cc66cc;">18</span> , 0x999999 , <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">&#41;</span>;
			t.<span style="color: #0066CC;">autoSize</span> = TextFieldAutoSize.<span style="color: #0066CC;">LEFT</span>;
			addChild<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> timer : Timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#41;</span>;
			timer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>,handleTimer<span style="color: #66cc66;">&#41;</span>;
			timer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>,handleClick<span style="color: #66cc66;">&#41;</span>;
&nbsp;
&nbsp;
			<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> Stats<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> handleTimer<span style="color: #66cc66;">&#40;</span> event : TimerEvent <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			counter = <span style="color: #cc66cc;">0</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> makeGC <span style="color: #66cc66;">&#41;</span> <span style="color: #0066CC;">System</span>.<span style="color: #006600;">gc</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			dispatchEvent<span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">CHANGE</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> i:uint;
			<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #66cc66;">*</span> <span style="color: #b1b100;">in</span> dict <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				i++;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			t.<span style="color: #0066CC;">text</span> = <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Still &quot;</span> + counter + <span style="color: #ff0000;">&quot; dead objects living... (GC &quot;</span> + <span style="color: #66cc66;">&#40;</span>makeGC?<span style="color: #ff0000;">'on'</span>:<span style="color: #ff0000;">'off'</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">')'</span> <span style="color: #66cc66;">&#41;</span>;
			t.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>In dictionary: '</span> + i <span style="color: #66cc66;">&#41;</span>;
			t.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>Click to switch manual Garbage Collection aka System.gc()'</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> switcher++ <span style="color: #66cc66;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">new</span> TestSprite<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">this</span> <span style="color: #66cc66;">&#41;</span>;
				t.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>Added new test object (should live for 10 msec)'</span> <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> handleClick<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>
			makeGC = <span style="color: #66cc66;">!</span>makeGC;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>	
<span style="color: #66cc66;">&#125;</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;">display</span>.<span style="color: #006600;">InteractiveObject</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Timer</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">TimerEvent</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: #0066CC;">system</span>.<span style="color: #0066CC;">System</span>;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> TestSprite <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">// the TestSprite instance should not live longer than 10 msec</span>
&nbsp;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TestSprite<span style="color: #66cc66;">&#40;</span> parent : Sprite <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;">// add to weak dictionary</span>
		<span style="color: #808080; font-style: italic;">//MemoryLeakTest.dict[ this ] = true;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// temporarily add to parent</span>
		parent.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">this</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000000; font-weight: bold;">var</span> timer : Timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#41;</span>;
		timer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>,handleTimer<span style="color: #66cc66;">&#41;</span>;
		timer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// listen (weak!!) to parent event - this is just for control purposes</span>
		parent.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">CHANGE</span> , handleChange , <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>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// let's have those sprites eat some memory while alive</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">cacheAsBitmap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
		graphics.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xff0000,<span style="color: #cc66cc;">0.1</span><span style="color: #66cc66;">&#41;</span>;
		graphics.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">500</span>,<span style="color: #cc66cc;">500</span><span style="color: #66cc66;">&#41;</span>;
		graphics.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> handleTimer<span style="color: #66cc66;">&#40;</span> event : TimerEvent <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#40;</span> event.<span style="color: #0066CC;">target</span> as Timer <span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>,handleTimer<span style="color: #66cc66;">&#41;</span>;
		parent.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> handleChange<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>
		MemoryLeakTest.<span style="color: #006600;">counter</span>++;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2009/09/09/garbage-collection-dictionary-listener/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BBML Presentation at SFUG</title>
		<link>http://blog.betabong.com/2009/04/22/bbml-presentation/</link>
		<comments>http://blog.betabong.com/2009/04/22/bbml-presentation/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 08:02:14 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[bbml]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[sfug]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=262</guid>
		<description><![CDATA[<p>Yesterday I had a presentation at the <a href="http://www.sfug.ch/?p=123">SFUG meeting</a> covering some bits of my rewritten BBML framework (originated from the project laax.com). I&#8217;ve tried to share some insights into the technical concept and strategies for CSS parsing, <a href="http://en.wikipedia.org/wiki/CSS_selector">CSS</a>&#8230; <a href="http://blog.betabong.com/2009/04/22/bbml-presentation/" class="read_more">Read more</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Yesterday I had a presentation at the <a href="http://www.sfug.ch/?p=123">SFUG meeting</a> covering some bits of my rewritten BBML framework (originated from the project laax.com). I&#8217;ve tried to share some insights into the technical concept and strategies for CSS parsing, <a href="http://en.wikipedia.org/wiki/CSS_selector">CSS selectors</a> and layout validation.</p>
<p><img src="http://blog.betabong.com/wp-content/uploads/2009/04/sfug-pres.jpg" alt="Sev presenting..." title="Sev presenting..." width="520" height="390" class="alignnone size-full wp-image-266" /><br />
<small>Picture by <a href="http://www.entropy.ch/about/welcome.html">Marc Liyanage</a></small></p>
<p>It&#8217;s been surprisingly fun (I give credits to the beer sponsored by <a href="http://www.nemos.ch/">Nemos</a>). People even managed to pretend they&#8217;d be interested in what I was prosing, so credit to them too!</p>
<p><a href="http://www.flashatthelake.ch" style="float: right; display: block; margin-left: 10pt; margin-bottom: 10pt;"><img src="http://fatl.ch/banners/fatl_button3_120x60.gif" width="120" height="60" hspace="10" vspace="10" border="0" alt="Flash at the lake Swiss Flash User Group Conference." /></a> I&#8217;d also like to mention that there&#8217;ll be <strong>the</strong> swiss flash event soon: Flash at the Lake will not only pamper you with appearances of <a href="http://fatl.ch/?page_id=16">great national and international Flash enthustiacs</a>, it will also give anybody attending the pleasure to enjoy one of Zurich&#8217;s greatest locations with people who don&#8217;t think of you as a storm lightning adorer when you sit in the sun twittering Flash into the clear lake. And all that to a fantastic price. Check it out at <a href="http://fatl.ch">fatl.ch</a></p>
<p>So here we go with the presentation (<a href="http://www.apple.com/quicktime/download/">Quicktime</a> so you can enjoy the marvelous effects):</p>
<p><object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="520" height="390"><param name="src" value="/wp-content/uploads/2009/04/sfug-presentation-bbml-hq.mov" /><param name="controller" value="true" /><param name="autoplay" value="false" /><param name="scale" value="aspect" /><object type="video/quicktime" data="/wp-content/uploads/2009/04/sfug-presentation-bbml-hq.mov" width="520" height="390">
<param name="autoplay" value="false" /><param name="controller" value="true" /><param name="scale" value="aspect" /></object></object></p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2009/04/22/bbml-presentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MetaTunnel with Pixel Bender</title>
		<link>http://blog.betabong.com/2009/04/17/metatunnel-with-pixel-bender/</link>
		<comments>http://blog.betabong.com/2009/04/17/metatunnel-with-pixel-bender/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 21:37:31 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[Labs]]></category>
		<category><![CDATA[Pixel Bender]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=252</guid>
		<description><![CDATA[<p>This is a follow-up of <a href="/2009/04/13/metatunnel-1k-demo-as-vs-js/">this</a>.</p>
<p><img src="http://blog.betabong.com/wp-content/uploads/2009/04/metatunnel-pixelbender.jpg" alt="metatunnel-pixelbender" title="metatunnel-pixelbender" width="512" height="512" class="alignnone size-full wp-image-254" /></p>
<p>Yeah well, I was more than optimistic to show <a href="http://demoscene.appjet.net/">those JS guys</a> how fast Flash can be with the help of some brand new Adobe magic – but Pixel Bender was, unfortunately,&#8230; <a href="http://blog.betabong.com/2009/04/17/metatunnel-with-pixel-bender/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/' rel='bookmark' title='Metatunnel 1k Demo: AS vs. JS'>Metatunnel 1k Demo: AS vs. JS</a></li>
<li><a href='http://blog.betabong.com/2009/04/13/gridfittype-animation/' rel='bookmark' title='GridFitType (&amp; animation)'>GridFitType (&#038; animation)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This is a follow-up of <a href="/2009/04/13/metatunnel-1k-demo-as-vs-js/">this</a>.</p>
<p><img src="http://blog.betabong.com/wp-content/uploads/2009/04/metatunnel-pixelbender.jpg" alt="metatunnel-pixelbender" title="metatunnel-pixelbender" width="512" height="512" class="alignnone size-full wp-image-254" /></p>
<p>Yeah well, I was more than optimistic to show <a href="http://demoscene.appjet.net/">those JS guys</a> how fast Flash can be with the help of some brand new Adobe magic – but Pixel Bender was, unfortunately, quite disappointing:<br />
<span id="more-252"></span></p>
<ol>
<li>I spent hours to successfully migrate the code to Pixel Bender Toolkit (wasn&#8217;t that difficult actually, but a wrong character there and your math is all screwed up). So here the first letdown: Pixel Bender Toolkit is <strong>not a very nice coding environment</strong>. It&#8217;s a rough baby. But I&#8217;d do everything for speed :-)..</li>
<li>Once I had it running (the above picture is captured from Pixel Bender) I tried to export it for Flash Player. But hoohoo! <strong>no support for loops</strong> in Flash Player! Yeah, well, ..(and also <strong>no custom functions</strong> by the way)</li>
<li>But I didn&#8217;t give up. I just calculated how many max loops where needed (about 100) and replicated the while loop with many if-conditions (I love to do computer&#8217;s dummy job ;). Then finally: Export to Flash Player! But in Flash Player having the shader as Filter for a BitmapData just <strong>really fucked up the rendering</strong>. I even went down to 1fps, but still no luck. What a bummer! (sometimes I saw a few pixels blue, but very unusable: I&#8217;ve written <a href="http://forums.adobe.com/thread/419485">to the Pixel Bender Forum </a>- invited by <a href="http://twitter.com/pixelbender">@Pixelbender</a> – but that led to nothing so far).</li>
<li>Today, finally, I got it working by taking a more rough approach (not BitmapFilter, but ShaderJob). <strong>But hell is it slow!!!</strong> And it eats all my 8 cpu cores!! So I wondered how that could be: Fast as hell in Pixel Bender Toolkit (uses may be 2% of my cpu at full fps!), but slow as hell in Flash Player?! The answer is obvious: <strong>Adobe decided not to talk to the GCU (Graphics Card)</strong> for the calculations, probably to keep the Flash Player be as platform independent as possible &#8211; and as small as possible. But then I wonder.. WTF do you give us this toy if we can&#8217;t use it?!! It&#8217;s like Apple would say: «Great news: we have Core Graphics on the iPhone &#8211; without hardware acceleration..» Adobe, to me, this doesn&#8217;t make too much sense. (But I&#8217;m so very much pleased about the new Text Engine – *that* was a good job)</li>
</ol>
<p>Here the result: (Click to start, it&#8217;ll eat your cpu!)</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="520" height="128">
      <param name="movie" value="/wp-content/uploads/flash/MetaTunnelBender.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="/wp-content/uploads/flash/MetaTunnelBender.swf" width="520" height="128">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>And for the geeks, here we go with the source codes:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>languageVersion <span style="color: #339933;">:</span> <span style="color: #CC0000;">1.0</span><span style="color: #339933;">;&gt;</span>
&nbsp;
kernel MetaTunnel
<span style="color: #339933;">&lt;</span>   <span style="color: #003366; font-weight: bold;">namespace</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;com.betabong&quot;</span><span style="color: #339933;">;</span>
    vendor <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Betabong&quot;</span><span style="color: #339933;">;</span>
    version <span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
    description <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;MetaTunnel Port&quot;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #009900;">&#123;</span>
    parameter int size
    <span style="color: #339933;">&lt;</span>
        minValue<span style="color: #339933;">:</span> <span style="color: #CC0000;">16</span><span style="color: #339933;">;</span>
        maxValue<span style="color: #339933;">:</span> <span style="color: #CC0000;">512</span><span style="color: #339933;">;</span>
        defaultValue<span style="color: #339933;">:</span> <span style="color: #CC0000;">128</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">&gt;;</span>
&nbsp;
&nbsp;
    parameter float time
    <span style="color: #339933;">&lt;</span>
        minValue<span style="color: #339933;">:</span> float<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">0.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        maxValue<span style="color: #339933;">:</span> float<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">15.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        defaultValue<span style="color: #339933;">:</span> float<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">0.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">&gt;;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
    input image4 src<span style="color: #339933;">;</span>
    output pixel3 dst<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">void</span>
    evaluatePixel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        float cos1 <span style="color: #339933;">=</span> cos<span style="color: #009900;">&#40;</span> time <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float cos0_5 <span style="color: #339933;">=</span> cos<span style="color: #009900;">&#40;</span>time <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float cos0_7 <span style="color: #339933;">=</span> cos<span style="color: #009900;">&#40;</span>time <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float sin1 <span style="color: #339933;">=</span> sin<span style="color: #009900;">&#40;</span> time <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float sin0_2 <span style="color: #339933;">=</span> sin<span style="color: #009900;">&#40;</span>time <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float sin_0_5 <span style="color: #339933;">=</span> sin<span style="color: #009900;">&#40;</span>time <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        float dim <span style="color: #339933;">=</span> float<span style="color: #009900;">&#40;</span> size <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float2 point <span style="color: #339933;">=</span> outCoord<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> dim<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> point.<span style="color: #660066;">x</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1.0</span> <span style="color: #339933;">||</span> point.<span style="color: #660066;">y</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1.0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            dst.<span style="color: #660066;">rgb</span> <span style="color: #339933;">=</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">1.0</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">1.0</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">1.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        float2 vp <span style="color: #339933;">=</span> float2<span style="color: #009900;">&#40;</span> point.<span style="color: #660066;">x</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2.0</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1.0</span> <span style="color: #339933;">,</span> <span style="color: #339933;">-</span>point.<span style="color: #660066;">y</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2.0</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float s <span style="color: #339933;">=</span> float<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">0.4</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float3 op <span style="color: #339933;">=</span> float3<span style="color: #009900;">&#40;</span> vp.<span style="color: #660066;">x</span> <span style="color: #339933;">,</span> vp.<span style="color: #660066;">y</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">1.25</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float3 dp <span style="color: #339933;">=</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>vp.<span style="color: #660066;">x</span> <span style="color: #339933;">+</span> cos1 <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">64.0</span> <span style="color: #339933;">,</span> vp.<span style="color: #660066;">y</span><span style="color: #339933;">/</span><span style="color: #CC0000;">64.0</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">1.0</span><span style="color: #339933;">/</span><span style="color: #CC0000;">64.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float f <span style="color: #339933;">=</span> float<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">1.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        float tt <span style="color: #339933;">=</span> float<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">0.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float g <span style="color: #339933;">=</span> float<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">1.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        float3 p <span style="color: #339933;">=</span> float3<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1.0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1.0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1.0</span><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: #009900;">&#40;</span>g <span style="color: #339933;">&gt;</span> s<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>tt<span style="color: #339933;">&lt;</span><span style="color: #CC0000;">375.0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            p <span style="color: #339933;">=</span> op <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span> dp <span style="color: #339933;">*</span> tt <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            f <span style="color: #339933;">=</span> <span style="color: #CC0000;">1.0</span><span style="color: #339933;">;</span>
            f <span style="color: #339933;">*=</span> abs<span style="color: #009900;">&#40;</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> cos1<span style="color: #339933;">+</span>sin0_2 <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span><span style="color: #339933;">+</span>cos0_5<span style="color: #339933;">*</span><span style="color: #CC0000;">0.5</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            f <span style="color: #339933;">*=</span> abs<span style="color: #009900;">&#40;</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span>cos0_7 <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span><span style="color: #339933;">+</span>sin_0_5 <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            f <span style="color: #339933;">*=</span> abs<span style="color: #009900;">&#40;</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span>sin0_2<span style="color: #339933;">*</span><span style="color: #CC0000;">0.5</span> <span style="color: #339933;">,</span> sin1 <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            f <span style="color: #339933;">*=</span> cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">0.1</span> <span style="color: #339933;">-</span> cos<span style="color: #009900;">&#40;</span> p.<span style="color: #660066;">z</span><span style="color: #339933;">*</span><span style="color: #CC0000;">7.0</span> <span style="color: #339933;">+</span> time<span style="color: #339933;">*</span><span style="color: #CC0000;">7.0</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #339933;">*</span><span style="color: #CC0000;">3.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span><span style="color: #339933;">*</span><span style="color: #CC0000;">4.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">;</span>
            g <span style="color: #339933;">=</span> f<span style="color: #339933;">;</span>
            tt <span style="color: #339933;">+=</span> g <span style="color: #339933;">*</span> <span style="color: #CC0000;">4.0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        float color <span style="color: #339933;">=</span> <span style="color: #CC0000;">0.0</span><span style="color: #339933;">;</span>
        float3 dtt <span style="color: #339933;">=</span> op <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span> dp <span style="color: #339933;">*</span> tt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        p <span style="color: #339933;">=</span> float3<span style="color: #009900;">&#40;</span> dtt.<span style="color: #660066;">x</span> <span style="color: #339933;">,</span> dtt.<span style="color: #660066;">y</span> <span style="color: #339933;">,</span> dtt.<span style="color: #660066;">z</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">=</span> <span style="color: #CC0000;">1.0</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> cos1<span style="color: #339933;">+</span>sin0_2 <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span><span style="color: #339933;">+</span>cos0_5<span style="color: #339933;">*</span><span style="color: #CC0000;">0.5</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span>cos0_7 <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span><span style="color: #339933;">+</span>sin_0_5 <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span>sin0_2<span style="color: #339933;">*</span><span style="color: #CC0000;">0.5</span> <span style="color: #339933;">,</span> sin1 <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">-</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">z</span><span style="color: #339933;">*</span><span style="color: #CC0000;">7.0</span><span style="color: #339933;">+</span>time<span style="color: #339933;">*</span><span style="color: #CC0000;">7.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #339933;">*</span><span style="color: #CC0000;">3.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span><span style="color: #339933;">*</span><span style="color: #CC0000;">4.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">;</span>
        float objd <span style="color: #339933;">=</span> f<span style="color: #339933;">;</span>
&nbsp;
        float3 np <span style="color: #339933;">=</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">0.0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0.0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0.0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        p <span style="color: #339933;">=</span> float3<span style="color: #009900;">&#40;</span> dtt.<span style="color: #660066;">x</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.01</span> <span style="color: #339933;">,</span> dtt.<span style="color: #660066;">y</span> <span style="color: #339933;">,</span> dtt.<span style="color: #660066;">z</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">=</span> <span style="color: #CC0000;">1.0</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> cos1<span style="color: #339933;">+</span>sin0_2 <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span><span style="color: #339933;">+</span>cos0_5<span style="color: #339933;">*</span><span style="color: #CC0000;">0.5</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span>cos0_7 <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span><span style="color: #339933;">+</span>sin_0_5 <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span>sin0_2<span style="color: #339933;">*</span><span style="color: #CC0000;">0.5</span> <span style="color: #339933;">,</span> sin1 <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">-</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">z</span><span style="color: #339933;">*</span><span style="color: #CC0000;">7.0</span><span style="color: #339933;">+</span>time<span style="color: #339933;">*</span><span style="color: #CC0000;">7.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #339933;">*</span><span style="color: #CC0000;">3.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span><span style="color: #339933;">*</span><span style="color: #CC0000;">4.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">;</span>
        np.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> objd <span style="color: #339933;">-</span> f<span style="color: #339933;">;</span>
&nbsp;
        p <span style="color: #339933;">=</span> float3<span style="color: #009900;">&#40;</span> dtt.<span style="color: #660066;">x</span> <span style="color: #339933;">,</span> dtt.<span style="color: #660066;">y</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.01</span> <span style="color: #339933;">,</span> dtt.<span style="color: #660066;">z</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">=</span> <span style="color: #CC0000;">1.0</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> cos1<span style="color: #339933;">+</span>sin0_2 <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span><span style="color: #339933;">+</span>cos0_5<span style="color: #339933;">*</span><span style="color: #CC0000;">0.5</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span>cos0_7 <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span><span style="color: #339933;">+</span>sin_0_5 <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span>sin0_2<span style="color: #339933;">*</span><span style="color: #CC0000;">0.5</span> <span style="color: #339933;">,</span> sin1 <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">-</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">z</span><span style="color: #339933;">*</span><span style="color: #CC0000;">7.0</span><span style="color: #339933;">+</span>time<span style="color: #339933;">*</span><span style="color: #CC0000;">7.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #339933;">*</span><span style="color: #CC0000;">3.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span><span style="color: #339933;">*</span><span style="color: #CC0000;">4.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">;</span>
        np.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> objd <span style="color: #339933;">-</span> f<span style="color: #339933;">;</span>
&nbsp;
        p <span style="color: #339933;">=</span> float3<span style="color: #009900;">&#40;</span> dtt.<span style="color: #660066;">x</span> <span style="color: #339933;">,</span> dtt.<span style="color: #660066;">y</span> <span style="color: #339933;">,</span> dtt.<span style="color: #660066;">z</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.01</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">=</span> <span style="color: #CC0000;">1.0</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> cos1<span style="color: #339933;">+</span>sin0_2 <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span><span style="color: #339933;">+</span>cos0_5<span style="color: #339933;">*</span><span style="color: #CC0000;">0.5</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span>cos0_7 <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span><span style="color: #339933;">+</span>sin_0_5 <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            f <span style="color: #339933;">*=</span> distance<span style="color: #009900;">&#40;</span> float3<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span>sin0_2<span style="color: #339933;">*</span><span style="color: #CC0000;">0.5</span> <span style="color: #339933;">,</span> sin1 <span style="color: #339933;">,</span> <span style="color: #CC0000;">2.0</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> p <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        f <span style="color: #339933;">*=</span> cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">-</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">z</span><span style="color: #339933;">*</span><span style="color: #CC0000;">7.0</span><span style="color: #339933;">+</span>time<span style="color: #339933;">*</span><span style="color: #CC0000;">7.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">x</span><span style="color: #339933;">*</span><span style="color: #CC0000;">3.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>cos<span style="color: #009900;">&#40;</span>p.<span style="color: #660066;">y</span><span style="color: #339933;">*</span><span style="color: #CC0000;">4.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #CC0000;">0.1</span><span style="color: #339933;">;</span>
        np.<span style="color: #660066;">z</span> <span style="color: #339933;">=</span> objd <span style="color: #339933;">-</span> f<span style="color: #339933;">;</span>
&nbsp;
        float d <span style="color: #339933;">=</span> length<span style="color: #009900;">&#40;</span> np <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        np.<span style="color: #660066;">y</span> <span style="color: #339933;">/=</span> d<span style="color: #339933;">;</span>
        np.<span style="color: #660066;">z</span> <span style="color: #339933;">/=</span> d<span style="color: #339933;">;</span>
&nbsp;
        color <span style="color: #339933;">=</span> max<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">0.5</span> <span style="color: #339933;">*</span> np.<span style="color: #660066;">z</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.0</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> max<span style="color: #009900;">&#40;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">0.5</span> <span style="color: #339933;">*</span>np.<span style="color: #660066;">y</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.5</span> <span style="color: #339933;">*</span> np.<span style="color: #660066;">z</span> <span style="color: #339933;">,</span> <span style="color: #CC0000;">0.0</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.5</span><span style="color: #339933;">;</span>
        float3 rgb <span style="color: #339933;">=</span> float3<span style="color: #009900;">&#40;</span>color  <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.1</span> <span style="color: #339933;">*</span> tt <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.025</span> <span style="color: #339933;">,</span> color  <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.2</span> <span style="color: #339933;">*</span> tt <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.025</span>  <span style="color: #339933;">,</span> color <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.5</span> <span style="color: #339933;">*</span> tt <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.025</span>   <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        rgb.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> max<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">0.0</span> <span style="color: #339933;">,</span> min<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">1.0</span> <span style="color: #339933;">,</span> rgb.<span style="color: #660066;">x</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        rgb.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> max<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">0.0</span> <span style="color: #339933;">,</span> min<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">1.0</span> <span style="color: #339933;">,</span> rgb.<span style="color: #660066;">y</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        rgb.<span style="color: #660066;">z</span> <span style="color: #339933;">=</span> max<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">0.0</span> <span style="color: #339933;">,</span> min<span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">1.0</span> <span style="color: #339933;">,</span> rgb.<span style="color: #660066;">z</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        dst.<span style="color: #660066;">rgb</span> <span style="color: #339933;">=</span> rgb<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
      <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And here the Actionscript part:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
 <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #66cc66;">*</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filters</span>.<span style="color: #66cc66;">*</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #66cc66;">*</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
&nbsp;
    <span style="color: #0066CC;">import</span> net.<span style="color: #006600;">hires</span>.<span style="color: #006600;">debug</span>.<span style="color: #006600;">Stats</span>;
    <span style="color: #808080; font-style: italic;">// SWF Metadata </span>
    <span style="color: #66cc66;">&#91;</span>SWF<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span> = <span style="color: #ff0000;">&quot;520&quot;</span>, <span style="color: #0066CC;">height</span> = <span style="color: #ff0000;">&quot;128&quot;</span>, <span style="color: #0066CC;">backgroundColor</span> = <span style="color: #ff0000;">&quot;#000000&quot;</span>, framerate = <span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MetaTunnelBender <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;test/MetaTunnel-stupid.pbj&quot;</span>, mimeType = <span style="color: #ff0000;">&quot;application/octet-stream&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> TestFilter: <span style="color: #000000; font-weight: bold;">Class</span>;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> playing : <span style="color: #0066CC;">Boolean</span>;
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> im: Bitmap;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> job:ShaderJob;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> shader: Shader;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> shaderfilter:ByteArray;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">time</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0.0</span>;
        <span style="color: #0066CC;">private</span> const <span style="color: #0066CC;">SIZE</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">64</span>;
        <span style="color: #0066CC;">private</span> const WHITE:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">SIZE</span> , <span style="color: #0066CC;">SIZE</span> , <span style="color: #000000; font-weight: bold;">false</span> , 0xffffff <span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MetaTunnelBender<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: #006600;">frameRate</span> = <span style="color: #cc66cc;">20</span>;
            im = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span> WHITE.<span style="color: #006600;">clone</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
            im.<span style="color: #006600;">scaleX</span> = im.<span style="color: #006600;">scaleY</span> = <span style="color: #cc66cc;">2</span>;
            addChild<span style="color: #66cc66;">&#40;</span>im<span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// stat info</span>
            <span style="color: #000000; font-weight: bold;">var</span> s:DisplayObject = <span style="color: #000000; font-weight: bold;">new</span> Stats<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            addChild<span style="color: #66cc66;">&#40;</span> s <span style="color: #66cc66;">&#41;</span>;
            s.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">128</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">//Pass the embedded filter to the Shader as a ByteArray </span>
            shaderfilter = <span style="color: #000000; font-weight: bold;">new</span> TestFilter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ByteArray;
            shader = <span style="color: #000000; font-weight: bold;">new</span> Shader<span style="color: #66cc66;">&#40;</span> shaderfilter <span style="color: #66cc66;">&#41;</span>;
            shader.<span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">size</span>.<span style="color: #006600;">value</span> = <span style="color: #66cc66;">&#91;</span> <span style="color: #0066CC;">SIZE</span> <span style="color: #66cc66;">&#93;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">//start shaderjob (async start won't work - bug?)            </span>
            job = <span style="color: #000000; font-weight: bold;">new</span> ShaderJob<span style="color: #66cc66;">&#40;</span> shader , im.<span style="color: #006600;">bitmapData</span> , im.<span style="color: #0066CC;">width</span> , im.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">&#41;</span>;
			job.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// let's start/stop on click</span>
			<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">CLICK</span> , click <span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// render first frame</span>
			enterframe<span style="color: #66cc66;">&#40;</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> enterframe<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        	<span style="color: #0066CC;">time</span> += <span style="color: #cc66cc;">0.05</span>;
			shader.<span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">time</span>.<span style="color: #006600;">value</span> = <span style="color: #66cc66;">&#91;</span> <span style="color: #0066CC;">time</span> <span style="color: #66cc66;">&#93;</span>;
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> job.<span style="color: #006600;">progress</span> <span style="color: #66cc66;">&#41;</span>;
            job = <span style="color: #000000; font-weight: bold;">new</span> ShaderJob<span style="color: #66cc66;">&#40;</span> shader , im.<span style="color: #006600;">bitmapData</span> , im.<span style="color: #0066CC;">width</span> , im.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">&#41;</span>;
			job.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</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> click<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:<span style="color: #66cc66;">*</span> = <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span>playing <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	           addEventListener<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span> , enterframe <span style="color: #66cc66;">&#41;</span>;
	        <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
	           removeEventListener<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span> , enterframe <span style="color: #66cc66;">&#41;</span>;
	        <span style="color: #66cc66;">&#125;</span>
	        playing = <span style="color: #66cc66;">!</span>playing;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/' rel='bookmark' title='Metatunnel 1k Demo: AS vs. JS'>Metatunnel 1k Demo: AS vs. JS</a></li>
<li><a href='http://blog.betabong.com/2009/04/13/gridfittype-animation/' rel='bookmark' title='GridFitType (&amp; animation)'>GridFitType (&#038; animation)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2009/04/17/metatunnel-with-pixel-bender/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Metatunnel 1k Demo: AS vs. JS</title>
		<link>http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/</link>
		<comments>http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 10:16:17 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=245</guid>
		<description><![CDATA[<p>I did a quick port of a «graphic demo» called <a href="http://www.pouet.net/prod.php?which=52777">«metatunnel» (created by FRequency).</a></p>
<p><a href="http://demoscene.appjet.net/">Paulo Falcão ported this to Javascript</a> using canvas.</p>
<p>To make the set complete I ported Paulos JS version to Actionscript, just quick&#8217;n'dirty.</p>
<p>Click on it&#8230; <a href="http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2009/04/17/metatunnel-with-pixel-bender/' rel='bookmark' title='MetaTunnel with Pixel Bender'>MetaTunnel with Pixel Bender</a></li>
<li><a href='http://blog.betabong.com/2008/09/26/weak-method-closure/' rel='bookmark' title='Weak Method Closure'>Weak Method Closure</a></li>
<li><a href='http://blog.betabong.com/2009/03/05/javascript-canvas-3d/' rel='bookmark' title='3D Point Cloud with Javascript and Canvas'>3D Point Cloud with Javascript and Canvas</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I did a quick port of a «graphic demo» called <a href="http://www.pouet.net/prod.php?which=52777">«metatunnel» (created by FRequency).</a></p>
<p><a href="http://demoscene.appjet.net/">Paulo Falcão ported this to Javascript</a> using canvas.</p>
<p>To make the set complete I ported Paulos JS version to Actionscript, just quick&#8217;n'dirty.</p>
<p>Click on it to start the animation:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="128" height="128">
      <param name="movie" value="/wp-content/uploads/flash/MetaTunnel.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="/wp-content/uploads/flash/MetaTunnel.swf" width="128" height="128">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p><span id="more-245"></span></p>
<p>Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package test
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapData</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;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JSCanvasPort <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> JSCanvasPort<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> canvas = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
			canvas.<span style="color: #0066CC;">smoothing</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			canvas.<span style="color: #006600;">scaleX</span> = canvas.<span style="color: #006600;">scaleY</span> = <span style="color: #cc66cc;">2</span>;
			draw<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			addEventListener<span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">CLICK</span> , handleClick <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;">var</span> playing:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> handleClick<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> playing <span style="color: #66cc66;">&#41;</span>
				removeEventListener<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span> , enterframe <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">else</span>
				addEventListener<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span> , enterframe <span style="color: #66cc66;">&#41;</span>;
			playing = <span style="color: #66cc66;">!</span>playing;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> enterframe<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:Event=<span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			draw<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">time</span>:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> maxr:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">64.0</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> canvas:Bitmap;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> distance<span style="color: #66cc66;">&#40;</span>ax:<span style="color: #0066CC;">Number</span>,ay:<span style="color: #0066CC;">Number</span>,az:<span style="color: #0066CC;">Number</span>,bx:<span style="color: #0066CC;">Number</span>,by:<span style="color: #0066CC;">Number</span>,bz:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> dx:<span style="color: #0066CC;">Number</span>=bx-ax , dy:<span style="color: #0066CC;">Number</span>=by-ay , dz:<span style="color: #0066CC;">Number</span>=bz-az;
		    <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sqrt</span><span style="color: #66cc66;">&#40;</span> dx<span style="color: #66cc66;">*</span>dx + dy<span style="color: #66cc66;">*</span>dy + dz<span style="color: #66cc66;">*</span>dz <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> obj<span style="color: #66cc66;">&#40;</span>x:<span style="color: #0066CC;">Number</span>,y:<span style="color: #0066CC;">Number</span>,z:<span style="color: #0066CC;">Number</span>,t:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#123;</span>
		        <span style="color: #000000; font-weight: bold;">var</span> f:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">1.0</span>;
		        f<span style="color: #66cc66;">*</span>=distance<span style="color: #66cc66;">&#40;</span>x,y,z,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span>+<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.2</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #cc66cc;">0.3</span>,<span style="color: #cc66cc;">2.0</span>+<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">&#41;</span>;
		        f<span style="color: #66cc66;">*</span>=distance<span style="color: #66cc66;">&#40;</span>x,y,z,-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.7</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #cc66cc;">0.3</span>,<span style="color: #cc66cc;">2.0</span>+<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		        f<span style="color: #66cc66;">*</span>=distance<span style="color: #66cc66;">&#40;</span>x,y,z,-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.5</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span>,<span style="color: #cc66cc;">2.0</span><span style="color: #66cc66;">&#41;</span>;
		        f<span style="color: #66cc66;">*</span>=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#41;</span>-<span style="color: #cc66cc;">0.1</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>z<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">7.0</span>+t<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">7.0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">3.0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>y<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">4.0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.1</span>;
		        <span style="color: #b1b100;">return</span> f;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">eval</span><span style="color: #66cc66;">&#40;</span>x:<span style="color: #0066CC;">Number</span>,y:<span style="color: #0066CC;">Number</span>,t:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:uint<span style="color: #66cc66;">&#123;</span>
		   <span style="color: #000000; font-weight: bold;">var</span> vx:<span style="color: #0066CC;">Number</span>=x<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">2.0</span>-<span style="color: #cc66cc;">1.0</span>; <span style="color: #000000; font-weight: bold;">var</span> vy:<span style="color: #0066CC;">Number</span>=-y<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">2.0</span>+<span style="color: #cc66cc;">1.0</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0.4</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> ox:<span style="color: #0066CC;">Number</span>=vx;var oy:<span style="color: #0066CC;">Number</span>=vy<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1.25</span>;var oz:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0.0</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> dx:<span style="color: #0066CC;">Number</span>=<span style="color: #66cc66;">&#40;</span>vx+<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">64.0</span>;var dy:<span style="color: #0066CC;">Number</span>=vy<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">64.0</span>;var dz:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">1.0</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">64.0</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> tt:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0.0</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> g:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">1.0</span>;
		   <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>g<span style="color: #66cc66;">&amp;</span>gt;s<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&amp;</span>amp;<span style="color: #66cc66;">&amp;</span>amp;<span style="color: #66cc66;">&#40;</span>tt<span style="color: #66cc66;">&amp;</span>lt;<span style="color: #cc66cc;">375</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		         g=obj<span style="color: #66cc66;">&#40;</span>ox+dx<span style="color: #66cc66;">*</span>tt,oy+dy<span style="color: #66cc66;">*</span>tt,oz+dz<span style="color: #66cc66;">*</span>tt,t<span style="color: #66cc66;">&#41;</span>;
		         tt+=g<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">4</span>;
		   <span style="color: #66cc66;">&#125;</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">color</span>:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0.0</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> dxtt:<span style="color: #0066CC;">Number</span>=ox+dx<span style="color: #66cc66;">*</span>tt;var dytt:<span style="color: #0066CC;">Number</span>=oy+dy<span style="color: #66cc66;">*</span>tt;var dztt:<span style="color: #0066CC;">Number</span>=oz+dz<span style="color: #66cc66;">*</span>tt;
		   <span style="color: #000000; font-weight: bold;">var</span> objd:<span style="color: #0066CC;">Number</span>=obj<span style="color: #66cc66;">&#40;</span>dxtt,dytt,dztt,t<span style="color: #66cc66;">&#41;</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> nx:<span style="color: #0066CC;">Number</span>=objd-obj<span style="color: #66cc66;">&#40;</span>dxtt+<span style="color: #cc66cc;">0.01</span>,dytt,dztt,t<span style="color: #66cc66;">&#41;</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> ny:<span style="color: #0066CC;">Number</span>=objd-obj<span style="color: #66cc66;">&#40;</span>dxtt,dytt+<span style="color: #cc66cc;">0.01</span>,dztt,t<span style="color: #66cc66;">&#41;</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> nz:<span style="color: #0066CC;">Number</span>=objd-obj<span style="color: #66cc66;">&#40;</span>dxtt,dytt,dztt+<span style="color: #cc66cc;">0.01</span>,t<span style="color: #66cc66;">&#41;</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> d:<span style="color: #0066CC;">Number</span>=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sqrt</span><span style="color: #66cc66;">&#40;</span>nx<span style="color: #66cc66;">*</span>nx+ny<span style="color: #66cc66;">*</span>ny+nz<span style="color: #66cc66;">*</span>nz<span style="color: #66cc66;">&#41;</span>;ny=ny<span style="color: #66cc66;">/</span>d;nz=nz<span style="color: #66cc66;">/</span>d;
		   <span style="color: #0066CC;">color</span>+=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">max</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">*</span>nz,<span style="color: #cc66cc;">0.0</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">max</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">*</span>ny+<span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">*</span>nz,<span style="color: #cc66cc;">0.0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.5</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> r:<span style="color: #0066CC;">Number</span>=<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">color</span>+<span style="color: #cc66cc;">0.1</span><span style="color: #66cc66;">*</span>tt<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.025</span><span style="color: #66cc66;">&#41;</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> g:<span style="color: #0066CC;">Number</span>=<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">color</span>+<span style="color: #cc66cc;">0.2</span><span style="color: #66cc66;">*</span>tt<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.025</span><span style="color: #66cc66;">&#41;</span>;
		   <span style="color: #000000; font-weight: bold;">var</span> b:<span style="color: #0066CC;">Number</span>=<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">color</span>+<span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">*</span>tt<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">0.025</span><span style="color: #66cc66;">&#41;</span>;
		   <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">getRGB</span><span style="color: #66cc66;">&#40;</span>r,g,b<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">getRGB</span><span style="color: #66cc66;">&#40;</span>r:<span style="color: #0066CC;">Number</span>,g:<span style="color: #0066CC;">Number</span>,b:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:uint<span style="color: #66cc66;">&#123;</span>
		        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>r<span style="color: #66cc66;">&amp;</span>lt;<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> r=<span style="color: #cc66cc;">0</span>; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>r<span style="color: #66cc66;">&amp;</span>gt;<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> r=<span style="color: #cc66cc;">1</span>;
		        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>g<span style="color: #66cc66;">&amp;</span>lt;<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> g=<span style="color: #cc66cc;">0</span>; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>g<span style="color: #66cc66;">&amp;</span>gt;<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> g=<span style="color: #cc66cc;">1</span>;
		        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&amp;</span>lt;<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> b=<span style="color: #cc66cc;">0</span>; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&amp;</span>gt;<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> b=<span style="color: #cc66cc;">1</span>;
			<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>r<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&amp;</span>amp;<span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;</span>lt;<span style="color: #66cc66;">&amp;</span>lt; <span style="color: #cc66cc;">16</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>g<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&amp;</span>amp;<span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;</span>lt;<span style="color: #66cc66;">&amp;</span>lt; <span style="color: #cc66cc;">8</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&amp;</span>amp;<span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> draw<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: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> canvas.<span style="color: #006600;">bitmapData</span> == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				canvas.<span style="color: #006600;">bitmapData</span> = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span> maxr , maxr , <span style="color: #000000; font-weight: bold;">false</span> , 0xffffff <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">var</span> t:BitmapData = canvas.<span style="color: #006600;">bitmapData</span>;
			<span style="color: #0066CC;">time</span>+=<span style="color: #cc66cc;">0.1</span>;
			t.<span style="color: #006600;">lock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		        <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> x:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>;x<span style="color: #66cc66;">&lt;</span>maxr;x++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		                <span style="color: #000000; font-weight: bold;">var</span> px:<span style="color: #0066CC;">Number</span>=x<span style="color: #66cc66;">/</span>maxr;
		                <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> y:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>;y<span style="color: #66cc66;">&lt;</span>maxr;y++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		                        <span style="color: #000000; font-weight: bold;">var</span> py:<span style="color: #0066CC;">Number</span>=y<span style="color: #66cc66;">/</span>maxr;
		                        t.<span style="color: #006600;">setPixel</span><span style="color: #66cc66;">&#40;</span> x , y , <span style="color: #0066CC;">eval</span><span style="color: #66cc66;">&#40;</span>px,py,<span style="color: #0066CC;">time</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
		                <span style="color: #66cc66;">&#125;</span>
		        <span style="color: #66cc66;">&#125;</span>
		   t.<span style="color: #006600;">unlock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Update:</strong> A quickly optimized version (nothing advanced really).</p>
<p>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="128" height="128">
      <param name="movie" value="/wp-content/uploads/flash/MetaTunnel-optim-1.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="/wp-content/uploads/flash/MetaTunnel-optim-1.swf" width="128" height="128">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
(You can switch quality in this version with key up or down).</p>
<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2009/04/17/metatunnel-with-pixel-bender/' rel='bookmark' title='MetaTunnel with Pixel Bender'>MetaTunnel with Pixel Bender</a></li>
<li><a href='http://blog.betabong.com/2008/09/26/weak-method-closure/' rel='bookmark' title='Weak Method Closure'>Weak Method Closure</a></li>
<li><a href='http://blog.betabong.com/2009/03/05/javascript-canvas-3d/' rel='bookmark' title='3D Point Cloud with Javascript and Canvas'>3D Point Cloud with Javascript and Canvas</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GridFitType (&amp; animation)</title>
		<link>http://blog.betabong.com/2009/04/13/gridfittype-animation/</link>
		<comments>http://blog.betabong.com/2009/04/13/gridfittype-animation/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 23:02:58 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Rendering]]></category>
		<category><![CDATA[Text]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=242</guid>
		<description><![CDATA[<p>GridFitType has a great impact on Text rendering:</p>
<p>Well not really much to say here:</p>
<ul>
<li><strong>NONE</strong> Good for animation and people who prefer Font appearance over readability</li>
<li><strong>SUBPIXEL</strong> Good compromise between readability (small sizes) and appearance</li>
<li><strong>PIXEL</strong> Pure nonsense</li></ul><p>&#8230; <a href="http://blog.betabong.com/2009/04/13/gridfittype-animation/" class="read_more">Read more</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>GridFitType has a great impact on Text rendering:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_3" width="520" height="350">
      <param name="movie" value="/wp-content/uploads/flash/GridFitType/GridFitType.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="/wp-content/uploads/flash/GridFitType/GridFitType.swf" width="520" height="350">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>Well not really much to say here:</p>
<ul>
<li><strong>NONE</strong> Good for animation and people who prefer Font appearance over readability</li>
<li><strong>SUBPIXEL</strong> Good compromise between readability (small sizes) and appearance</li>
<li><strong>PIXEL</strong> Pure nonsense if you ask me</li>
</ul>
<p>What I really wonder though is: <strong>Why on earth can&#8217;t I adjust fractioned text sizes</strong> (aka float)??? In the IDE, yes you can. By actionscript, no you can&#8217;t. I don&#8217;t get it.. anybody knows why that is? And more importantly: is there some fancy workaround? (in the example I&#8217;m just scaling the text fields, but that&#8217;s not really a cool solution).</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2009/04/13/gridfittype-animation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bug Hunting: Shadowed 3D and ScrollRect</title>
		<link>http://blog.betabong.com/2009/04/01/bug-hunting-shadowed-3d-and-scrollrect/</link>
		<comments>http://blog.betabong.com/2009/04/01/bug-hunting-shadowed-3d-and-scrollrect/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 16:02:05 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flash Player]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=217</guid>
		<description><![CDATA[<p>I don&#8217;t discover as many bugs nowadays as I&#8217;ve used to in the old days when I was beta testing for Macromedia. But it happened today, and I&#8217;ve just installed the newest Flash Player 10.0.22.87 to be sure.</p>
<p>It happens&#8230; <a href="http://blog.betabong.com/2009/04/01/bug-hunting-shadowed-3d-and-scrollrect/" class="read_more">Read more</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t discover as many bugs nowadays as I&#8217;ve used to in the old days when I was beta testing for Macromedia. But it happened today, and I&#8217;ve just installed the newest Flash Player 10.0.22.87 to be sure.</p>
<p>It happens to DisplayObjects A inside DisplayObjectContainers B inside DisplayObjectContainer C, when</p>
<ul>
<li>A was not initially visible (not inside initial scroll rect of C)</li>
<li>A is in 3D mode (I just change rotationY for that)</li>
<li>B is in «cached as Bitmap» (cacheAsBitmap would do, I go with DropShadowFilter in the example)</li>
<li>C&#8217;s scrollrect property is set, so A is shows up (well, it doesn&#8217;t – that&#8217;s the bug after all ;)</li>
</ul>
<p>Here the example:</p>
<div style="padding: 10px; background-color: #eee;"><object width="500" height="200" data="/wp-content/uploads/2009/04/bug-3d-shadow.swf" type="application/x-shockwave-flash"><param name="id" value="Bug-3D-Shadow" /><param name="align" value="middle" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="src" value="/wp-content/uploads/2009/04/bug-3d-shadow.swf" /><param name="name" value="Bug-3D-Shadow" /><param name="allowfullscreen" value="false" /></object></div>
<p><a href="http://blog.betabong.com/wp-content/uploads/2009/04/bug-3d-shadow.swf">bug-3d-shadow.swf</a><br />
<span id="more-217"></span><br />
And here the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Flash Bug - Flash Player 10.0.22.87
	disappearance when 3d's parent has shadow
	more info: betabong@gmail.com
*/</span>
&nbsp;
<span style="color: #0066CC;">this</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;">this</span>.<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span> = StageAlign.<span style="color: #006600;">TOP_LEFT</span>;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> scroller:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span> scroller <span style="color: #66cc66;">&#41;</span>;
scroller = <span style="color: #0066CC;">this</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> filter:DropShadowFilter = <span style="color: #000000; font-weight: bold;">new</span> DropShadowFilter<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">2</span> , <span style="color: #cc66cc;">90</span> , <span style="color: #cc66cc;">0</span> , <span style="color: #cc66cc;">0.5</span> , <span style="color: #cc66cc;">8</span> , <span style="color: #cc66cc;">8</span> , <span style="color: #cc66cc;">1</span> , <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> r:Sprite,rect:Sprite;
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> mode:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span> ; mode<span style="color: #66cc66;">&lt;</span>=<span style="color: #cc66cc;">1</span> ; mode++ <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span> ; i<span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">3000</span> ; i+=<span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		r = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		r.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span> rect = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
		rect.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span> 0xff0000 <span style="color: #66cc66;">&#41;</span>;
		rect.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span> -<span style="color: #cc66cc;">40</span> , -<span style="color: #cc66cc;">40</span> , <span style="color: #cc66cc;">80</span> , <span style="color: #cc66cc;">80</span> <span style="color: #66cc66;">&#41;</span>;
		rect.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		rect.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span> , rotate <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span>mode <span style="color: #66cc66;">&#41;</span> r.<span style="color: #006600;">cacheAsBitmap</span> = <span style="color: #000000; font-weight: bold;">true</span>; <span style="color: #808080; font-style: italic;">//r.filters = [ filter ];</span>
		r.<span style="color: #006600;">y</span> = i + <span style="color: #cc66cc;">100</span>;
		r.<span style="color: #006600;">x</span> = mode <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">150</span> + <span style="color: #cc66cc;">100</span>;
		addChild<span style="color: #66cc66;">&#40;</span> r <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span> , move <span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">scroll</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #000000; font-weight: bold;">function</span> move<span style="color: #66cc66;">&#40;</span> event:Event <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">scroll</span> += <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">mouseY</span> - <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">50</span>;
	scroller.<span style="color: #006600;">scrollRect</span> = <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">0</span> , <span style="color: #0066CC;">scroll</span> , <span style="color: #cc66cc;">500</span> , <span style="color: #cc66cc;">200</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> rotate<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">rotationY</span>++;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Update:</strong> Now that: it took me about 20 min to file a bug in the Adobe Bug System (which is slow as hell anyway). And when I want to submit it, I get a message saying they&#8217;d be in maintenance. Well, buggy bug systems piss me off quite a bit.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2009/04/01/bug-hunting-shadowed-3d-and-scrollrect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embed Assets in Flash Project</title>
		<link>http://blog.betabong.com/2009/02/13/embed-assets-in-flash-project/</link>
		<comments>http://blog.betabong.com/2009/02/13/embed-assets-in-flash-project/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 13:00:18 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flash IDE]]></category>
		<category><![CDATA[Flex Builder]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=190</guid>
		<description><![CDATA[<p>There&#8217;s still quite a gap between Flash and Flex – while Flash is great for creating animations, vector symbols and just keeping little assets within one place, Flex Builder is so very much better for anything code. So how to&#8230; <a href="http://blog.betabong.com/2009/02/13/embed-assets-in-flash-project/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/12/03/test-movie-from-flex-to-flash-easy-way/' rel='bookmark' title='Test Movie from Flex to Flash (easy way)'>Test Movie from Flex to Flash (easy way)</a></li>
<li><a href='http://blog.betabong.com/2008/12/06/test-flex-throttled-simulate-download/' rel='bookmark' title='Test Flex/Flash throttled (aka Simulate Download)'>Test Flex/Flash throttled (aka Simulate Download)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s still quite a gap between Flash and Flex – while Flash is great for creating animations, vector symbols and just keeping little assets within one place, Flex Builder is so very much better for anything code. So how to link those two together?</p>
<p>Though I&#8217;ve written some posts about how to code within Flex Builder and <a href="/2008/12/03/test-movie-from-flex-to-flash-easy-way/">compile from there using Flash IDE</a>, I personally don&#8217;t like that at all and only use it for some few older AS3 projects. There are better methods, ways to compile from within Flex Builder while still being able to make use of Flash comfort.</p>
<p>There&#8217;s a neat way to <strong>embed a library</strong> without loosing any functionality (like little scripts). I&#8217;ve first seen it at <a href="http://www.gskinner.com/blog/archives/2007/03/using_flash_sym.html">Grant Skinner</a> (who&#8217;s doing great stuff, one of my favorites in the flash community really). Let&#8217;s say, you have a assets.fla and a published assets.swf. Now here we go:<span id="more-190"></span></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>SWF<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;750&quot;</span>, <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;500&quot;</span>, frameRate=<span style="color: #ff0000;">&quot;30&quot;</span>, <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;#111111&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">dynamic</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyApplication <span style="color: #0066CC;">extends</span> Sprite
<span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/assets.swf&quot;</span>, mimeType=<span style="color: #ff0000;">&quot;application/octet-stream&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> StageAssets:<span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> GlobusFlow<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		loadEmbedded<span style="color: #66cc66;">&#40;</span> StageAssets <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadEmbedded<span style="color: #66cc66;">&#40;</span> cls : <span style="color: #000000; font-weight: bold;">Class</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: #ff0000;">&quot;[Preloader] Loading embedded&quot;</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000000; font-weight: bold;">var</span> loader : 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> , <span style="color: #0066CC;">this</span>.<span style="color: #006600;">handleComplete</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000000; font-weight: bold;">var</span> context : 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: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> cls<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> , context <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	protected <span style="color: #000000; font-weight: bold;">function</span> handleComplete<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span> : 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> app : Sprite = Sprite<span style="color: #66cc66;">&#40;</span> LoaderInfo<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span> <span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">content</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">loaded</span><span style="color: #66cc66;">&#40;</span> app <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	protected <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">loaded</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>:Sprite<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> <span style="color: #0066CC;">background</span> : <span style="color: #0066CC;">MovieClip</span> = <span style="color: #0066CC;">target</span> as <span style="color: #0066CC;">MovieClip</span>;
&nbsp;
		<span style="color: #000000; font-weight: bold;">var</span> mainChildren : <span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span> ; i<span style="color: #66cc66;">&lt;</span>background.<span style="color: #006600;">numChildren</span> ; i++ <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			mainChildren.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">background</span>.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> child : DisplayObject <span style="color: #b1b100;">in</span> mainChildren <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> child.<span style="color: #0066CC;">name</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#91;</span> child.<span style="color: #0066CC;">name</span> <span style="color: #66cc66;">&#93;</span> = child;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span> child <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> = <span style="color: #0066CC;">background</span>.<span style="color: #0066CC;">width</span>;
		<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> = <span style="color: #0066CC;">background</span>.<span style="color: #0066CC;">height</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This does a bit more than just make the library available. In loaded() we&#8217;ll loop through all assets that are «on stage» in the loaded/embedded movieclip (assets.swf), and add each of them to our stage. That leads to a state that&#8217;s quite similar to as if we&#8217;d code within assets.fla itself. Hmm&#8230; well, really, that sounds more complicated than it is :-) It mainly gives you the feeling of being able to code within a SWF file. You can visually do your stuff in assets.fla, you can add a background and whatever to its stage, keep a nice library with graphics, animations, sounds and fonts.. and schwupps, here you go!</p>
<p>If you have Fonts embedded in your library, there&#8217;s a tiny little more to do:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">loaded</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>:Sprite<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;">// ... (all the other stuff, see above)</span>
	registerFont<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'BoldFont'</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> registerFont<span style="color: #66cc66;">&#40;</span> fontLinkageId : <span style="color: #0066CC;">String</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> fontClass : <span style="color: #000000; font-weight: bold;">Class</span> = getDefinitionByName<span style="color: #66cc66;">&#40;</span> fontLinkageId <span style="color: #66cc66;">&#41;</span> as <span style="color: #000000; font-weight: bold;">Class</span>;
	<span style="color: #0066CC;">Font</span>.<span style="color: #006600;">registerFont</span><span style="color: #66cc66;">&#40;</span> fontClass <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>If you just wanna embed fonts without any registering, you can also go like that:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">'assets/fonts.swf'</span> , symbol=<span style="color: #ff0000;">'BoldFont'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> BoldFont : <span style="color: #000000; font-weight: bold;">Class</span>;</pre></div></div>

<p>Of course, instead of embedding everything, you can also load this dynamically (I mean, after all we have the Loader ready, don&#8217;t we? :) The advantage of that is that you can give your assets to some dumb Flasher and he can mess around with it without you having to recompile the app.</p>
<p>I know, this is all snippets and frickets, I&#8217;m just too lazy right now to build an example Flex project. Still I hope it&#8217;s of some use for one or the other.</p>
<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/12/03/test-movie-from-flex-to-flash-easy-way/' rel='bookmark' title='Test Movie from Flex to Flash (easy way)'>Test Movie from Flex to Flash (easy way)</a></li>
<li><a href='http://blog.betabong.com/2008/12/06/test-flex-throttled-simulate-download/' rel='bookmark' title='Test Flex/Flash throttled (aka Simulate Download)'>Test Flex/Flash throttled (aka Simulate Download)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2009/02/13/embed-assets-in-flash-project/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CoverFlow: 3D with Flash Player 10</title>
		<link>http://blog.betabong.com/2008/12/08/coverflow-3d-with-flash-player-10/</link>
		<comments>http://blog.betabong.com/2008/12/08/coverflow-3d-with-flash-player-10/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 21:55:26 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=172</guid>
		<description><![CDATA[<p>I&#8217;m close to finishing a new project. Well, it&#8217;s actually not that new of a project, but it hasn&#8217;t gone online so far, and when I did the first version back in March I&#8217;ve used <strong>Papervision</strong> to achieve the goals.&#8230; <a href="http://blog.betabong.com/2008/12/08/coverflow-3d-with-flash-player-10/" class="read_more">Read more</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m close to finishing a new project. Well, it&#8217;s actually not that new of a project, but it hasn&#8217;t gone online so far, and when I did the first version back in March I&#8217;ve used <strong>Papervision</strong> to achieve the goals. It&#8217;s basically a simple CoverFlow effect to scroll through Logos.</p>
<p>The thing with the old Papervision version was.. it got pretty slow when loading many pictures (resulting in many 3d objects). I got briefed with a screen design more or less and expected much less elements to be loaded. Now they got back to me saying they had some problems. Oh yes, they had. Boy was it slow!!</p>
<p>So I did a new version, skipping Papervision for the <strong>new Flash Player 10 </strong>capabilities. Wow! What an improvement not only in <strong>speed</strong>, but also in <strong>quality</strong> (because I wouldn&#8217;t have to switch to crispy bitmap handling for acceptable speed &#8211; and Flash doesn&#8217;t provide that feature anyway) and <strong>file size</strong> (less than 25%!). Now I just hope that the end client will have the nuts to go with Flash Player 10 :-) (Adobe still doesn&#8217;t provide any <a href="http://www.adobe.com/products/player_census/flashplayer/version_penetration.html">statistics</a>, but it&#8217;s not that wide spread yet as for now).</p>
<p>See here the result (still in development – click the picture). You&#8217;ll need Flash Player 10 (I don&#8217;t check for the version in this example):</p>
<p><a href="http://www.betabong.com/work/nose/globusflow2/GlobusFlow2.html" target="_blank"><img class="alignnone size-full wp-image-173" title="coverflow" src="http://blog.betabong.com/wp-content/uploads/2008/12/coverflow.jpg" alt="" width="512" height="204" /></a></p>
<p>I made use of <a href="http://theflashblog.com/?p=470">SimpleZSorter</a></p>
<p><strong>Update:</strong> Well, the client wouldn&#8217;t go with 10. So I had to recode the Papervision version to speed it up as much as possible, and I think it got pretty speedy after all. <a href="http://www.betabong.com/work/nose/globusflow-pv3d/" target="_blank">See here for comparison.</a></p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2008/12/08/coverflow-3d-with-flash-player-10/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Develop in Flex Builder, publish in Flash IDE (Mac OS X)</title>
		<link>http://blog.betabong.com/2008/11/29/flex-builder-t-flash-ide/</link>
		<comments>http://blog.betabong.com/2008/11/29/flex-builder-t-flash-ide/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 12:12:43 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[CS4]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Install]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=144</guid>
		<description><![CDATA[<p><span class="update"><strong>Update:</strong> <a href="http://blog.betabong.com/2008/12/03/test-movie-from-flex-to-flash-easy-way/">I&#8217;ve found an easier way without FlashCommand</a></span></p>
<p>Once you got used to developing for Flash in Flex Builder, you hate to do any programming in Flash IDE. Still you sometimes might have to: Flex Builder won&#8217;t allow to&#8230; <a href="http://blog.betabong.com/2008/11/29/flex-builder-t-flash-ide/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/12/03/test-movie-from-flex-to-flash-easy-way/' rel='bookmark' title='Test Movie from Flex to Flash (easy way)'>Test Movie from Flex to Flash (easy way)</a></li>
<li><a href='http://blog.betabong.com/2008/12/06/test-flex-throttled-simulate-download/' rel='bookmark' title='Test Flex/Flash throttled (aka Simulate Download)'>Test Flex/Flash throttled (aka Simulate Download)</a></li>
<li><a href='http://blog.betabong.com/2008/07/16/flex-project-svn-strategy/' rel='bookmark' title='Flex Project &#8211; SVN Strategy'>Flex Project &#8211; SVN Strategy</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><span class="update"><strong>Update:</strong> <a href="http://blog.betabong.com/2008/12/03/test-movie-from-flex-to-flash-easy-way/">I&#8217;ve found an easier way without FlashCommand</a></span></p>
<p>Once you got used to developing for Flash in Flex Builder, you hate to do any programming in Flash IDE. Still you sometimes might have to: Flex Builder won&#8217;t allow to publish into a FLA file. (There are of course many other reasons, like supporting older AS1/AS2 projects, we don&#8217;t go into that here.) Thanks to Eclipse&#8217;s ability to be customized, there are ways to make things at least a little easier. I give here a little overview of how I&#8217;ve set up my environment, based on several helpful resources I&#8217;ve found in the web.</p>
<ol>
<li>Install FlashCommand</li>
<li>Install Ant</li>
</ol>
<p>And for each project:</p>
<ol>
<li>Create/modify Ant file</li>
<li>Create Actionscript project</li>
<li>Set up project and FLA file</li>
</ol>
<p><span id="more-144"></span></p>
<h3>What you need</h3>
<ul>
<li><a href="http://www.adobe.com/products/flex/">Flex Builder</a></li>
<li><a href="http://www.adobe.com/products/flash/">Flash IDE (CS3 or CS4)</a></li>
</ul>
<h3>Install FlashCommand</h3>
<p><a href="http://www.mikechambers.com/blog/2008/05/02/flashcommand-for-os-x-updated-to-work-with-flash-cs3/">flashcommand</a> is a python script by <a href="http://www.mikechambers.com/blog/">Mike Chambers</a> that lets you compile FLA files from the command line using Flash IDE. <a href="http://code.google.com/p/flashcommand/downloads/list">Download it</a> and put it wherever you want.</p>
<h3>Install ANT</h3>
<p>If you&#8217;re used to FDT (or Eclipse in any way) you may well know Ant. <a href="http://en.wikipedia.org/wiki/Apache_Ant">Ant</a> is the premier build tool for any developers working in <a href="http://www.eclipse.org/">Eclipse</a>, with many many cool possibilites to automate your workflow. Here&#8217;s how you <a href="http://blog.jodybrewster.net/2008/04/09/installing-ant-in-flex-builder-3/">install Ant in Flex Builder 3 Standalone</a>:</p>
<ol>
<li>Go to Help &gt; Software Updates &gt; Find and Install</li>
<li>Search for new features to install, click next</li>
<li>Select «The Eclipse Project Updates», click finish<br />
Note: If you do not have the option above click «New Remote Site» and enter «The Eclipse Project Updates» as the name and «http://update.eclipse.org/updates/3.3» as the url.</li>
<li>In Eclipse project updates look for «Eclipse Java Development Tools &#8230;» – it might be in «Eclipse SDK Eclipse 3.3.2» but this depends on what version you have installed and what version is currently available. Select it and click next.</li>
<li>Accept licence agreement, click next. Then click «Finish» to start download.</li>
<li>Once downloaded, click «Install all»</li>
<li>Restart Eclipse (you&#8217;ll be asked to)</li>
</ol>
<h3>Create Project</h3>
<ol>
<li>Create a new Actionscript Project in Flex Builder</li>
<li>Add a new «build» directory in the project root</li>
<li>Add your FLA file(s) and assets to the build folder and your source files to the src folder<br />
(I also strongly recommend adding external libraries to and «externals» directory and use svn:externals property on it, but that&#8217;s another story) </li>
<li>Add build paths. You have to do this at least twice:
<ul>
<li>In the Flash IDE for the FLA: Publish Settings &gt; Actionscript 3 «Settings&#8230;». Don&#8217;t forget to add the src folder at least.<br />
Test your FLA once done. It should compile just fine.</li>
<li>In Flex Builder: Project &gt; Properties &gt; ActionScript Build Path. Add your external libraries here. This is used so Flex knows where to lookup your classes, it won&#8217;t actually be needed for compiling, because that&#8217;s what Flash IDE&#8217;s gonna do.</li>
</ul>
</li>
<li>Now you&#8217;re almost done: you can edit your classes in Flex Builder and switch to Flash IDE to publish and/or test your movie. We&#8217;re gonna make this a little more comfortable with Ant and flashcommand.</li>
</ol>
<h3>Add Ant build file</h3>
<ol>
<li>Create a new file build.xml in the root folder and open it with Ant Editor (in Flex Builder aka Eclipse)</li>
<li>Edit the build.xml according your setup (see below for example)</li>
<li>Add build.xml to Ant View (Window &gt; Other Views&#8230;)</li>
<li>Run an action by double clicking it in Ant View: there you go!! It will compile in Flash IDE and open in your browser for testing!</li>
</ol>
<h3>Sample Ant build.xml</h3>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- ====================================================================== </span>
<span style="color: #808080; font-style: italic;">	     Nov 28, 2008 1:37:54 AM                                                        </span>
&nbsp;
<span style="color: #808080; font-style: italic;">	     MyProject    </span>
<span style="color: #808080; font-style: italic;">	     Compile in Flash IDE</span>
&nbsp;
<span style="color: #808080; font-style: italic;">	     sev                                                                </span>
<span style="color: #808080; font-style: italic;">	     ====================================================================== --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MyProject&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;Compile and Run&quot;</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;./&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	        <span style="color: #808080; font-style: italic;">&lt;!-- project specifics --&gt;</span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;browser&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Safari&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;swf.filename&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;MyProject&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;html.filename&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;fla/index.html&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	        <span style="color: #808080; font-style: italic;">&lt;!-- Flash IDE Commandline compiler --&gt;</span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;python&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/usr/bin/python&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;flash.command&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/path/to/flashcommand&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	        <span style="color: #808080; font-style: italic;">&lt;!-- directories --&gt;</span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;user.path&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/Users/yourname&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;build.dir&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${basedir}/build&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;main.fla&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${build.dir}/${swf.filename}.fla&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	        <span style="color: #808080; font-style: italic;">&lt;!-- paths --&gt;</span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;output.path&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${build.dir}/${swf.filename}.swf&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
			<span style="color: #808080; font-style: italic;">&lt;!-- you can also point to the file:///path/to/index.html --&gt;</span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;local.path&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;http://localhost/projects/MyProject/${html.filename}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;log.path&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${user.path}/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	        <span style="color: #808080; font-style: italic;">&lt;!-- Compile python flashcommand -e  -s build/MyProject.fla -o build/MyProject.swf </span>
&nbsp;
<span style="color: #808080; font-style: italic;">	        usage: flashcommand -e | -c | -p [-v] [-x] (-s &lt;sourcefile&gt;) ([-o] &lt;exportpath&gt;) ([-t] &lt;timeout&gt;)([-d] &lt;tempdir&gt;) [-j]</span>
&nbsp;
<span style="color: #808080; font-style: italic;">	        Options and arguments:</span>
&nbsp;
<span style="color: #808080; font-style: italic;">	        -a : Prints version and about information.</span>
<span style="color: #808080; font-style: italic;">	        -c : Specifies save and compact action. </span>
<span style="color: #808080; font-style: italic;">	        -d : Specifies temp directory that will be used for temporary files. Optional.</span>
<span style="color: #808080; font-style: italic;">	        -e : Specifies export action.</span>
<span style="color: #808080; font-style: italic;">	        -h : Prints usage information.</span>
<span style="color: #808080; font-style: italic;">	        -j : Specifies that the generated JSFL file should be printed. If this option is specified, Flash will not be executed.</span>
<span style="color: #808080; font-style: italic;">	        -o : Specifies the output file if -e flag is also set. Optional. If not specified, file will be output to same directory as source.</span>
<span style="color: #808080; font-style: italic;">	        -p : Specifies publish action.</span>
<span style="color: #808080; font-style: italic;">	        -s : Specifies source file. Required.</span>
<span style="color: #808080; font-style: italic;">	        -t : Specifies timeout value. Optional.</span>
<span style="color: #808080; font-style: italic;">	        -v : Specifies verbose mode. Optional.</span>
<span style="color: #808080; font-style: italic;">	        -f : Specifies that the Flash authoring version installed is a version other than Flash CS3</span>
<span style="color: #808080; font-style: italic;">	        -x : Specifies whether Flash should be closed after it is done processing. Optional.    </span>
&nbsp;
<span style="color: #808080; font-style: italic;">	        --&gt;</span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Compile and Run&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;antcall</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;Compile in IDE&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;antcall</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;Clear Log&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;antcall</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;Open in Browser&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Compile in IDE&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${flash.command} -e -c -s ${main.fla} -o ${output.path}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exec</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;${python}&quot;</span> <span style="color: #000066;">failonerror</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">logError</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;${flash.command}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-e &quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-s ${main.fla} &quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-o ${output.path}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exec<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Open in local browser --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Open in Browser&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exec</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;open&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-a ${browser} ${local.path}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exec<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Clear Debug Log --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Clear Log&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
        	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;concat</span> <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;${log.path}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>                                                                                                            
.: Sev Log File :.
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/concat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exec</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;open&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-a console '${log.path}'&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exec<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Update:</strong> <a href="http://www.leebrimelow.com/">Lee Brimelov</a> just released a <a href="http://theflashblog.com/?p=482">plugin for Eclipse</a>, that provides this functionality (more or less) with a single click of an icon. It&#8217;s an alpha version, and you won&#8217;t have all the Ant flexibility (well, you could still install Ant), but you can avoid most of the installation hazzle, and that&#8217;s pretty cool. Unfortunately I couldn&#8217;t get it to work so far. </p>
<p><strong>Update 2:</strong> It bugged me that every time I execute this action Flash would pop up. To work around that I slightly modified the FlashCommand script (it actually checks wether the FLA file is already open, and if so won&#8217;t call the open command). Also I had to leave away the -c option (save and compact), something I don&#8217;t need anyway. So now when you execute the command from Flex the following happens:</p>
<ol>
<li>The little publish dialog pops up (Fla is exported to SWF)</li>
<li>The HTML file is opened in the browser (which comes to front), as well as the Console displaying the trace output</li>
</ol>
<p>Also I have bound the «Launch last external tool» command in Flex Builder to a key combo. Now things run pretty smooth and as much satisfying as compiling via Flash can be. Btw, I also looked into this Eclipse plugin – as it seems the only thing it does is to tell Flash to «Test Movie» with the frontmost open document. That&#8217;s absolutely okay for most people, but I&#8217;m glad for the extra functionality I get with this solution (at the cost of more initial effort of course). Download here the modified FlashCommand: <a class="download" href='http://blog.betabong.com/wp-content/uploads/2008/12/flashcommand.zip'>flashcommand.zip</a></p>
<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/12/03/test-movie-from-flex-to-flash-easy-way/' rel='bookmark' title='Test Movie from Flex to Flash (easy way)'>Test Movie from Flex to Flash (easy way)</a></li>
<li><a href='http://blog.betabong.com/2008/12/06/test-flex-throttled-simulate-download/' rel='bookmark' title='Test Flex/Flash throttled (aka Simulate Download)'>Test Flex/Flash throttled (aka Simulate Download)</a></li>
<li><a href='http://blog.betabong.com/2008/07/16/flex-project-svn-strategy/' rel='bookmark' title='Flex Project &#8211; SVN Strategy'>Flex Project &#8211; SVN Strategy</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2008/11/29/flex-builder-t-flash-ide/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Alchemy – THE cool new flash feature!</title>
		<link>http://blog.betabong.com/2008/11/19/alchemy-release/</link>
		<comments>http://blog.betabong.com/2008/11/19/alchemy-release/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 14:53:39 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=142</guid>
		<description><![CDATA[<p>Adobe today released <a href="http://labs.adobe.com/technologies/alchemy/">Alchemy</a>, a SDK to compile C/C++ code into AVM2 Bytecode.</p>
<p>This has been sneak peaked a while ago (see Video below) &#8211; now it&#8217;s here. And I&#8217;m amazed!! Think of the possiblities: XSLT interpreter (as demoed&#8230; <a href="http://blog.betabong.com/2008/11/19/alchemy-release/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/08/22/flash-player-10-i-love-speed/' rel='bookmark' title='Flash Player 10 – I love speed'>Flash Player 10 – I love speed</a></li>
<li><a href='http://blog.betabong.com/2008/09/23/e4x-string-parser/' rel='bookmark' title='E4X String Parser'>E4X String Parser</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Adobe today released <a href="http://labs.adobe.com/technologies/alchemy/">Alchemy</a>, a SDK to compile C/C++ code into AVM2 Bytecode.</p>
<p>This has been sneak peaked a while ago (see Video below) &#8211; now it&#8217;s here. And I&#8217;m amazed!! Think of the possiblities: XSLT interpreter (as demoed in the vid), 3D speed, super fast parsing, physics, AI &#8211; everything that&#8217;s CPU intensive and won&#8217;t need any platform specific stuff.</p>
<p>So far this C code still looks pretty fucked up to me (see examples at the labs), but hell, I&#8217;m sure that one day we&#8217;re gonna see some real fancy stuff thanks to this. I&#8217;m looking forward!</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="512" height="380" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://blip.tv/play/AZmeJIX8bw" /><embed type="application/x-shockwave-flash" width="512" height="380" src="http://blip.tv/play/AZmeJIX8bw"></embed></object></p>
<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/08/22/flash-player-10-i-love-speed/' rel='bookmark' title='Flash Player 10 – I love speed'>Flash Player 10 – I love speed</a></li>
<li><a href='http://blog.betabong.com/2008/09/23/e4x-string-parser/' rel='bookmark' title='E4X String Parser'>E4X String Parser</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2008/11/19/alchemy-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weak Method Closure</title>
		<link>http://blog.betabong.com/2008/09/26/weak-method-closure/</link>
		<comments>http://blog.betabong.com/2008/09/26/weak-method-closure/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 23:36:16 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[weak]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=115</guid>
		<description><![CDATA[<p>Sometimes you want to pass an objects function as an argument and store that function (along its arguments) for later calling. Still you don&#8217;t want that storage to prevent its object (instance) from being destroyed (from being removed by the&#8230; <a href="http://blog.betabong.com/2008/09/26/weak-method-closure/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/' rel='bookmark' title='Metatunnel 1k Demo: AS vs. JS'>Metatunnel 1k Demo: AS vs. JS</a></li>
<li><a href='http://blog.betabong.com/2008/07/21/nested-inner-functions-can-be-evil/' rel='bookmark' title='Nested inner functions can be evil'>Nested inner functions can be evil</a></li>
<li><a href='http://blog.betabong.com/2009/04/17/metatunnel-with-pixel-bender/' rel='bookmark' title='MetaTunnel with Pixel Bender'>MetaTunnel with Pixel Bender</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want to pass an objects function as an argument and store that function (along its arguments) for later calling. Still you don&#8217;t want that storage to prevent its object (instance) from being destroyed (from being removed by the garbage collector). But storing a function does so, because it holds a reference to the function which belongs to an object.</p>
<p>It&#8217;s one of the biggest traps you can fall into when developing a larger project where many objects are created and destroyed and created and so on&#8230; geeks call that kind of thing memory leaks I think :)</p>
<p>So if you can avoid it: avoid it! If you can&#8217;t.. may be this little thing can help:<br />
<span id="more-115"></span></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">betabong</span>.<span style="color: #006600;">util</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Dictionary</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WeakMethodClosure <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> holder : Dictionary;
&nbsp;
		<span style="color: #000000; font-weight: bold;">function</span> WeakMethodClosure<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">target</span> : <span style="color: #0066CC;">Object</span> , method : <span style="color: #000000; font-weight: bold;">Function</span> , <span style="color: #0066CC;">arguments</span> : <span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			holder = <span style="color: #000000; font-weight: bold;">new</span> Dictionary<span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">&#41;</span>;
			holder<span style="color: #66cc66;">&#91;</span> <span style="color: #0066CC;">target</span> <span style="color: #66cc66;">&#93;</span> = 	<span style="color: #000000; font-weight: bold;">new</span> MethodStorage<span style="color: #66cc66;">&#40;</span> method , <span style="color: #0066CC;">arguments</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Boolean</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> args : <span style="color: #0066CC;">Array</span>;
			<span style="color: #000000; font-weight: bold;">var</span> f : <span style="color: #000000; font-weight: bold;">Function</span>;
			<span style="color: #000000; font-weight: bold;">var</span> cache : MethodStorage;
			<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> obj : <span style="color: #66cc66;">*</span> <span style="color: #b1b100;">in</span> holder <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				cache = holder<span style="color: #66cc66;">&#91;</span>obj<span style="color: #66cc66;">&#93;</span> as MethodStorage;
				cache.<span style="color: #006600;">method</span>.<span style="color: #0066CC;">apply</span><span style="color: #66cc66;">&#40;</span> obj , cache.<span style="color: #0066CC;">arguments</span> <span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MethodStorage <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> method : <span style="color: #000000; font-weight: bold;">Function</span>;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">arguments</span> : <span style="color: #0066CC;">Array</span>;
	<span style="color: #000000; font-weight: bold;">function</span> MethodStorage<span style="color: #66cc66;">&#40;</span> method : <span style="color: #000000; font-weight: bold;">Function</span> , <span style="color: #0066CC;">arguments</span> : <span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">method</span> = method;
		<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">arguments</span> = <span style="color: #0066CC;">arguments</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This actually uses one of the two mechanisms Flash provides to store objects by weak reference: the magic Dictionary. So instead of storing the function, you actually store the method storage or call method:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> callAfterTime<span style="color: #66cc66;">&#40;</span> f : <span style="color: #000000; font-weight: bold;">Function</span> , a : <span style="color: #0066CC;">Array</span> , t : uint <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">storedfunction</span> = <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> WeakMethodClosure<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">this</span> , f , a <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">call</span>;
<span style="color: #808080; font-style: italic;">// and later:</span>
storedfunction<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>It might not be obvious where you&#8217;d wanna use this, but I guess if you&#8217;ve found your way to this blog entry, you might be able to find out if that&#8217;s of any value for you anyway ;)</p>
<p><a href="/showcase/WeakMethodClosure.as.zip">Download WeakMethodClosure.as (zip)</a></p>
<p>Just be aware that this solution might not be superduper save in all cases: the Garbage Collector is a wayward beast – there&#8217;s no guarantee it&#8217;ll clean your dictionary on time. Still, in my experience, it&#8217;s save enough. It&#8217;s comparable to adding a weak event listener..</p>
<p>And hey, if you&#8217;ve got any better idea, I&#8217;d love to hear!</p>
<p><strong>Update:</strong> Below a test application&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">betabong</span>.<span style="color: #006600;">util</span>.<span style="color: #006600;">WeakMethodClosure</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;">TimerEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Timer</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #0066CC;">getTimer</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WeakClosureTest <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> closure : WeakMethodClosure;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> timer : Timer;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> WeakClosureTest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>			
			testWeakClosure<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testWeakClosure<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> tempObject : <span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
				test: testTrace
			<span style="color: #66cc66;">&#125;</span>
			closure = <span style="color: #000000; font-weight: bold;">new</span> WeakMethodClosure<span style="color: #66cc66;">&#40;</span> tempObject , tempObject.<span style="color: #006600;">test</span> <span style="color: #66cc66;">&#41;</span>;
			callWeakClosure<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">50</span> <span style="color: #66cc66;">&#41;</span>;
			timer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span> , callWeakClosure <span style="color: #66cc66;">&#41;</span>;
			timer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> callWeakClosure<span style="color: #66cc66;">&#40;</span> event : TimerEvent = <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span>closure.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Closure failed&quot;</span> <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testTrace<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: #ff0000;">&quot;Called test&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Outputs:</p>
<pre>
Called test
Called test
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
Closure failed
</pre>
<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/' rel='bookmark' title='Metatunnel 1k Demo: AS vs. JS'>Metatunnel 1k Demo: AS vs. JS</a></li>
<li><a href='http://blog.betabong.com/2008/07/21/nested-inner-functions-can-be-evil/' rel='bookmark' title='Nested inner functions can be evil'>Nested inner functions can be evil</a></li>
<li><a href='http://blog.betabong.com/2009/04/17/metatunnel-with-pixel-bender/' rel='bookmark' title='MetaTunnel with Pixel Bender'>MetaTunnel with Pixel Bender</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2008/09/26/weak-method-closure/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>E4X String Parser</title>
		<link>http://blog.betabong.com/2008/09/23/e4x-string-parser/</link>
		<comments>http://blog.betabong.com/2008/09/23/e4x-string-parser/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 11:13:00 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[e4x]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[os]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=111</guid>
		<description><![CDATA[<p>I did a lot of string parsing in the recent time: CSS Selectors, XML Display Objects, Stylesheets, &#8230; I also need XML selection from String expressions – I formerly (AS2) used the great <a href="http://www.xfactorstudio.com/">XPath4AS2 from XFactorStudio</a> which did it&#8217;s&#8230; <a href="http://blog.betabong.com/2008/09/23/e4x-string-parser/" class="read_more">Read more</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I did a lot of string parsing in the recent time: CSS Selectors, XML Display Objects, Stylesheets, &#8230; I also need XML selection from String expressions – I formerly (AS2) used the great <a href="http://www.xfactorstudio.com/">XPath4AS2 from XFactorStudio</a> which did it&#8217;s job well (though a bit slow, it&#8217;s AS2 after all).</p>
<p>There&#8217;s also one for Actionscript 3 (<a href="http://code.google.com/p/xpath-as3/">xpath-as3</a>). But.. well&#8230; I wanted to go for some real speed! I like XPath a lot, but we now have native E4X selection in Actionscript 3, quite a different concept of node selection, and the conversion of XPath to E4X obviously results in quite a compromise in performance.</p>
<p>So all I need is a decent E4X parser. And hey, I found one! E<a href="http://www.adobe.com/devnet/flex/articles/e4x_print.html">4XParser from Digital Primates</a>. It does its job really well, especially considering the very compact code it consists of. Thanks to some preparsing and caching, it&#8217;s also quite fast.</p>
<p><strong>Still I thought I can do better :-)</strong> So I planted myself for a day (and a night) in front of my displays and hacked the hell out of it. The result is a little library which does pretty much the same thing as E4XParser, though pretty much more and a little faster too (15% to 50%). It&#8217;s about half as fast as the native E4X selection (once parsed). You can do nearly anything you can do with E4X. Use it like this:</p>
<p> </p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">betabong</span>.<span style="color: #0066CC;">xml</span>.<span style="color: #006600;">e4x</span>.<span style="color: #006600;">E4X</span>;
<span style="color: #000000; font-weight: bold;">var</span> result : XMLList = E4X.<span style="color: #006600;">evaluate</span><span style="color: #66cc66;">&#40;</span> xmllist , <span style="color: #ff0000;">&quot;author.( name.@last == 'Jobs' )&quot;</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// E4X.evaluate( source : XMLList , expression : String ) : XMLList</span></pre></div></div>

<p> <br />
If your source is XML, just do XMLList( xml ), if your result should be xml, do xml = result[0]</p>
<p><a href="/showcase/e4x/E4X_Parse_Test.html">Test it here</a></p>
<p><a href="http://blog.betabong.com/showcase/e4x/E4X_Parse_Test.html" target="_blank"><img class="alignnone size-full wp-image-113" title="e4x" src="http://blog.betabong.com/wp-content/uploads/2008/09/e4x.png" alt="" width="512" height="405" /></a></p>
<p><strong>Restrictions:</strong> You can&#8217;t use AND/OR in comparisions. So, this won&#8217;t go: author.( name.@first == &#8216;Steve&#8217; &amp;&amp; name.@last == &#8216;Jobs&#8217; ) – though this is only a real limitations for OR. do this for AND: author.( name.@first == &#8216;Steve&#8217; ).( name.@last == &#8216;Jobs&#8217; ).</p>
<p><strong>What you can do:</strong> Yes, you can do quite advanced stuff like author.( name.@first == name.@last ) or car.@rating.average() (one of the few proprietary functions I added). Or even</p>
<pre>*..car.( @brand.toLowerCase() == 'volvo' ).( parent().( localName() == 'group' ).@rating &gt; @rating )</pre>
<p>– a weird example, I admit, but fancy, ain&#8217;t it? :-)</p>
<p>This is the first time ever I&#8217;m releasing part of my library as Open Source (MIT licence). As soon as I&#8217;ll find some time (and if I see any interest), I&#8217;m gonna put this into Google Code, so everybody can easily checkout and participate. Until then download it from here:</p>
<p><a class="download" href="/showcase/e4x/betabong-e4x.zip">Download</a> (zip 13kb)</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2008/09/23/e4x-string-parser/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Simplicity follows Performance – parsing Strings in Actionscript 3</title>
		<link>http://blog.betabong.com/2008/09/01/speed-parsing-string-in-as3/</link>
		<comments>http://blog.betabong.com/2008/09/01/speed-parsing-string-in-as3/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 16:18:25 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=101</guid>
		<description><![CDATA[<p>In my current project I do a lot of String parsing. Much a lot! And when it comes to do the same things many many times, performance will gain much from little details.</p>
<p>Let&#8217;s take the simplest parsing as an&#8230; <a href="http://blog.betabong.com/2008/09/01/speed-parsing-string-in-as3/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2009/09/22/binary-fun-bits-in-bed-with-actionscript/' rel='bookmark' title='Binary Fun &#8211; Bits in Bed with Actionscript'>Binary Fun &#8211; Bits in Bed with Actionscript</a></li>
<li><a href='http://blog.betabong.com/2008/07/21/nested-inner-functions-can-be-evil/' rel='bookmark' title='Nested inner functions can be evil'>Nested inner functions can be evil</a></li>
<li><a href='http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/' rel='bookmark' title='Metatunnel 1k Demo: AS vs. JS'>Metatunnel 1k Demo: AS vs. JS</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In my current project I do a lot of String parsing. Much a lot! And when it comes to do the same things many many times, performance will gain much from little details.</p>
<p>Let&#8217;s take the simplest parsing as an example. Converting a CSS like string <strong>&#8220;width: 100%; maxwidth: 500; fontface: Bold; gap: 10;&#8221;</strong> to an object <strong>{ width: &#8220;100%&#8221; , maxwidth: &#8220;500&#8243; , fontface: &#8220;Bold&#8221; , gap: &#8220;10&#8243; }</strong></p>
<p>Compare these two methods to achieve this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> simpleStringToObject_fast<span style="color: #66cc66;">&#40;</span> input : <span style="color: #0066CC;">String</span> , o : <span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> input == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">||</span> <span style="color: #66cc66;">!</span><span style="color: #0066CC;">Boolean</span><span style="color: #66cc66;">&#40;</span>input<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> o;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> o == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> o = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> cursor : <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> found_key : <span style="color: #0066CC;">String</span>;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">index</span> : <span style="color: #0066CC;">int</span>;
	<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> found_key == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">index</span> = input.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">':'</span> , cursor <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">index</span> <span style="color: #66cc66;">&amp;</span>gt;= <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span> input.<span style="color: #0066CC;">charAt</span><span style="color: #66cc66;">&#40;</span>index-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">&#41;</span> index--;
				found_key = input.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span> cursor , <span style="color: #0066CC;">index</span> <span style="color: #66cc66;">&#41;</span>;
				cursor = <span style="color: #0066CC;">index</span> + <span style="color: #cc66cc;">1</span>;
				<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span> input.<span style="color: #0066CC;">charAt</span><span style="color: #66cc66;">&#40;</span>cursor<span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">&#41;</span> cursor++;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">break</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">index</span> = input.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">';'</span> , cursor <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">index</span> <span style="color: #66cc66;">&amp;</span>gt;= <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span> input.<span style="color: #0066CC;">charAt</span><span style="color: #66cc66;">&#40;</span>index-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">&#41;</span> index--;
				o<span style="color: #66cc66;">&#91;</span> found_key <span style="color: #66cc66;">&#93;</span> = input.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span> cursor , <span style="color: #0066CC;">index</span> <span style="color: #66cc66;">&#41;</span>;
				found_key = <span style="color: #000000; font-weight: bold;">null</span>;
				cursor = <span style="color: #0066CC;">index</span> + <span style="color: #cc66cc;">1</span>;
				<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span> input.<span style="color: #0066CC;">charAt</span><span style="color: #66cc66;">&#40;</span>cursor<span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">&#41;</span> cursor++;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
				o<span style="color: #66cc66;">&#91;</span> found_key <span style="color: #66cc66;">&#93;</span> = input.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span> cursor <span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">break</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> o;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> simpleStringToObject_slow<span style="color: #66cc66;">&#40;</span> input : <span style="color: #0066CC;">String</span> , o : <span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> input == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">||</span> <span style="color: #66cc66;">!</span><span style="color: #0066CC;">Boolean</span><span style="color: #66cc66;">&#40;</span>input<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> o;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> o == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span> o = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;
&nbsp;
	input = input.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">' '</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">join</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// remove spaces</span>
	<span style="color: #000000; font-weight: bold;">var</span> a : <span style="color: #0066CC;">Array</span> = input.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">';'</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> pair : <span style="color: #0066CC;">Array</span>;
	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span> ; i <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			o<span style="color: #66cc66;">&#91;</span> pair<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#93;</span> = pair<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> o;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The first one might look like some crap lacking any elegance and style, but it&#8217;s<strong> twice as fast</strong> as the second one! And hey, if you do this a million times, it can be 5 seconds instead of 10. Might not seem to be that much, but I think it&#8217;s certainly <strong>worth the extra coding</strong> :-)</p>
<p>(Update: I haven&#8217;t mentioned RegExp here, though it definitely deserves a mention. Thing is that Regular Expressions are just damned slow in Flash compared to String manipulations, especially with longer strings. This is kind of surprising because it&#8217;s implemented natively. But the implementation obviously isn&#8217;t too good performance wise. I hope to see improvements with F10, though haven&#8217;t read anything about it yet &#8211; and also haven&#8217;t tested yet with beta. This little article confirms my experience with RegExp: <a href="http://www.mischel.com/diary/2006/07/12.htm">With a file of 10,000 lines, the string version is still instantaneous, but the regular expression version takes about five seconds.  Even with 180,000 lines, the string version is immediate.  We gave up on the regular expression version after over five minutes..</a>)</p>
<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2009/09/22/binary-fun-bits-in-bed-with-actionscript/' rel='bookmark' title='Binary Fun &#8211; Bits in Bed with Actionscript'>Binary Fun &#8211; Bits in Bed with Actionscript</a></li>
<li><a href='http://blog.betabong.com/2008/07/21/nested-inner-functions-can-be-evil/' rel='bookmark' title='Nested inner functions can be evil'>Nested inner functions can be evil</a></li>
<li><a href='http://blog.betabong.com/2009/04/13/metatunnel-1k-demo-as-vs-js/' rel='bookmark' title='Metatunnel 1k Demo: AS vs. JS'>Metatunnel 1k Demo: AS vs. JS</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2008/09/01/speed-parsing-string-in-as3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Flash Player 10 – I love speed</title>
		<link>http://blog.betabong.com/2008/08/22/flash-player-10-i-love-speed/</link>
		<comments>http://blog.betabong.com/2008/08/22/flash-player-10-i-love-speed/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 08:30:03 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[vector]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=77</guid>
		<description><![CDATA[<p><img class="alignleft size-full wp-image-84" title="astro" src="http://blog.betabong.com/wp-content/uploads/2008/08/astro.jpg" alt="" width="150" height="164" style="margin-right:20px; margin-bottom:20px; float:left;"/>So Flash Player 10 is on its way. Soon, very soon, we&#8217;ll be able to enjoy 3D effects on every other website, youhaa. While some are eagerly waiting for this or the enhanced drawing API, I&#8217;m very much looking forward&#8230; <a href="http://blog.betabong.com/2008/08/22/flash-player-10-i-love-speed/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2009/04/05/flash-debug-speed/' rel='bookmark' title='Flash Debug Speed'>Flash Debug Speed</a></li>
<li><a href='http://blog.betabong.com/2008/11/19/alchemy-release/' rel='bookmark' title='Alchemy – THE cool new flash feature!'>Alchemy – THE cool new flash feature!</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-84" title="astro" src="http://blog.betabong.com/wp-content/uploads/2008/08/astro.jpg" alt="" width="150" height="164" style="margin-right:20px; margin-bottom:20px; float:left;"/>So Flash Player 10 is on its way. Soon, very soon, we&#8217;ll be able to enjoy 3D effects on every other website, youhaa. While some are eagerly waiting for this or the enhanced drawing API, I&#8217;m very much looking forward to the speed enhancements.</p>
<p>Visual Speed</p>
<p>While Flash Player 9 or more precisely the underlying actionscript 3 interpreter have lead to great speed enhancements on the logic side (meaning much faster data manipulation), it&#8217;s still rather slow when it comes to rendering. In a project I&#8217;m currently working on there&#8217;s quite some stuff going on here, but when I check speed performance with the Flex Profiler, most time is spent for rendering. Significant time. And it&#8217;s not some freaky Papervision 3D stuff ;)</p>
<p>So with Flash Player 10 this will be better. Adobe finally improves rendering speed, and the good thing is that every exisiting project (at least &gt;= f9, all?) will profit without republishing. I had done some little tests with a beta, and though I don&#8217;t remember the results, they looked quite promising (even on a Mac). I&#8217;m not sure though when they&#8217;re gonna use the graphic card to speed up – I don&#8217;t think it made use of that in my tests. Most people mention the hardware acceleration (some rendering tasks can be offloaded to your graphics card), but in my understanding the overhauled the entire rendering system, so everything and everyone should profit.</p>
<p>Vectors</p>
<p>Vectors are simply typed Arrays. A limited array. Ha! why would we want that?! For two reasons:</p>
<ul>
<li>Developers have more feedback while coding: the IDE will be able to tell you when you put some wrong stuff in an array – as for now you could mix whatever data in an array, the compiler wouldn&#8217;t complain. But above all, the IDE will be able to provide you help while typing: no more casting all the time to get to the methods of an array item!</li>
<li>Speed. A typed array can be much faster. And it will be.</li>
</ul>
<p>It looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> vector:Vector.<span style="color: #66cc66;">&amp;</span>lt;int<span style="color: #66cc66;">&amp;</span>gt; = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&amp;</span>lt;int<span style="color: #66cc66;">&amp;</span>gt;<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>I&#8217;m not too much a fan of the definition syntax – something like this would look better, I think:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> vector:Vector::<span style="color: #0066CC;">int</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector::<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// or</span>
<span style="color: #000000; font-weight: bold;">var</span> vector:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>But I haven&#8217;t thought of it much. Adobe certainly thought about it. Or some ECMA comittee. (Copy-pasting in WordPress HTML mode also won&#8217;t work anymore.. pfff) Also I personally would have preferred not to have another class for that (just enhance the good old Array), but there are reasons for that too (backward compatibility, I guess, I can sing a song about that too). So anyway, I&#8217;m eagerly looking forward to use that stuff. I just love speed.</p>
<p>More infos here: <a title="Permanent Link to Using Vectors in ActionScript 3 and Flash Player 10" rel="bookmark" href="http://www.mikechambers.com/blog/2008/08/19/using-vectors-in-actionscript-3-and-flash-player-10/">Using Vectors in ActionScript 3 and Flash Player 10</a></p>
<p>Update: Ok, I can&#8217;t make to appear the new Vector syntax in WordPress. Now I like the syntax even less ;-)</p>
<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2009/04/05/flash-debug-speed/' rel='bookmark' title='Flash Debug Speed'>Flash Debug Speed</a></li>
<li><a href='http://blog.betabong.com/2008/11/19/alchemy-release/' rel='bookmark' title='Alchemy – THE cool new flash feature!'>Alchemy – THE cool new flash feature!</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2008/08/22/flash-player-10-i-love-speed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nested inner functions can be evil</title>
		<link>http://blog.betabong.com/2008/07/21/nested-inner-functions-can-be-evil/</link>
		<comments>http://blog.betabong.com/2008/07/21/nested-inner-functions-can-be-evil/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 07:53:29 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[EventDispatcher]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=39</guid>
		<description><![CDATA[<p>Sometimes it would be quite comfortable (from a programmer&#8217;s perspective) to use nested inner functions. But they are a potential source for nasty problems. Let&#8217;s take the following simple scenario:<span id="more-39"></span></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&#60;?xml version=<span style="color: #ff0000;">&#34;1.0&#34;</span> encoding=<span style="color: #ff0000;">&#34;utf-8&#34;</span>?<span style="color: #7400FF;">&#62;</span></span>
<span</pre></div></div><p>&#8230; <a href="http://blog.betabong.com/2008/07/21/nested-inner-functions-can-be-evil/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/09/26/weak-method-closure/' rel='bookmark' title='Weak Method Closure'>Weak Method Closure</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Sometimes it would be quite comfortable (from a programmer&#8217;s perspective) to use nested inner functions. But they are a potential source for nasty problems. Let&#8217;s take the following simple scenario:<span id="more-39"></span></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;create()&quot;</span> click=<span style="color: #ff0000;">&quot;destroy()&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">		&lt;![CDATA[</span>
<span style="color: #339933;">			private var dispatcher : Sprite;</span>
&nbsp;
<span style="color: #339933;">			private function create() : void {</span>
<span style="color: #339933;">				dispatcher = new Sprite();</span>
<span style="color: #339933;">				// listen to inner function</span>
<span style="color: #339933;">				dispatcher.addEventListener( Event.ENTER_FRAME , function( e : Event ) : void { trace( e.type ); } );</span>
<span style="color: #339933;">			}</span>
&nbsp;
<span style="color: #339933;">			private function destroy() : void {</span>
<span style="color: #339933;">				// this should free created dispatcher from memory</span>
<span style="color: #339933;">				dispatcher = null;</span>
<span style="color: #339933;">				// what we would need is:</span>
<span style="color: #339933;">				// dispatcher.destroy() or dispatcher.removeEventListener( Event.ENTER_FRAME )</span>
<span style="color: #339933;">				// or dispatcher.removeAllEventListeners()</span>
<span style="color: #339933;">			}</span>
<span style="color: #339933;">		]]&gt;</span>
<span style="color: #339933;">	&lt;/mx:Script&gt;</span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>The dispatcher will just live on. The mean thing is that in method «destroy» we don&#8217;t even have a chance to get rid of the sprite anymore – it just lives on and on (and dispatches its event every time it enters a frame to the listener function.) So 3 objects will just not be freed in memory because of our inner function listener: 1. the dispatcher object, 2. the listener function (the inner function) and 3. the creating object, because the listener function (or its method closure) is bound to the creating method create() scope.</p>
<p>We also can&#8217;t use the addEventListener&#8217;s flag to use weak references, because the listener method wouldn&#8217;t have any other references and would «dye» instantely. So what you should do right now is something like that:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;create()&quot;</span> click=<span style="color: #ff0000;">&quot;destroy()&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">		&lt;![CDATA[</span>
<span style="color: #339933;">			private var dispatcher : Sprite;</span>
&nbsp;
<span style="color: #339933;">			private function create() : void {</span>
<span style="color: #339933;">				dispatcher = new Sprite();</span>
<span style="color: #339933;">				dispatcher.addEventListener( Event.ENTER_FRAME , handler );</span>
<span style="color: #339933;">			}</span>
&nbsp;
<span style="color: #339933;">			private function destroy() : void {</span>
<span style="color: #339933;">				dispatcher.removeEventListener( Event.ENTER_FRAME , handler );</span>
<span style="color: #339933;">				dispatcher = null;</span>
<span style="color: #339933;">			}</span>
&nbsp;
<span style="color: #339933;">			private function handler( event : Event ) : void {</span>
<span style="color: #339933;">				trace( e.type );</span>
<span style="color: #339933;">			}</span>
<span style="color: #339933;">		]]&gt;</span>
<span style="color: #339933;">	&lt;/mx:Script&gt;</span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>That&#8217;s clean code. Good bye dispatcher, good bye sprite! But sometimes it can be quite difficult to maintain this. I personally would wish that actionscript objects, especially the EventDispatcher class, would provide a destroy() method. Calling it gets rid of all event listeners and also would unlisten to everything it has listened to. And for DisplayObjects it would also perform other operations like removing itself from its parent and destroying all children.</p>
<p>I&#8217;d also like to see the following method like this in EventDispatcher:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">EventDispatcher.<span style="color: #0066CC;">removeListener</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">type</span> : <span style="color: #0066CC;">String</span> = <span style="color: #000000; font-weight: bold;">null</span> , listener : <span style="color: #000000; font-weight: bold;">Function</span> = <span style="color: #000000; font-weight: bold;">null</span> , useCapture : <span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// so this would remove all listeners</span>
EventDispatcher.<span style="color: #0066CC;">removeListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// and this all listeners to enter frame</span>
EventDispatcher.<span style="color: #0066CC;">removeListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>I get around many issues by implementing something like a IEventListener interface:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">interface</span> IEventListener <span style="color: #66cc66;">&#123;</span>
<span style="color: #000000; font-weight: bold;">function</span> listenTo<span style="color: #66cc66;">&#40;</span> dispatcher : IEventDispatcher , <span style="color: #0066CC;">type</span> : <span style="color: #0066CC;">String</span> , listener : <span style="color: #000000; font-weight: bold;">Function</span> , useCapture : <span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>;
functon unlistenTo<span style="color: #66cc66;">&#40;</span> dispatcher : IEventDispatcher , <span style="color: #0066CC;">type</span> : <span style="color: #0066CC;">String</span> , listener : <span style="color: #000000; font-weight: bold;">Function</span> , useCapture : <span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>;
<span style="color: #000000; font-weight: bold;">function</span> destroy<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>; <span style="color: #808080; font-style: italic;">// will remove myself as event listener from all registered dispatchers</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Way to go :-)</p>
<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/09/26/weak-method-closure/' rel='bookmark' title='Weak Method Closure'>Weak Method Closure</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2008/07/21/nested-inner-functions-can-be-evil/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Garbage Collector and Dictionary</title>
		<link>http://blog.betabong.com/2008/07/18/garbage-collector-and-dictionary/</link>
		<comments>http://blog.betabong.com/2008/07/18/garbage-collector-and-dictionary/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 23:59:11 +0000</pubDate>
		<dc:creator>betabong</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=27</guid>
		<description><![CDATA[<p><a href="http://dispatchevent.org/mims/creating-weak-references-in-as3/">Weak references</a> are cool. No. they are substantial. I don&#8217;t know how we lived without them before. Anyway, they made our (we = flash developers) life better. I use them very often, when adding event listeners or caching with dictionaries&#8230; <a href="http://blog.betabong.com/2008/07/18/garbage-collector-and-dictionary/" class="read_more">Read more</a></p>
No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://dispatchevent.org/mims/creating-weak-references-in-as3/">Weak references</a> are cool. No. they are substantial. I don&#8217;t know how we lived without them before. Anyway, they made our (we = flash developers) life better. I use them very often, when adding event listeners or caching with dictionaries (and I&#8217;m sure I&#8217;d use them even more often if there was any more possibilty provided).</p>
<p>Still you can struggle over unexpected behaviour.<span id="more-27"></span> First of all there is no guarantee that objects are <a href="http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html">garbaged</a> (well it&#8217;s probably not a memory thing.. more about unreferencing, what the heck do I know?!) as soon as there aren&#8217;t any references left. But, in my experience, weak references work quite good.. I didn&#8217;t have to worry about them living for some more seconds or so. But. But! They&#8217;ll live on at least until next rendering step, meaning until actionscript execution is done.</p>
<p>I struggled over this with a validation manager, that keeps tracks of unvalidated objects in a weak dictionary. So when object unvalidates, it tells so to the validator who will validate before rendering update. Now let&#8217;s assume the object shall be destroyed in the mean time – it will unlisten to dispatchers, it will unlink sprites and so on.. but may be it&#8217;s already registered in the validator. So it&#8217;ll stay alive to fullfill next validation processing. (Which led into uncaught errors due to null references in the destroyed object in my example.)</p>
<p>I could of course unregister at the validator at destroy. But.. hmm.. I want my engine to be as fast and robust as possible and unregistering can be difficult and time consuming (especially when 1000 objects will be destroyed). So what I&#8217;ve done is, I set a flag &#8216;destroyed&#8217; when destruction is complete, and on each validation I&#8217;ll check for that flag:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> validateDisplay<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: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> _render_dirty <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #66cc66;">!</span>destroyed <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    render<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Checking against a boolean flag is fast as hell, so that&#8217;s cool. And also, it won&#8217;t happen often (it was really a rare exceptional case actually). So besides weak references in AS3 we still have to be careful as hell about memory leaks. By the way, the profiler in Flex Pro is just fucking great :-)</p>
<p>On a side note: Any one any info on MethodClosure objects lying around in memory?? I know what they are used for, but it seems they live and live and live&#8230;.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2008/07/18/garbage-collector-and-dictionary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Project &#8211; SVN Strategy</title>
		<link>http://blog.betabong.com/2008/07/16/flex-project-svn-strategy/</link>
		<comments>http://blog.betabong.com/2008/07/16/flex-project-svn-strategy/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 10:35:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.betabong.com/?p=13</guid>
		<description><![CDATA[<p>I like to keep all my projects on a svn server. So far this was just for myself and I didn&#8217;t care much about the simplicity of checking out and in – a little chaos is acceptable if you&#8217;re up&#8230; <a href="http://blog.betabong.com/2008/07/16/flex-project-svn-strategy/" class="read_more">Read more</a></p>
Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/12/03/test-movie-from-flex-to-flash-easy-way/' rel='bookmark' title='Test Movie from Flex to Flash (easy way)'>Test Movie from Flex to Flash (easy way)</a></li>
<li><a href='http://blog.betabong.com/2008/11/29/flex-builder-t-flash-ide/' rel='bookmark' title='Develop in Flex Builder, publish in Flash IDE (Mac OS X)'>Develop in Flex Builder, publish in Flash IDE (Mac OS X)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I like to keep all my projects on a svn server. So far this was just for myself and I didn&#8217;t care much about the simplicity of checking out and in – a little chaos is acceptable if you&#8217;re up to handle it ;)</p>
<p>Finally I was forced to rethink this strategy because I wanted to let other people work on a project. As many actionscript projects, this one also heavily relies on external libraries, most of them hosted by Google Code, another one being my own (closed) lib. So should I tell people: «hey, just svn checkout from here and there and then relink the libs in the project properties but don&#8217;t check in the updated settings for christ&#8217;s sake!»No. Too shaky, really.</p>
<p>Fortunately, SVN provides a fucking cool way to solve this issue: svn:externals. <span id="more-13"></span>Ha! This is so awesome, you won&#8217;t believe it ;-) Okay, here are the steps to follow (on a mac at least):</p>
<p>Create a flex project:</p>
<ul>
<li>project
<ul>
<li>html-template</li>
<li>src</li>
</ul>
</li>
</ul>
<p>Add a new directory:</p>
<ul>
<li>project
<ul>
<li>html-template</li>
<li>src</li>
<li>externals</li>
</ul>
</li>
</ul>
<p>Now put this on your svn, either by svn add or by putting in the repos and checking out again (well.. just as you did). If you&#8217;ve already got bin-debug or bin-release directories, just remove them on the repos and svn update (they are created with each publish in flex).</p>
<p>Now let&#8217;s say our project resides in ~/Documents/projects/project (path to project). Do the following in Terminal:</p>
<pre>cd ~/Documents/projects/project/externals
svn svn propedit svn:externals .</pre>
<p>This should open an editor (in my case I&#8217;ve defined textmate as my editor by doing:)</p>
<pre>export EDITOR='mate -w'</pre>
<p>Enter the following (example libraries):</p>
<pre>caurinatweener http://tweener.googlecode.com/svn/trunk/as3/
as3corelib http://as3corelib.googlecode.com/svn/</pre>
<p>You can also add a specific release:</p>
<pre>caurinatweener -r23 http://tweener.googlecode.com/svn/trunk/as3/</pre>
<p>(in TextMate save and close, if you use vim you know what to do anyway)</p>
<p>Now comes the magic part:</p>
<pre>svn up</pre>
<p>This will checkout all defined libraries into externals/xyz!! you do <code>svn commit</code> and now every time somebody checks out your project (or your externals directory) all the libs will be checked out automatically! I think this is just fucking awesome! :-)</p>
<p>Now in Eclipse all paths to your external libraries will be relative to the project (of course you have to add the libs there or change the paths – you should know how to do that ;))</p>
<p>Now all we need to is ignoring bin-release and bin-debug. We don&#8217;t want these directories to be in our svn repos:</p>
<pre>cd ~/Documents/projects/project
svn svn propedit svn:ignore .</pre>
<p>enter a list of directories or files to be ignored. in our case:</p>
<pre>bin-debug
bin-release</pre>
<p>That&#8217;s it! Thanks, svn!</p>
<p>Related posts:<ol>
<li><a href='http://blog.betabong.com/2008/12/03/test-movie-from-flex-to-flash-easy-way/' rel='bookmark' title='Test Movie from Flex to Flash (easy way)'>Test Movie from Flex to Flash (easy way)</a></li>
<li><a href='http://blog.betabong.com/2008/11/29/flex-builder-t-flash-ide/' rel='bookmark' title='Develop in Flex Builder, publish in Flash IDE (Mac OS X)'>Develop in Flex Builder, publish in Flash IDE (Mac OS X)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.betabong.com/2008/07/16/flex-project-svn-strategy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: blog.betabong.com @ 2012-02-05 06:40:05 -->
