<?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>BJÖRN ACKER &#124; Interactive Media</title>
	<atom:link href="http://www.bjoernacker.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bjoernacker.de</link>
	<description>Web Development, Online Games and Illustration</description>
	<lastBuildDate>Wed, 17 Apr 2013 13:44:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Hexdump a ByteArray</title>
		<link>http://www.bjoernacker.de/flash/hexdump-a-bytearray/</link>
		<comments>http://www.bjoernacker.de/flash/hexdump-a-bytearray/#comments</comments>
		<pubDate>Fri, 20 Apr 2012 20:32:30 +0000</pubDate>
		<dc:creator>bma</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.bjoernacker.de/?p=601</guid>
		<description><![CDATA[Here is a class to hexdump a ByteArray to a string inspired by HxD&#8230; 1 2 3 4 5 6 7 8 9 10 &#160;var ba:ByteArray = new ByteArray&#40;&#41;; &#160;ba.writeByte&#40;0x0a&#41;; &#160;ba.writeByte&#40;0x0a&#41;; &#160;ba.writeByte&#40;0x0a&#41;; &#160;ba.writeUTFBytes&#40;&#34;Testdump&#34;&#41; &#160;for &#40;var i:int = 0; i &#60; 80; i++&#41; &#160;&#123; &#160; &#160;ba.writeByte&#40;int&#40;Math.random&#40;&#41;*0x50&#41;&#41;; &#160;&#125; &#160;trace&#40;HexDump.dump&#40;ba&#41;&#41;; var ba:ByteArray = new ByteArray(); ba.writeByte(0x0a); ba.writeByte(0x0a); ba.writeByte(0x0a); [...]]]></description>
				<content:encoded><![CDATA[<p>Here is a class to hexdump a ByteArray to a string inspired by <a href="http://mh-nexus.de/en/hxd/">HxD</a>&#8230;<br />
<span id="more-601"></span></p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
</pre></td><td class="de1"><pre class="de1">&nbsp;<span class="kw2">var</span> ba<span class="sy0">:</span>ByteArray <span class="sy0">=</span> <span class="kw2">new</span> ByteArray<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;ba.<span class="me1">writeByte</span><span class="br0">&#40;</span>0x0a<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;ba.<span class="me1">writeByte</span><span class="br0">&#40;</span>0x0a<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;ba.<span class="me1">writeByte</span><span class="br0">&#40;</span>0x0a<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;ba.<span class="me1">writeUTFBytes</span><span class="br0">&#40;</span><span class="st0">&quot;Testdump&quot;</span><span class="br0">&#41;</span>
&nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i<span class="sy0">:</span>int <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> <span class="nu0">80</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span>
&nbsp;<span class="br0">&#123;</span>
&nbsp; &nbsp;ba.<span class="me1">writeByte</span><span class="br0">&#40;</span>int<span class="br0">&#40;</span>Math.<span class="me1">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">*</span>0x50<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;<span class="br0">&#125;</span>
&nbsp;trace<span class="br0">&#40;</span>HexDump.<span class="me1">dump</span><span class="br0">&#40;</span>ba<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse"> var ba:ByteArray = new ByteArray();
 ba.writeByte(0x0a);
 ba.writeByte(0x0a);
 ba.writeByte(0x0a);
 ba.writeUTFBytes("Testdump")
 for (var i:int = 0; i &lt; 80; i++)
 {
   ba.writeByte(int(Math.random()*0x50));
 }
 trace(HexDump.dump(ba));</pre></div></div>

<p>will output</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
</pre></td><td class="de1"><pre class="de1">Offset 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 0A 0A 0A <span class="nu0">54</span> <span class="nu0">65</span> <span class="nu0">73</span> <span class="nu0">74</span> <span class="nu0">64</span> <span class="nu0">75</span> 6D <span class="nu0">70</span> 06 0B <span class="nu0">27</span> 3D 3B ...<span class="me1">Testdump</span>..<span class="st0">'=;</span>
<span class="st0">00000010 4C 2D 39 22 46 43 1E 20 03 0E 33 1F 07 10 30 17 L-9&quot;FC. ..3...0.</span>
<span class="st0">00000020 15 10 3A 19 43 1D 16 3B 02 4F 26 08 25 0C 3E 0B ..:.C..;.O&amp;.%.&gt;.</span>
<span class="st0">00000030 37 2A 3E 33 42 2A 2F 04 35 0F 0E 29 06 2E 40 36 7*&gt;3B*/.5..)..@6</span>
<span class="st0">00000040 3F 13 14 1C 33 4D 46 40 41 2B 1C 03 3E 3F 1D 3B ?...3MF@A+..&gt;?.;</span>
<span class="st0">00000050 2E 3D 21 15 17 42 2E 48 12 37 49 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.=!..B.H.7I</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">Offset 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 0A 0A 0A 54 65 73 74 64 75 6D 70 06 0B 27 3D 3B ...Testdump..'=;
00000010 4C 2D 39 22 46 43 1E 20 03 0E 33 1F 07 10 30 17 L-9"FC. ..3...0.
00000020 15 10 3A 19 43 1D 16 3B 02 4F 26 08 25 0C 3E 0B ..:.C..;.O&amp;.%.&gt;.
00000030 37 2A 3E 33 42 2A 2F 04 35 0F 0E 29 06 2E 40 36 7*&gt;3B*/.5..)..@6
00000040 3F 13 14 1C 33 4D 46 40 41 2B 1C 03 3E 3F 1D 3B ?...3MF@A+..&gt;?.;
00000050 2E 3D 21 15 17 42 2E 48 12 37 49                .=!..B.H.7I</pre></div></div>

<p>This is the HexDump Class:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar" style="right: 15px;" ><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"style=" height: 420px;"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="de1"><pre class="de1"><span class="kw2">package</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="kw2">import</span> flash.<span class="me1">utils</span>.<span class="me1">ByteArray</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="coMULTI">/**</span>
<span class="coMULTI">&nbsp; &nbsp; * @author Björn Acker | www.bjoernacker.de</span>
<span class="coMULTI">&nbsp; &nbsp; */</span>
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">class</span> HexDump
&nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> static <span class="kw2">function</span> dump<span class="br0">&#40;</span>buffer<span class="sy0">:</span>ByteArray<span class="br0">&#41;</span><span class="sy0">:</span>String
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> out<span class="sy0">:</span>String <span class="sy0">=</span> fillUp<span class="br0">&#40;</span><span class="st0">&quot;Offset&quot;</span><span class="sy0">,</span> <span class="nu0">8</span><span class="sy0">,</span> <span class="st0">&quot; &quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot; &nbsp;00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<span class="es0">\n</span>&quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> offset<span class="sy0">:</span>int <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> l<span class="sy0">:</span>int <span class="sy0">=</span> buffer.<span class="me1">length</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> row<span class="sy0">:</span>String <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer.<span class="me1">position</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i<span class="sy0">:</span>int <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> l<span class="sy0">;</span> i <span class="sy0">+=</span> <span class="nu0">15</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; row <span class="sy0">+=</span> fillUp<span class="br0">&#40;</span>offset.<span class="me1">toString</span><span class="br0">&#40;</span><span class="nu0">16</span><span class="br0">&#41;</span>.<span class="me1">toUpperCase</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="nu0">8</span><span class="sy0">,</span> <span class="st0">&quot;0&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot; &nbsp;&quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> n<span class="sy0">:</span>int <span class="sy0">=</span> Math.<span class="me1">min</span><span class="br0">&#40;</span><span class="nu0">16</span><span class="sy0">,</span> buffer.<span class="me1">length</span> <span class="sy0">-</span> buffer.<span class="me1">position</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> string<span class="sy0">:</span>String <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> j<span class="sy0">:</span>int <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> j <span class="sy0">&lt;</span> <span class="nu0">16</span><span class="sy0">;</span> <span class="sy0">++</span>j<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>j <span class="sy0">&lt;</span> n<span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> value<span class="sy0">:</span>int <span class="sy0">=</span> buffer.<span class="me1">readUnsignedByte</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string <span class="sy0">+=</span> value <span class="sy0">&gt;=</span> <span class="nu0">32</span> <span class="sy0">?</span> String.<span class="me1">fromCharCode</span><span class="br0">&#40;</span>value<span class="br0">&#41;</span> <span class="sy0">:</span> <span class="st0">&quot;.&quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; row <span class="sy0">+=</span> fillUp<span class="br0">&#40;</span>value.<span class="me1">toString</span><span class="br0">&#40;</span><span class="nu0">16</span><span class="br0">&#41;</span>.<span class="me1">toUpperCase</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="nu0">2</span><span class="sy0">,</span> <span class="st0">&quot;0&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot; &quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; offset<span class="sy0">++;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; row <span class="sy0">+=</span> <span class="st0">&quot; &nbsp; &quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string <span class="sy0">+=</span> <span class="st0">&quot; &quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; row <span class="sy0">+=</span> <span class="st0">&quot; &quot;</span> <span class="sy0">+</span> string <span class="sy0">+</span> <span class="st0">&quot;<span class="es0">\n</span>&quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; out <span class="sy0">+=</span> row<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> out<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> static <span class="kw2">function</span> fillUp<span class="br0">&#40;</span>value<span class="sy0">:</span>String<span class="sy0">,</span> count<span class="sy0">:</span>int<span class="sy0">,</span> fillWith<span class="sy0">:</span>String<span class="br0">&#41;</span><span class="sy0">:</span>String
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> l<span class="sy0">:</span>int <span class="sy0">=</span> count <span class="sy0">-</span> value.<span class="me1">length</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> ret<span class="sy0">:</span>String <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="sy0">--</span>l <span class="sy0">&gt;</span> <span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret <span class="sy0">+=</span> fillWith<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> ret <span class="sy0">+</span> value<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">package
{
    import flash.utils.ByteArray;

    /**
    * @author Björn Acker | www.bjoernacker.de
    */
    public class HexDump
    {

        public static function dump(buffer:ByteArray):String
        {
            var out:String = fillUp("Offset", 8, " ") + "  00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n";
            var offset:int = 0;
            var l:int = buffer.length;
            var row:String = "";
            buffer.position = 0;
            for (var i:int = 0; i &lt; l; i += 15)
            {
                row += fillUp(offset.toString(16).toUpperCase(), 8, "0") + "  ";
                var n:int = Math.min(16, buffer.length - buffer.position);
                var string:String = "";
                for (var j:int = 0; j &lt; 16; ++j)
                {
                    if (j &lt; n)                     
                    {
                        var value:int = buffer.readUnsignedByte();
                        string += value &gt;= 32 ? String.fromCharCode(value) : ".";
                        row += fillUp(value.toString(16).toUpperCase(), 2, "0") + " ";
                        offset++;
                    }
                    else
                    {
                        row += "   ";
                        string += " ";
                    }
                }
                row += " " + string + "\n";
            }
            out += row;
            return out;
        }

        private static function fillUp(value:String, count:int, fillWith:String):String
        {
            var l:int = count - value.length;
            var ret:String = "";
            while (--l &gt; -1)
            ret += fillWith;
            return ret + value;
        }
    }
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bjoernacker.de/flash/hexdump-a-bytearray/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AssetsProtector &#8211; Protect SWF, JPEG and XML files</title>
		<link>http://www.bjoernacker.de/flash/assetsprotector-protect-your-media-files/</link>
		<comments>http://www.bjoernacker.de/flash/assetsprotector-protect-your-media-files/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 13:55:43 +0000</pubDate>
		<dc:creator>bma</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.bjoernacker.de/?p=581</guid>
		<description><![CDATA[I&#8217;ve developed a little tool to protect files like SWFs, PNGs, JPEGs or XMLs from beeing decompiled or directly used. So e.g. if you don&#8217;t like to hear your sounds playing in another game or you don&#8217;t want to allow poking around in your code AssetsProtector could help. The AssetsProtector toolkit is composed of 3 components: Protector [...]]]></description>
				<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-596" title="Frightened Assets" src="http://www.bjoernacker.de/wp-content/uploads/2012/02/blog_header1.jpg" alt="" width="690" height="155" /></p>
<p>I&#8217;ve developed a little tool to protect files like SWFs, PNGs, JPEGs or XMLs from beeing decompiled or directly used. So e.g. if you don&#8217;t like to hear your sounds playing in another game or you don&#8217;t want to allow poking around in your code <a title="Assets Protection for the Flash Platform" href="http://www.assetsprotector.net" target="_blank"><strong>AssetsProtector</strong> </a>could help.</p>
<p><span id="more-581"></span>The AssetsProtector toolkit is composed of 3 components:</p>
<ul>
<li><strong>Protector Machine</strong> &#8211; an Air app to encrypt your assets &#8211; it also supports batch protecting and has a command line integration</li>
<li><strong>Protector Agent</strong> &#8211; the preloader which loads your main SWF and assets and decrypts them at runtime</li>
<li><strong>Assets Loader</strong> &#8211; an AS3 library to simplify the assets loading. If you want to load protected files you have to use this library &#8211; it will auto-detect if the loaded file is protected or not</li>
</ul>
<p>The tool will at least make it a bit harder for people looking at your files from &#8220;outside&#8221; using decompilers like &#8220;ASV&#8221; or &#8220;Sothink SWF Decompiler&#8221; as both don&#8217;t know what to do with those encrypted SWFs and both completely crashed when trying to decompile the ProtectorAgent. The &#8220;Protector Agent&#8221; preloader also blocks <a href="http://jpauclair.net/2010/02/17/one-swf-to-rule-them-all-the-almighty-preloadswf/" target="_blank">PreloadSWFs</a> like <a href="http://code.google.com/p/doomsdayconsole/" target="_blank">Doomsday Console</a> or <a href="http://jpauclair.net/flashpreloadprofiler/" target="_blank">FlashPreloadProfiler</a>.<br />
Actually it won&#8217;t help against those smart guys poking around in memory at runtime &#8211; to make it really safe  put all your sensitive functions on a server&#8230;</p>
<p>Here is a brief tutorial of how to use the tool</p>
<div class="sc-video">
<div>
			<object type="application/x-shockwave-flash" style="width:570px; height:347px;" data="http://www.youtube.com/v/ERjArbNDAHc&amp;hl=en_US&amp;fs=1&amp;"><param name="movie" value="http://www.youtube.com/v/ERjArbNDAHc&amp;fs=1&amp;" /></object>
		</div>
</p></div>
<p>The usage of the Asset Loader class is as easy as the following example:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar" style="right: 15px;" ><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"style=" height: 420px;"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="de1"><pre class="de1"><span class="kw2">private</span> <span class="kw2">function</span> startLoading<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp; &nbsp; <span class="co1">//Create the asset loader and add the assets to the load queue</span>
&nbsp; &nbsp; _assetsLoader <span class="sy0">=</span> <span class="kw2">new</span> AssetsLoader<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; _assetsLoader.<span class="me1">addAsset</span><span class="br0">&#40;</span><span class="st0">&quot;agent&quot;</span><span class="sy0">,</span> <span class="st0">&quot;assets/agent.swf&quot;</span><span class="sy0">,</span> AssetType.<span class="me1">DISPLAY_OBJECT</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; _assetsLoader.<span class="me1">addAsset</span><span class="br0">&#40;</span><span class="st0">&quot;xml&quot;</span><span class="sy0">,</span> <span class="st0">&quot;assets/text.xml&quot;</span><span class="sy0">,</span> AssetType.<span class="me1">TEXT</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; _assetsLoader.<span class="me1">addAsset</span><span class="br0">&#40;</span><span class="st0">&quot;machine&quot;</span><span class="sy0">,</span> <span class="st0">&quot;assets/machine.jpg&quot;</span><span class="sy0">,</span> AssetType.<span class="me1">DISPLAY_OBJECT</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; _assetsLoader.<span class="me1">addAsset</span><span class="br0">&#40;</span><span class="st0">&quot;assets&quot;</span><span class="sy0">,</span> <span class="st0">&quot;assets/assets.png&quot;</span><span class="sy0">,</span> AssetType.<span class="me1">DISPLAY_OBJECT</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; _assetsLoader.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span><span class="sy0">,</span> onComplete<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; _assetsLoader.<span class="me1">addEventListener</span><span class="br0">&#40;</span>AssetProgressEvent.<span class="me1">EVENT</span><span class="sy0">,</span> onProgress<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; _assetsLoader.<span class="me1">addEventListener</span><span class="br0">&#40;</span>AssetLoadedEvent.<span class="me1">EVENT</span><span class="sy0">,</span> onAssetLoaded<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; _assetsLoader.<span class="me1">load</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="coMULTI">/**</span>
<span class="coMULTI">&nbsp;* Will be called if a asset has been loaded and is ready to use</span>
<span class="coMULTI">&nbsp;*/</span>
<span class="kw2">private</span> <span class="kw2">function</span> onAssetLoaded<span class="br0">&#40;</span>e<span class="sy0">:</span>AssetLoadedEvent<span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="co1">//The &quot;agent&quot; asset has the logo movieclip exported for AS</span>
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">currentAssetKey</span> <span class="sy0">==</span> <span class="st0">&quot;agent&quot;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; _logo <span class="sy0">=</span> Sprite<span class="br0">&#40;</span> AssetsLoader.<span class="me1">getAssetClassInstance</span><span class="br0">&#40;</span><span class="st0">&quot;agent&quot;</span><span class="sy0">,</span> <span class="st0">&quot;asset_logo&quot;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; _container.<span class="me1">addChild</span><span class="br0">&#40;</span>_logo<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">onResize</span><span class="br0">&#40;</span><span class="kw2">null</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="coMULTI">/**</span>
<span class="coMULTI">&nbsp;* Will be triggered while an asset is loading</span>
<span class="coMULTI">&nbsp;*/</span>
<span class="kw2">private</span> <span class="kw2">function</span> onProgress<span class="br0">&#40;</span>e<span class="sy0">:</span>AssetProgressEvent<span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; trace<span class="br0">&#40;</span>e.<span class="me1">currentAssetKey</span><span class="sy0">,</span> e.<span class="me1">assetsLoaded</span><span class="sy0">,</span> e.<span class="me1">assetsTotal</span><span class="sy0">,</span> e.<span class="me1">percent</span><span class="sy0">,</span> e.<span class="me1">bytesLoaded</span><span class="sy0">,</span> e.<span class="me1">bytesTotal</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="coMULTI">/**</span>
<span class="coMULTI">&nbsp;* Will be called if all assets are loaded</span>
<span class="coMULTI">&nbsp;*/</span>
<span class="kw2">private</span> <span class="kw2">function</span> onComplete<span class="br0">&#40;</span>e<span class="sy0">:</span>Event<span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="co1">//do something very important</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">private function startLoading():void
	//Create the asset loader and add the assets to the load queue
	_assetsLoader = new AssetsLoader();
	_assetsLoader.addAsset("agent", "assets/agent.swf", AssetType.DISPLAY_OBJECT);
	_assetsLoader.addAsset("xml", "assets/text.xml", AssetType.TEXT);
	_assetsLoader.addAsset("machine", "assets/machine.jpg", AssetType.DISPLAY_OBJECT);
	_assetsLoader.addAsset("assets", "assets/assets.png", AssetType.DISPLAY_OBJECT);
	_assetsLoader.addEventListener(Event.COMPLETE, onComplete);
	_assetsLoader.addEventListener(AssetProgressEvent.EVENT, onProgress);
	_assetsLoader.addEventListener(AssetLoadedEvent.EVENT, onAssetLoaded);
	_assetsLoader.load();
}

/**
 * Will be called if a asset has been loaded and is ready to use
 */
private function onAssetLoaded(e:AssetLoadedEvent):void
{
	//The "agent" asset has the logo movieclip exported for AS
	if (e.currentAssetKey == "agent")
	{
		_logo = Sprite( AssetsLoader.getAssetClassInstance("agent", "asset_logo") );
		_container.addChild(_logo);
		onResize(null);
	}
}

/**
 * Will be triggered while an asset is loading
 */
private function onProgress(e:AssetProgressEvent):void
{
	trace(e.currentAssetKey, e.assetsLoaded, e.assetsTotal, e.percent, e.bytesLoaded, e.bytesTotal);
}

/**
 * Will be called if all assets are loaded
 */
private function onComplete(e:Event):void
{
	//do something very important
}</pre></div></div>

<p>&nbsp;</p>
<p>See the tool&#8217;s website // <strong><a title="Assets Protection for the Flash Platform" href="http://www.assetsprotector.net" target="_blank">www.assetsprotector.net</a></strong></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernacker.de/flash/assetsprotector-protect-your-media-files/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Export Characters to Sprites with 3ds Max</title>
		<link>http://www.bjoernacker.de/3ds-max/export-characters-to-sprites-with-3ds-max/</link>
		<comments>http://www.bjoernacker.de/3ds-max/export-characters-to-sprites-with-3ds-max/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 23:56:13 +0000</pubDate>
		<dc:creator>bma</dc:creator>
				<category><![CDATA[3ds Max]]></category>

		<guid isPermaLink="false">http://www.bjoernacker.de/?p=532</guid>
		<description><![CDATA[One big issue of my last 2D and 2.5D game projects was to automate and optimize the character&#8217;s export process. For that I&#8217;ve developed a small exporter tool for 3ds Max written in MAXScript which could render your frames in a batch. So, if you are working with 3ds Max and are building 2D or [...]]]></description>
				<content:encoded><![CDATA[<p>One big issue of my last 2D and 2.5D game projects was to automate and optimize the character&#8217;s export process. For that I&#8217;ve developed a small exporter tool for 3ds Max written in MAXScript which could render your frames in a batch.<br />
So, if you are working with 3ds Max and are building 2D or 2.5D (isometric) games e.g. with Starling or ND2D, than this script might be useful.<br />
<span id="more-532"></span></p>
<p>To get started please download the source files //<strong> <a title="Download the source files" href="http://www.bjoernacker.de/wp-content/uploads/2012/02/CharacterExporter.zip" target="_blank">CharacterExporter</a></strong></p>
<p>After unzipping the ZIP file launch 3ds Max and install the exporter script by either selecting MAXScript / Run Script&#8230;</p>
<p><a href="http://www.bjoernacker.de/wp-content/uploads/2012/02/2012-02-09_230516.png" rel="shadowbox[sbpost-532];player=img;"><img class="alignnone size-medium wp-image-539" title="2012-02-09_230516" src="http://www.bjoernacker.de/wp-content/uploads/2012/02/2012-02-09_230516-300x286.png" alt="" width="300" height="286" /></a></p>
<p>and then select &#8220;CharacterExporter.mzp&#8221; from the source files and click open</p>
<p><a href="http://www.bjoernacker.de/wp-content/uploads/2012/02/2012-02-09_230621.png" rel="shadowbox[sbpost-532];player=img;"><img class="alignnone size-medium wp-image-540" title="2012-02-09_230621" src="http://www.bjoernacker.de/wp-content/uploads/2012/02/2012-02-09_230621-300x221.png" alt="" width="300" height="221" /></a></p>
<p>or just dragging the mzp file right into the 3ds Max application. Max will install all needed files automatically into the right places.</p>
<p>Next step is to add the exporter tool to a toolbar by opening the Customize User Interface Panel (Customize / Customize User Interface).<br />
Click the  &#8221;Toolbars&#8221; tab and choose &#8220;Electronauts&#8221; as the category. Finally drag the &#8220;Character Exporter&#8221; icon to a toolbar of your choice.</p>
<p><a href="http://www.bjoernacker.de/wp-content/uploads/2012/02/2012-02-09_230855.png" rel="shadowbox[sbpost-532];player=img;"><img class="alignnone size-medium wp-image-541" title="2012-02-09_230855" src="http://www.bjoernacker.de/wp-content/uploads/2012/02/2012-02-09_230855-300x273.png" alt="" width="300" height="273" /></a></p>
<p>Now you are ready to go. Click the icon to open up the CharacterExporter panel.</p>
<p><a href="http://www.bjoernacker.de/wp-content/uploads/2012/02/2012-02-09_230951.png" rel="shadowbox[sbpost-532];player=img;"><img class="alignnone size-medium wp-image-542" title="2012-02-09_230951" src="http://www.bjoernacker.de/wp-content/uploads/2012/02/2012-02-09_230951-178x300.png" alt="" width="178" height="300" /></a></p>
<p>The exporter provides you the following options:</p>
<ol>
<li><strong>Select your &#8220;RenderStage&#8221;</strong><br />
When exporting the characters will be loaded into the render stage and rendered with the provided settings.<br />
I&#8217;ve included a sample render stage which contains the must have elements. It&#8217;s a base for modifications e.g. different light settings or different renderers like VRay. It&#8217;s  mandatory that there&#8217;s a camera named &#8220;Camera&#8221;.</li>
<li><strong>Adjust how many directions or different angles shall be rendered</strong></li>
<li><strong>Export</strong></li>
</ol>
<p>After pressing the &#8220;Export&#8221; button the exporter will ask you for the source and the target folder to export the images into.</p>
<p>It&#8217;s important to maintain the source folder structure (please also see the &#8220;source&#8221; folder in the archive):<br />
Every character must have its own folder. Inside this folder the different animation types like &#8220;idle&#8221;, &#8220;walk&#8221; or &#8220;attack&#8221; have to be setup in different .max files.<br />
The exporter will now scan the source folder and render all files in a batch. It will adopt the animation length and the render dimensions defined in the files.</p>
<p>One of the best tools to create sprite sheets out of all those frames is <a href="http://www.texturepacker.com/" target="_blank">TexturePacker</a>.</p>
<p>Now some slightly more advanced stuff:<br />
Sometimes it is important to attach e.g. a flash animation to the character&#8217;s weapon muzzle which is moving in space frame by frame. To handle this you can define dummy objects, put them in the right place and attach them to your character. Just prefix them with &#8220;pivot_&#8221; e.g. &#8220;pivot_muzzle&#8221; and the exporter stores the offsets of the according pivot frame by frame in a <strong><a title="Example JSON File" href="http://www.bjoernacker.de/wp-content/uploads/2012/02/npc.txt" target="_blank">JSON </a></strong>file (if you&#8217;re using Chrome this <strong><a title="JSON Formatter" href="https://chrome.google.com/webstore/detail/bcjindcccaagfpapjjmafapmmgkkhgoa" target="_blank">extension </a></strong>for formatting JSON files is quite handy).</p>
<p><a href="http://www.bjoernacker.de/wp-content/uploads/2012/02/2012-02-09_231550.png" rel="shadowbox[sbpost-532];player=img;"><img class="alignnone size-medium wp-image-543" title="2012-02-09_231550" src="http://www.bjoernacker.de/wp-content/uploads/2012/02/2012-02-09_231550-300x278.png" alt="" width="300" height="278" /></a></p>
<p>The offset defines the x and y distance from the image&#8217;s center to the pivot&#8217;s transformed 2D postion, e.g. the x/y offset of &#8220;pivot_muzzle_left&#8221; in the first frame of the provided &#8220;die&#8221; animation example  is -56/-55, which is defined in the &#8220;pivot_muzzle_left&#8221; array of the &#8220;die&#8221; object:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
</pre></td><td class="de1"><pre class="de1"><span class="st0">&quot;pivot_muzzle_left&quot;</span><span class="sy0">:</span> <span class="br0">&#91;</span>
&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span><span class="st0">&quot;x&quot;</span><span class="sy0">:</span> <span class="sy0">-</span><span class="nu0">56</span><span class="sy0">,</span><span class="st0">&quot;y&quot;</span><span class="sy0">:</span> <span class="sy0">-</span><span class="nu0">55</span><span class="br0">&#125;</span><span class="sy0">,</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">"pivot_muzzle_left": [
     {"x": -56,"y": -55},</pre></div></div>

<p><a href="http://www.bjoernacker.de/wp-content/uploads/2012/02/offset.png" rel="shadowbox[sbpost-532];player=img;"><img class="alignnone size-medium wp-image-559" title="Offset Example" src="http://www.bjoernacker.de/wp-content/uploads/2012/02/offset-300x225.png" alt="" width="300" height="225" /></a></p>
<p>To grab the the right offset object out of the array you can use this formula:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
</pre></td><td class="de1"><pre class="de1">index <span class="sy0">=</span> <span class="br0">&#40;</span>currentDirection <span class="sy0">-</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="sy0">*</span> numberOfAnimationFrames <span class="sy0">+</span> currentFrame</pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">index = (currentDirection - 1) * numberOfAnimationFrames + currentFrame</pre></div></div>

<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernacker.de/3ds-max/export-characters-to-sprites-with-3ds-max/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>28 Bratwursts Later &#8211; Zombie 2.5D Shooter Game</title>
		<link>http://www.bjoernacker.de/flash/28-bratwurst-later-zombie-2-5d-shooter-game/</link>
		<comments>http://www.bjoernacker.de/flash/28-bratwurst-later-zombie-2-5d-shooter-game/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 20:55:38 +0000</pubDate>
		<dc:creator>bma</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.bjoernacker.de/?p=518</guid>
		<description><![CDATA[&#8220;23.12.2012: Scientists finally have interpreted the last icon of the dresden codex. It shows a bratwurst&#8230;&#8221; Together with some mates I&#8217;m currently working in my spare time on a small fun zombie 2.5D shooter game with the fruity title &#8220;28 Bratwursts Later&#8221;. It&#8217;s developed with Flash and uses the Stage3D framework ND2D and it has evolved far enough to show at least a short video. The final version [...]]]></description>
				<content:encoded><![CDATA[<p><em>&#8220;23.12.2012: Scientists finally have interpreted the last icon of the dresden codex. It shows a bratwurst&#8230;&#8221;</em></p>
<p><a href="http://www.bjoernacker.de/wp-content/uploads/2012/02/Bildschirmfoto-2012-02-03-um-21.38.35.png" rel="shadowbox[sbpost-518];player=img;"><img class="alignnone size-medium wp-image-521" title="28BL" src="http://www.bjoernacker.de/wp-content/uploads/2012/02/Bildschirmfoto-2012-02-03-um-21.38.35-300x167.png" alt="" width="300" height="167" /></p>
<p></a><a href="http://www.bjoernacker.de/wp-content/uploads/2012/02/Bildschirmfoto-2012-02-03-um-22.08.37.png" rel="shadowbox[sbpost-518];player=img;"><img class="alignnone size-medium wp-image-526" title="28BL" src="http://www.bjoernacker.de/wp-content/uploads/2012/02/Bildschirmfoto-2012-02-03-um-22.08.37-300x165.png" alt="" width="300" height="165" /></a></p>
<p>Together with some mates I&#8217;m currently working in my spare time on a small fun zombie 2.5D shooter game with the fruity title &#8220;28 Bratwursts Later&#8221;.<br />
It&#8217;s developed with Flash and uses the Stage3D framework ND2D and it has evolved far enough to show at least a short video.</p>
<p><span id="more-518"></span></p>
<div class="sc-video">
<div>
			<object type="application/x-shockwave-flash" style="width:570px; height:347px;" data="http://www.youtube.com/v/TL9t2fRWAeg&amp;hl=en_US&amp;fs=1&amp;"><param name="movie" value="http://www.youtube.com/v/TL9t2fRWAeg&amp;fs=1&amp;" /></object>
		</div>
</p></div>
<p>The final version will feature 10+ different weapons, 5 maps with lots of different quests, 6+ NPC types with various AIs and a &#8220;bold&#8221; soundtrack.<br />
May be, if there is some time and motivation left, a multiplayer cooperative gameplay mode could be feasible.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernacker.de/flash/28-bratwurst-later-zombie-2-5d-shooter-game/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>ND2D &#8211; Advanced Camera with Parallax Layers</title>
		<link>http://www.bjoernacker.de/flash/nd2d-advanced-camera-with-parallax-layers/</link>
		<comments>http://www.bjoernacker.de/flash/nd2d-advanced-camera-with-parallax-layers/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 22:52:17 +0000</pubDate>
		<dc:creator>bma</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://bjoernacker.de/blog/?p=131</guid>
		<description><![CDATA[For my current game I&#8217;ve built an advanced camera to use with the ND2D framework. It supports parallax layers depending on their z (depth) settings map / level boundaries constraints shaking with a given strength and duration focusing a target zooming out based on the  target&#8217;s speed To see a small demo please click the image [...]]]></description>
				<content:encoded><![CDATA[<p>For my current game I&#8217;ve built an advanced camera to use with the <a href="https://github.com/nulldesign/nd2d">ND2D</a> framework.<br />
It supports</p>
<ul>
<li>parallax layers depending on their z (depth) settings</li>
<li>map / level boundaries constraints</li>
<li>shaking with a given strength and duration</li>
<li>focusing a target</li>
<li>zooming out based on the  target&#8217;s speed</li>
</ul>
<p>To see a small demo please click the image below. Use the arrow keys to control the ship: cursor left / right for turning and cursor up/down for speed.<br />
Press the &#8220;Shake&#8221; button to shake the screen.<br />
<a href="http://www.bjoernacker.de/vault/advancedcamera/" rel="shadowbox;width=800;height=800"><br />
<img class="alignnone size-full wp-image-489" title="advancedCamera2d-2" src="http://www.bjoernacker.de/wp-content/uploads/2012/01/advancedCamera2d-2.jpg" alt="" width="580" height="215" /></a></p>
<p><span id="more-131"></span>The usage is quite simple&#8230;<br />
You have to define at least one &#8220;Parallax Layer&#8221; which acts as a container for your (game-) objects. For each parallax layer you can define its z (depth) value &#8211; the greater the valuie the further away and the smaller the object will be rendered.  The amount of the perspective distortion is controlled by the <strong>focalLength</strong> property in the <strong>AdvancedCamera2D</strong> class.</p>
<p>First create some parallax layer instances, where the first paramter is the z value:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
</pre></td><td class="de1"><pre class="de1">_layer1 <span class="sy0">=</span> <span class="kw2">new</span> ParallaxLayer<span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//cloud layer</span>
_layer2 <span class="sy0">=</span> <span class="kw2">new</span> ParallaxLayer<span class="br0">&#40;</span><span class="nu0">70</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//ship layer</span>
_layer3 <span class="sy0">=</span> <span class="kw2">new</span> ParallaxLayer<span class="br0">&#40;</span><span class="nu0">120</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// tiles layer</span>
_layer4 <span class="sy0">=</span> <span class="kw2">new</span> ParallaxLayer<span class="br0">&#40;</span><span class="nu0">250</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// cloud layer</span>
_layer5 <span class="sy0">=</span> <span class="kw2">new</span> ParallaxLayer<span class="br0">&#40;</span><span class="nu0">600</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// tiles layer</span>
_layer6 <span class="sy0">=</span> <span class="kw2">new</span> ParallaxLayer<span class="br0">&#40;</span><span class="nu0">1000</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// tiles layer</span>
_layer7 <span class="sy0">=</span> <span class="kw2">new</span> ParallaxLayer<span class="br0">&#40;</span><span class="nu0">2000</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// planet layer</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">_layer1 = new ParallaxLayer(0); //cloud layer
_layer2 = new ParallaxLayer(70); //ship layer
_layer3 = new ParallaxLayer(120); // tiles layer
_layer4 = new ParallaxLayer(250); // cloud layer
_layer5 = new ParallaxLayer(600); // tiles layer
_layer6 = new ParallaxLayer(1000); // tiles layer
_layer7 = new ParallaxLayer(2000); // planet layer</pre></div></div>

<p>Than add those layers to the display list. Important to note is, that you must add them in the right order &#8211; from far away to near.</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
</pre></td><td class="de1"><pre class="de1">addChild<span class="br0">&#40;</span>_layer7<span class="br0">&#41;</span><span class="sy0">;</span>
addChild<span class="br0">&#40;</span>_layer6<span class="br0">&#41;</span><span class="sy0">;</span>
addChild<span class="br0">&#40;</span>_layer5<span class="br0">&#41;</span><span class="sy0">;</span>
addChild<span class="br0">&#40;</span>_layer4<span class="br0">&#41;</span><span class="sy0">;</span>
addChild<span class="br0">&#40;</span>_layer3<span class="br0">&#41;</span><span class="sy0">;</span>
addChild<span class="br0">&#40;</span>_layer2<span class="br0">&#41;</span><span class="sy0">;</span>
addChild<span class="br0">&#40;</span>_layer1<span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">addChild(_layer7);
addChild(_layer6);
addChild(_layer5);
addChild(_layer4);
addChild(_layer3);
addChild(_layer2);
addChild(_layer1);</pre></div></div>

<p>Create the advanced camera and also attach the layers to it</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
</pre></td><td class="de1"><pre class="de1">_cam <span class="sy0">=</span> <span class="kw2">new</span> AdvancedCamera2D<span class="br0">&#40;</span>camera<span class="br0">&#41;</span><span class="sy0">;</span>
_cam.<span class="me1">addLayer</span><span class="br0">&#40;</span>_layer1<span class="br0">&#41;</span><span class="sy0">;</span>
_cam.<span class="me1">addLayer</span><span class="br0">&#40;</span>_layer2<span class="br0">&#41;</span><span class="sy0">;</span>
_cam.<span class="me1">addLayer</span><span class="br0">&#40;</span>_layer3<span class="br0">&#41;</span><span class="sy0">;</span>
_cam.<span class="me1">addLayer</span><span class="br0">&#40;</span>_layer4<span class="br0">&#41;</span><span class="sy0">;</span>
_cam.<span class="me1">addLayer</span><span class="br0">&#40;</span>_layer5<span class="br0">&#41;</span><span class="sy0">;</span>
_cam.<span class="me1">addLayer</span><span class="br0">&#40;</span>_layer6<span class="br0">&#41;</span><span class="sy0">;</span>
_cam.<span class="me1">addLayer</span><span class="br0">&#40;</span>_layer7<span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">_cam = new AdvancedCamera2D(camera);
_cam.addLayer(_layer1);
_cam.addLayer(_layer2);
_cam.addLayer(_layer3);
_cam.addLayer(_layer4);
_cam.addLayer(_layer5);
_cam.addLayer(_layer6);
_cam.addLayer(_layer7);</pre></div></div>

<p>Now you can set the camera&#8217;s target. This could be any Node2D based object</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
</pre></td><td class="de1"><pre class="de1">_cam.<span class="me1">setTarget</span><span class="br0">&#40;</span>aTarget<span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">_cam.setTarget(aTarget);</pre></div></div>

<p>You can also define the world&#8217;s / level&#8217;s bounds. The <strong>bounds</strong> property is a Rectangle which works this way:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
</pre></td><td class="de1"><pre class="de1">_cam.<span class="me1">bounds</span> <span class="sy0">=</span> <span class="kw2">new</span> Rectangle<span class="br0">&#40;</span> <span class="sy0">-</span><span class="nu0">2048</span><span class="sy0">,</span> <span class="sy0">-</span><span class="nu0">2048</span><span class="sy0">,</span> <span class="nu0">2048</span><span class="sy0">,</span> <span class="nu0">2048</span> <span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">_cam.bounds = new Rectangle( -2048, -2048, 2048, 2048 );</pre></div></div>

<p>In this case the x dimension goes from -2048 tp 2048 and the y dimension from -2048 to 2048 pixels. The camera will automatically stop scrolling if the boundaries are exceeded.</p>
<p>With the <strong>movementZoomFactor</strong> you can adjust how much the camera shall zoom out depending on the target&#8217;s current speed.</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
</pre></td><td class="de1"><pre class="de1">_cam.<span class="me1">movementZoomFactor</span> <span class="sy0">=</span> <span class="nu0">40</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">_cam.movementZoomFactor = 40;</pre></div></div>

<p>I hope you find this useful? If you have any comments or suggestions please feel free to post them&#8230;</p>
<p><strong>Sources // <a href="http://www.bjoernacker.de/wp-content/uploads/2012/01/AdvancedCamera2D.zip">AdvancedCamera2D Sample Project</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernacker.de/flash/nd2d-advanced-camera-with-parallax-layers/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>ND2D &#8211; Adding Multiple &#8220;Alpha Masks&#8221;</title>
		<link>http://www.bjoernacker.de/flash/nd2d-adding-alpha-holes/</link>
		<comments>http://www.bjoernacker.de/flash/nd2d-adding-alpha-holes/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 15:42:50 +0000</pubDate>
		<dc:creator>bma</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://bjoernacker.de/blog/?p=84</guid>
		<description><![CDATA[For my current side project &#8211; a comic zombie shooter game &#8211; for which I utilize the ND2D framework - I wanted to add some atmosphere by putting a colored fog layer on top of all game layers, from which I could cut out multiple alpha masks to get something like search lights or illuminated auras. After [...]]]></description>
				<content:encoded><![CDATA[<p>For my current side project &#8211; <a title="28 Bratwursts Later – Zombie 2.5D Shooter Game" href="http://www.bjoernacker.de/flash/28-bratwurst-later-zombie-2-5d-shooter-game/">a comic zombie shooter game</a> &#8211; for which I utilize the <a href="https://github.com/nulldesign/nd2d">ND2D </a>framework - I wanted to add some atmosphere by putting a colored fog layer on top of all game layers, from which I could cut out multiple alpha masks to get something like search lights or illuminated auras.<span id="more-84"></span><br />
After some testing I ended up with this super complex AGAL fragment shader:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
</pre></td><td class="de1"><pre class="de1"><span class="st0">&quot;tex ft0, v0, fs0 &lt;2d,repeat,linear,mipnearest&gt;<span class="es0">\n</span>&quot;</span> 
<span class="st0">&quot;add oc, ft0, fc0 <span class="es0">\n</span>&quot;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">"tex ft0, v0, fs0 &lt;2d,repeat,linear,mipnearest&gt;\n" 
"add oc, ft0, fc0 \n"</pre></div></div>

<p>The fragment shader only adds the color information from the standard fragment shader constant to the sampled texture.</p>
<p>Click the image below for an example. Press &#8220;Add&#8221; to add an &#8220;AlphaHole&#8221; and change the color value to affect the fog&#8217;s tint.</p>
<p><a href="http://www.bjoernacker.de/vault/alphaholes" rel="shadowbox;width=800;height=600"><img class="alignnone size-full wp-image-491" title="alphahole" src="http://www.bjoernacker.de/wp-content/uploads/2012/01/alphahole.jpg" alt="" width="580" height="215" /></a></p>
<p>The trick is to have a Node2D container in which you could add your alpha masks.<br />
The later transparent parts of the alpha mask texture have to be white on a transparent background.</p>
<p><a href="http://www.bjoernacker.de/flash/nd2d-adding-alpha-holes/attachment/alphamask/" rel="attachment wp-att-94"><img class="alignleft size-full wp-image-94" title="AlphaMask" src="http://bjoernacker.de/wp-content/uploads/2012/01/alphaMask.jpg" alt="" width="101" height="100" /></a>This container is the input node for a TextureRenderer, which renders the container to a texture which is used by the final layer (Sprite2D).</p>
<p>The most important thing is to set the <strong>Blendmode</strong> of the final sprite to <strong>MODULATE</strong> which will turn all white areas into transparent ones.</p>
<p>&nbsp;</p>
<p><strong>Sources // <a href="http://www.bjoernacker.de/wp-content/uploads/2012/01/AlphaHoleMaterial.zip">AlphaHoleMaterial Sample Project</a></strong></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernacker.de/flash/nd2d-adding-alpha-holes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Detecting the Cheat Engine&#8217;s Speedhack in AS3</title>
		<link>http://www.bjoernacker.de/flash/detecting-the-cheat-engines-speedhack-in-as3/</link>
		<comments>http://www.bjoernacker.de/flash/detecting-the-cheat-engines-speedhack-in-as3/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 23:36:27 +0000</pubDate>
		<dc:creator>bma</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://bjoernacker.de/blog/?p=74</guid>
		<description><![CDATA[Another cool feature of the Cheat Engine is the so called &#8220;Speedhack&#8221; which allows you to slow down or speed up the execution of your (Flash) game. Cheat Engine achieves this by replacing some commonly used functions in games (or the Flash Player) to keep the speed constant with its own routine that goes faster or [...]]]></description>
				<content:encoded><![CDATA[<p>Another cool feature of the Cheat Engine is the so called &#8220;Speedhack&#8221; which allows you to slow down or speed up the execution of your (Flash) game. Cheat Engine achieves this by replacing some commonly used functions in games (or the Flash Player) to keep the speed constant with its own routine that goes faster or slower.</p>
<p>One approach to detect the speedhack could be to periodically check the difference between the system&#8217;s (OS) time and the Flash Player&#8217;s time. If the difference is too big the speedhack might be active and a warning could be dispatched or the alleged cheater could be e.g. marked in a black list ;-)<span id="more-74"></span></p>
<p>The <strong>SpeedWatchDog</strong> Class does dispatch a <strong>SecurityErrorEvent</strong> as I don&#8217;t wanted to use a custom event and the &#8220;SecurityErrorEvent&#8221; seemed pretty bold&#8230;</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar" style="right: 15px;" ><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"style=" height: 420px;"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
</pre></td><td class="de1"><pre class="de1"><span class="kw2">package</span>
<span class="br0">&#123;</span>
&nbsp;<span class="kw2">import</span> flash.<span class="me1">events</span>.<span class="me1">Event</span><span class="sy0">;</span>
&nbsp;<span class="kw2">import</span> flash.<span class="me1">events</span>.<span class="me1">EventDispatcher</span><span class="sy0">;</span>
&nbsp;<span class="kw2">import</span> flash.<span class="me1">events</span>.<span class="me1">SecurityErrorEvent</span><span class="sy0">;</span>
&nbsp;<span class="kw2">import</span> flash.<span class="me1">utils</span>.<span class="me1">clearInterval</span><span class="sy0">;</span>
&nbsp;<span class="kw2">import</span> flash.<span class="me1">utils</span>.<span class="me1">getTimer</span><span class="sy0">;</span>
&nbsp;<span class="kw2">import</span> flash.<span class="me1">utils</span>.<span class="me1">setInterval</span><span class="sy0">;</span>
&nbsp;
&nbsp;<span class="coMULTI">/**</span>
<span class="coMULTI">&nbsp;* @author Björn Acker | www.bjoernacker.de</span>
<span class="coMULTI">&nbsp;*/</span>
&nbsp;<span class="kw2">public</span> <span class="kw2">class</span> SpeedWatchDog <span class="kw2">extends</span> EventDispatcher
&nbsp;<span class="br0">&#123;</span>
&nbsp;<span class="kw2">protected</span> <span class="kw2">var</span> _tolerance<span class="sy0">:</span>Number<span class="sy0">;</span>
&nbsp;<span class="kw2">protected</span> <span class="kw2">var</span> _prevDate<span class="sy0">:</span>Number<span class="sy0">;</span>
&nbsp;<span class="kw2">protected</span> <span class="kw2">var</span> _prevTimer<span class="sy0">:</span>int<span class="sy0">;</span>
&nbsp;<span class="kw2">protected</span> <span class="kw2">var</span> _interval<span class="sy0">:</span>uint<span class="sy0">;</span>
&nbsp;
&nbsp;<span class="br0">&#91;</span>Event<span class="br0">&#40;</span><span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;securityError&quot;</span><span class="sy0">,</span>type<span class="sy0">=</span><span class="st0">&quot;flash.events.SecurityErrorEvent&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> init<span class="br0">&#40;</span>interval<span class="sy0">:</span>int <span class="sy0">=</span> <span class="nu0">1000</span><span class="sy0">,</span> tolerance<span class="sy0">:</span>Number <span class="sy0">=</span> <span class="nu0">0.35</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp;<span class="br0">&#123;</span>
&nbsp;_tolerance <span class="sy0">=</span> tolerance<span class="sy0">;</span>
&nbsp;_prevTimer <span class="sy0">=</span> getTimer<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;_prevDate <span class="sy0">=</span> <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">time</span><span class="sy0">;</span>
&nbsp;<span class="kw1">this</span>.<span class="me1">interval</span> <span class="sy0">=</span> interval<span class="sy0">;</span>
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> <span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp;<span class="br0">&#123;</span>
&nbsp;clearInterval<span class="br0">&#40;</span>_interval<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> get tolerance<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span>Number
&nbsp;<span class="br0">&#123;</span>
&nbsp;<span class="kw1">return</span> _tolerance<span class="sy0">;</span>
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> set tolerance<span class="br0">&#40;</span>value<span class="sy0">:</span>Number<span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp;<span class="br0">&#123;</span>
&nbsp;_tolerance <span class="sy0">=</span> value<span class="sy0">;</span>
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> get interval<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span>uint
&nbsp;<span class="br0">&#123;</span>
&nbsp;<span class="kw1">return</span> _interval<span class="sy0">;</span>
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> set interval<span class="br0">&#40;</span>value<span class="sy0">:</span>uint<span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp;<span class="br0">&#123;</span>
&nbsp;clearInterval<span class="br0">&#40;</span>_interval<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;_interval <span class="sy0">=</span> setInterval<span class="br0">&#40;</span>check<span class="sy0">,</span> value<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;<span class="br0">&#125;</span>
&nbsp;
&nbsp;<span class="kw2">protected</span> <span class="kw2">function</span> check<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp;<span class="br0">&#123;</span>
&nbsp;<span class="kw2">var</span> date<span class="sy0">:</span>Number <span class="sy0">=</span> <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">time</span> <span class="sy0">-</span> _prevDate<span class="sy0">;</span>
&nbsp;<span class="kw2">var</span> timer<span class="sy0">:</span>Number <span class="sy0">=</span> getTimer<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">-</span> _prevTimer<span class="sy0">;</span>
&nbsp;<span class="kw2">var</span> t<span class="sy0">:</span>Number <span class="sy0">=</span> date <span class="sy0">*</span> _tolerance<span class="sy0">;</span>
&nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>timer <span class="sy0">&gt;</span> date <span class="sy0">+</span> t <span class="sy0">||</span> timer <span class="sy0">&lt;</span> date <span class="sy0">-</span> t<span class="br0">&#41;</span>
&nbsp;<span class="br0">&#123;</span>
&nbsp;dispatchEvent<span class="br0">&#40;</span><span class="kw2">new</span> SecurityErrorEvent<span class="br0">&#40;</span>SecurityErrorEvent.<span class="me1">SECURITY_ERROR</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;<span class="br0">&#125;</span>
&nbsp;_prevTimer <span class="sy0">=</span> getTimer<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;_prevDate <span class="sy0">=</span> <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">time</span><span class="sy0">;</span>
&nbsp;<span class="br0">&#125;</span>
&nbsp;<span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">package
{
 import flash.events.Event;
 import flash.events.EventDispatcher;
 import flash.events.SecurityErrorEvent;
 import flash.utils.clearInterval;
 import flash.utils.getTimer;
 import flash.utils.setInterval;

 /**
 * @author Björn Acker | www.bjoernacker.de
 */
 public class SpeedWatchDog extends EventDispatcher
 {
 protected var _tolerance:Number;
 protected var _prevDate:Number;
 protected var _prevTimer:int;
 protected var _interval:uint;

 [Event(name="securityError",type="flash.events.SecurityErrorEvent")]

 public function init(interval:int = 1000, tolerance:Number = 0.35):void
 {
 _tolerance = tolerance;
 _prevTimer = getTimer();
 _prevDate = new Date().time;
 this.interval = interval;
 }

 public function stop():void
 {
 clearInterval(_interval);
 }

 public function get tolerance():Number
 {
 return _tolerance;
 }

 public function set tolerance(value:Number):void
 {
 _tolerance = value;
 }

 public function get interval():uint
 {
 return _interval;
 }

 public function set interval(value:uint):void
 {
 clearInterval(_interval);
 _interval = setInterval(check, value);
 }

 protected function check():void
 {
 var date:Number = new Date().time - _prevDate;
 var timer:Number = getTimer() - _prevTimer;
 var t:Number = date * _tolerance;
 if (timer &gt; date + t || timer &lt; date - t)
 {
 dispatchEvent(new SecurityErrorEvent(SecurityErrorEvent.SECURITY_ERROR));
 }
 _prevTimer = getTimer();
 _prevDate = new Date().time;
 }
 }
}</pre></div></div>

<p>Usage:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
</pre></td><td class="de1"><pre class="de1"><span class="kw2">var</span> wd<span class="sy0">:</span>SpeedWatchDog <span class="sy0">=</span> <span class="kw2">new</span> SpeedWatchDog<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">//Check every 2 seconds with a tolerance of 40%</span>
wd.<span class="me1">init</span><span class="br0">&#40;</span><span class="nu0">2000</span><span class="sy0">,</span> <span class="nu0">0.4</span><span class="br0">&#41;</span><span class="sy0">;</span>
wd.<span class="me1">addEventListener</span><span class="br0">&#40;</span>SecurityErrorEvent.<span class="me1">SECURITY_ERROR</span><span class="sy0">,</span> onSpeedHack<span class="sy0">;</span>
&nbsp;
<span class="kw2">function</span> onSpeedHack<span class="br0">&#40;</span>e<span class="sy0">:</span>Event<span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp;trace<span class="br0">&#40;</span><span class="st0">&quot;speedhack detected&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">var wd:SpeedWatchDog = new SpeedWatchDog();
//Check every 2 seconds with a tolerance of 40%
wd.init(2000, 0.4);
wd.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSpeedHack;

function onSpeedHack(e:Event):void
{
   trace("speedhack detected");
}</pre></div></div>

<p><span style="color: #010101; font-family: Arial;"><span style="font-size: xx-small; line-height: 14px;">  </span></span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #010101; font-family: Arial;"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernacker.de/flash/detecting-the-cheat-engines-speedhack-in-as3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Protecting your numbers against the Cheat Engine</title>
		<link>http://www.bjoernacker.de/flash/protecting-your-numbers-against-the-cheat-machine/</link>
		<comments>http://www.bjoernacker.de/flash/protecting-your-numbers-against-the-cheat-machine/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 22:46:01 +0000</pubDate>
		<dc:creator>bma</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://bjoernacker.de/blog/?p=61</guid>
		<description><![CDATA[Some time ago the highscore of one of my Flash based ad-game had some miraculous high values, which never could have been achieved through normal game-play. The game code itself had been obfuscated and protected as much as possible and the highscore data had been encrypted before it was send to the server. So the score [...]]]></description>
				<content:encoded><![CDATA[<p>Some time ago the highscore of one of my Flash based ad-game had some miraculous high values, which never could have been achieved through normal game-play. The game code itself had been obfuscated and protected as much as possible and the highscore data had been encrypted before it was send to the server. So the score must have been cheated with a tool like <a href="http://cheatengine.org/">Cheat Engine</a> (which is really incredibly powerful).</p>
<p>So I tried to develop a little AS3 class, which will make cheating a little bit harder at least for the lazy ones.<span id="more-61"></span></p>
<p>Here is the &#8220;NumberVault&#8221; clazz:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar" style="right: 15px;" ><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"style=" height: 420px;"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
</pre></td><td class="de1"><pre class="de1"><span class="kw2">package</span>
<span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="kw2">import</span> flash.<span class="me1">utils</span>.<span class="me1">clearInterval</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="kw2">import</span> flash.<span class="me1">utils</span>.<span class="me1">Dictionary</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="kw2">import</span> flash.<span class="me1">utils</span>.<span class="me1">setInterval</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="coMULTI">/**</span>
<span class="coMULTI">&nbsp; &nbsp; &nbsp;* @author Björn Acker | www.bjoernacker.de</span>
<span class="coMULTI">&nbsp; &nbsp; &nbsp;*/</span>
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">class</span> NumberVault
&nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> static <span class="kw2">var</span> _list<span class="sy0">:</span>Dictionary <span class="sy0">=</span> <span class="kw2">new</span> Dictionary<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> static <span class="kw2">var</span> _interval<span class="sy0">:</span>int <span class="sy0">=</span> <span class="sy0">-</span><span class="nu0">1</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> static <span class="kw2">function</span> setNumber<span class="br0">&#40;</span>key<span class="sy0">:*,</span> value<span class="sy0">:</span>Number<span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value <span class="sy0">=</span> Math.<span class="me1">round</span><span class="br0">&#40;</span>value <span class="sy0">*</span> <span class="nu0">1000000</span><span class="br0">&#41;</span> <span class="sy0">/</span> <span class="nu0">1000000</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> s<span class="sy0">:</span>String <span class="sy0">=</span> String<span class="br0">&#40;</span>value<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> index<span class="sy0">:</span>int <span class="sy0">=</span> s.<span class="me1">indexOf</span><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> d<span class="sy0">:</span>Number <span class="sy0">=</span> index <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</span> <span class="sy0">?</span> <span class="nu0">1</span> <span class="sy0">:</span> Math.<span class="me1">pow</span><span class="br0">&#40;</span><span class="nu0">10</span><span class="sy0">,</span> int<span class="br0">&#40;</span>s.<span class="me1">length</span> <span class="sy0">-</span> index <span class="sy0">-</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value <span class="sy0">*=</span> d<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> x<span class="sy0">:</span>int <span class="sy0">=</span> int<span class="br0">&#40;</span>Math.<span class="me1">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="br0">&#40;</span><span class="nu0">2</span> <span class="sy0">*</span> int.<span class="me1">MAX_VALUE</span><span class="br0">&#41;</span> <span class="sy0">-</span> int.<span class="me1">MAX_VALUE</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value <span class="sy0">^=</span> x<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _list<span class="br0">&#91;</span>key<span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#123;</span>v<span class="sy0">:</span> value<span class="sy0">,</span> x<span class="sy0">:</span> x<span class="sy0">,</span> d<span class="sy0">:</span> d<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> static <span class="kw2">function</span> getNumber<span class="br0">&#40;</span>key<span class="sy0">:*</span><span class="br0">&#41;</span><span class="sy0">:</span>Number
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> obj<span class="sy0">:</span>Object <span class="sy0">=</span> _list<span class="br0">&#91;</span>key<span class="br0">&#93;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>obj <span class="sy0">==</span> <span class="kw2">null</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">throw</span> <span class="kw2">new</span> Error<span class="br0">&#40;</span><span class="st0">&quot;Key doesn't exist&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> Math.<span class="me1">round</span><span class="br0">&#40;</span>Number<span class="br0">&#40;</span><span class="br0">&#40;</span>obj.<span class="me1">v</span> <span class="sy0">^</span> int<span class="br0">&#40;</span>obj.<span class="me1">x</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="co2">/ obj.d) * 1000000) /</span> <span class="nu0">1000000</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> static <span class="kw2">function</span> clearNumber<span class="br0">&#40;</span>key<span class="sy0">:*</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _list<span class="br0">&#91;</span>key<span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">delete</span> _list<span class="br0">&#91;</span>key<span class="br0">&#93;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> static <span class="kw2">function</span> clearAll<span class="br0">&#40;</span>key<span class="sy0">:*</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _list <span class="sy0">=</span> <span class="kw2">new</span> Dictionary<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> static <span class="kw2">function</span> shakeNumber<span class="br0">&#40;</span>key<span class="sy0">:*</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> obj<span class="sy0">:</span>Object <span class="sy0">=</span> _list<span class="br0">&#91;</span>key<span class="br0">&#93;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>obj <span class="sy0">==</span> <span class="kw2">null</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">throw</span> <span class="kw2">new</span> Error<span class="br0">&#40;</span><span class="st0">&quot;Key doesn't exist&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> x<span class="sy0">:</span>int <span class="sy0">=</span> int<span class="br0">&#40;</span>Math.<span class="me1">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="br0">&#40;</span><span class="nu0">2</span> <span class="sy0">*</span> int.<span class="me1">MAX_VALUE</span><span class="br0">&#41;</span> <span class="sy0">-</span> int.<span class="me1">MAX_VALUE</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span class="me1">v</span> <span class="sy0">=</span> Math.<span class="me1">round</span><span class="br0">&#40;</span>Number<span class="br0">&#40;</span><span class="br0">&#40;</span>obj.<span class="me1">v</span> <span class="sy0">^</span> int<span class="br0">&#40;</span>obj.<span class="me1">x</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">^</span> x<span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">1000000</span><span class="br0">&#41;</span> <span class="sy0">/</span> <span class="nu0">1000000</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span class="me1">x</span> <span class="sy0">=</span> x<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> static <span class="kw2">function</span> shakeAll<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i<span class="sy0">:</span>String <span class="kw1">in</span> _list<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shakeNumber<span class="br0">&#40;</span>i<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> static <span class="kw2">function</span> autoShake<span class="br0">&#40;</span>interval<span class="sy0">:</span>int<span class="sy0">=</span><span class="nu0">100</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _interval <span class="sy0">=</span> setInterval<span class="br0">&#40;</span>shakeAll<span class="sy0">,</span> interval<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">public</span> static <span class="kw2">function</span> stopAutoShake<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>_interval <span class="sy0">!=</span> <span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearInterval<span class="br0">&#40;</span>_interval<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _interval <span class="sy0">=</span> <span class="sy0">-</span><span class="nu0">1</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">package
{
	import flash.utils.clearInterval;
	import flash.utils.Dictionary;
	import flash.utils.setInterval;

	/**
	 * @author Björn Acker | www.bjoernacker.de
	 */
	public class NumberVault
	{

		private static var _list:Dictionary = new Dictionary();
		private static var _interval:int = -1;

		public static function setNumber(key:*, value:Number):void
		{
			value = Math.round(value * 1000000) / 1000000;
			var s:String = String(value);
			var index:int = s.indexOf(".");
			var d:Number = index == -1 ? 1 : Math.pow(10, int(s.length - index - 1));
			value *= d;
			var x:int = int(Math.random() * (2 * int.MAX_VALUE) - int.MAX_VALUE);
			value ^= x;
			_list[key] = {v: value, x: x, d: d};
		}

		public static function getNumber(key:*):Number
		{
			var obj:Object = _list[key];
			if (obj == null)
				throw new Error("Key doesn't exist");
			return Math.round(Number((obj.v ^ int(obj.x)) / obj.d) * 1000000) / 1000000;
		}

		public static function clearNumber(key:*):void
		{
			_list[key] = null;
			delete _list[key];
		}

		public static function clearAll(key:*):void
		{
			_list = new Dictionary();
		}

		public static function shakeNumber(key:*):void
		{
			var obj:Object = _list[key];
			if (obj == null)
				throw new Error("Key doesn't exist");
			var x:int = int(Math.random() * (2 * int.MAX_VALUE) - int.MAX_VALUE);
			obj.v = Math.round(Number((obj.v ^ int(obj.x)) ^ x) * 1000000) / 1000000;
			obj.x = x;
		}

		public static function shakeAll():void
		{
			for (var i:String in _list)
				shakeNumber(i);
		}

		public static function autoShake(interval:int=100):void
		{
			_interval = setInterval(shakeAll, interval);
		}

		public static function stopAutoShake():void
		{
			if (_interval != -1)
			{
				clearInterval(_interval);
				_interval = -1;
			}
		}
	}
}</pre></div></div>

<p>You can only protect <strong>Number</strong> or <strong>int</strong> values. You can add a number using the static method NumberVault.setNumber(key, value), e.g.</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
</pre></td><td class="de1"><pre class="de1">NumberVault.<span class="me1">setNumber</span><span class="br0">&#40;</span><span class="st0">&quot;score&quot;</span><span class="sy0">,</span> <span class="nu0">100</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">NumberVault.setNumber("score", 100);</pre></div></div>

<p>To read back a value use NumberVault.getNumber(key), e.g.</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
</pre></td><td class="de1"><pre class="de1">NumberVault.<span class="me1">getNumber</span><span class="br0">&#40;</span><span class="st0">&quot;score&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">NumberVault.getNumber("score");</pre></div></div>

<p>There are some more methods like NumberVault.autoShake() which will periodically modify the internal value representations.</p>
<p>To e.g. add some value to a number use:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
</pre></td><td class="de1"><pre class="de1">NumberVault.<span class="me1">setNumber</span><span class="br0">&#40;</span><span class="st0">&quot;score&quot;</span><span class="sy0">,</span> NumberVault.<span class="me1">getNumber</span><span class="br0">&#40;</span><span class="st0">&quot;score&quot;</span><span class="br0">&#41;</span><span class="sy0">+</span><span class="nu0">100</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">NumberVault.setNumber("score", NumberVault.getNumber("score")+100);</pre></div></div>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernacker.de/flash/protecting-your-numbers-against-the-cheat-machine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Debug Facebook Web Apps with FlashDevelop</title>
		<link>http://www.bjoernacker.de/flash/debug-facebook-web-apps-with-flashdevelop/</link>
		<comments>http://www.bjoernacker.de/flash/debug-facebook-web-apps-with-flashdevelop/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 13:55:44 +0000</pubDate>
		<dc:creator>bma</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://bjoernacker.de/blog/?p=9</guid>
		<description><![CDATA[I&#8217;ve been working on a Facebook web app using FlashDevelop and quickly found out that local testing won&#8217;t work as the URL specified in the Facebook app settings dialog doesn&#8217;t match the URL of your local SWF. After doing some research I found an easy way yet to build and debug the project directly from [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been working on a Facebook web app using FlashDevelop and quickly found out that local testing won&#8217;t work as the URL specified in the Facebook app settings dialog doesn&#8217;t match the URL of your local SWF.</p>
<p>After doing some research I found an easy way yet to build and debug the project directly from FlashDevelop.<br />
The basic idea is to directly publish the project&#8217;s SWF to the right folder on the web server and then test it at this place.</p>
<p>I&#8217;ve downloaded and installed  <a href="http://www.eldos.com/sftp-net-drive/">SFTP NetDrive</a>, a tool which allows you to work with the remote file system as if it is a local disk drive, given that the remote system supports SFTP protocol.<span id="more-9"></span></p>
<p>After setting up the connection details within NetDrive a new mapped network drive will show up in the Explorer.</p>
<p>Now, in FlashDevelop open up the &#8220;Project Properties&#8221; window and under &#8220;General&#8221; click the &#8220;Browse&#8221; Button to select the output file&#8217;s location. Here select the according directory of your mapped SFTP drive.</p>
<p><a href="http://bjoernacker.de/wp-content/uploads/2012/01/fd1.jpg" rel="shadowbox[sbpost-9];player=img;"><img class="alignnone size-medium wp-image-14" title="fd1" src="http://bjoernacker.de/wp-content/uploads/2012/01/fd1-300x258.jpg" alt="" width="300" height="258" /><br />
</a><br />
Next select &#8220;Open Document&#8230;&#8221; from the Test Project combo box, click &#8220;Edit&#8221; button and fill in the URL of your app.</p>
<p><a href="http://bjoernacker.de/wp-content/uploads/2012/01/fd21.jpg" rel="shadowbox[sbpost-9];player=img;"><img class="alignnone size-medium wp-image-34" title="fd2" src="http://bjoernacker.de/wp-content/uploads/2012/01/fd21-300x258.jpg" alt="" width="300" height="258" /></a></p>
<p>From now on FlashDevelop will export the SWF directly on the web server and open it up the default browser. Be sure that you have installed the <a href="http://www.adobe.com/support/flashplayer/downloads.html">Flash Debug Player</a>.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernacker.de/flash/debug-facebook-web-apps-with-flashdevelop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
