<?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>Stroep &#187; snippet</title> <atom:link href="http://blog.stroep.nl/tag/snippet/feed/" rel="self" type="application/rss+xml" /><link>http://blog.stroep.nl</link> <description>Just a collection of random works - Mark Knol</description> <lastBuildDate>Tue, 10 Jan 2012 20:09:53 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Javascript for AS3 developers</title><link>http://blog.stroep.nl/2011/01/javascript-for-as3-developers/</link> <comments>http://blog.stroep.nl/2011/01/javascript-for-as3-developers/#comments</comments> <pubDate>Tue, 25 Jan 2011 23:46:17 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Code snippets]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[html5]]></category> <category><![CDATA[oop]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=1146</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/netscape_logo.jpg" alt="" title="Javascript for AS3 developers" width="100" height="100" class="alignleft size-full wp-image-1158" />This article is some training for your JavaScript skills. I love Actionscript , and I am also starting to like JavaScript. HTML5 is an hot topic today, and it seems using JavaScript is an important part of it, so why not learn more of it?]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/netscape_logo.jpg" alt="" title="Javascript for AS3 developers" width="100" height="100" class="alignleft size-full wp-image-1158" />This article is some training for your JavaScript skills. I love Actionscript , and I am also starting to like JavaScript. However, coding in JavaScript feels like Actionscript 1.0. It&#8217;s a pity there aren&#8217;t decent editors, especially if you want to write object-oriented-code, which <em>is</em> possible with JavaScript . At the moment I think VisualStudio is the best JavaScript editor, but I really wish there was a tool for JavaScript like FlashDevelop (a clean editor for Actionscript projects) with great intellisense, code completion and snippets etc. But we should not focus on tools, lets focus on the language and get the most out of it. HTML5 is an hot topic today, and it seems using JavaScript is an important part of it, so why not learn more of it? I have seen some <a href="http://mrdoob.com/">stunning HTML5 examples</a> over the last year. As a developer it is very interesting to see how others code JavaScript. By the way; Personally I find it very funny to see how JavaScript has changed it&#8217;s &#8216;image&#8217;. Some of us remember the good days in Netscape. JavaScript was .. *kuch* not fast and associated with ugly rainbow mouse pointers and aggressive popup screens. Now it is associated with HTML5, which is supposed to be the future and it will be bright <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> I refuse to put my opinion about this topic here.<br /> I think the &#8216;image&#8217; of JS has slowly changed after great frameworks like jQuery have reached the developers. jQuery is awesome, I advice to use jQuery as default in all sites/apps.</p><p>Anyway, there are (ofcourse) some techniques to code like Actionscript in JavaScript. These snippets have helped me to understand object oriented JavaScript. For too long I did not even tried to learn what was possible with JavaScript because I thought it was a very limited language. Maybe some information is outdated; I am still learning, so please share your feedback.</p><h2>Object oriented javascript</h2><p>In javascript it is possible to create classes, public and private vars, getters/setters and there are even constructors. A function could be seen as a class. This is a bit strange at first, but if you use it for a while you will understand. Now lets create our own class right now.</p><p>Lets port some stuff of <a href="http://code.google.com/p/stroep/source/browse/trunk/flashsources/utils%20classes/nl/stroep/utils/Color.as">this Color Class</a> to javascript. It has private vars and public functions.</p><h2>Declare classes</h2><p>Defining classes is as easy as defining functions, because it is almost the same. After creating an function, you could already make some instances of it. The example below creates a <em>Color</em> class with a public variable called <em>value</em>. After that we create 2 instances of the <em>Color</em> class with some other values.</p><p>Note: I use the same code conventions as Actionscript: Classes should be <em>UpperCased</em>, functions/vars should be <em>lowerCased </em>and constants should be <em>FULL_CAPS</em>. Oh and since javascript looks like as1.0, I sometimes use an underscore before private vars <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /></p><div class="bbCSH" style="font-family: monospace;"> function Color( value )<br /> {<br /> &nbsp; &nbsp; this.value = value || 0;<br /> &nbsp; &nbsp; alert(&quot;Color created with value: &quot; + value)<br /> }</p><p>var myRedColor = new Color(0xFF0000); // create instance of Color &nbsp;(a red one)<br /> var myOrangeColor = new Color(0xFFCC00); // create instance of Color &nbsp;(an orange one)<br /> alert( myRedColor.value );<br /> alert( myOrangeColor.value );<br /> &nbsp;</div><h2>Public / Private</h2><p>In actionscript it is very useful to use <a href="http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming)">encapsulation</a>, which is a mechanism for restricting access to other objects. The previous+following example should work in all browsers. The difference between public and private vars/functions in javascript can be declared like this:</p><div class="bbCSH" style="font-family: monospace;"> function Color( value )<br /> {<br /> &nbsp; &nbsp; // public variable<br /> &nbsp; &nbsp; this.value = value || 0xFFFFFF; // set default value to 0xFFFFFF for parameter if it isn&#8217;t defined</p><p>&nbsp; &nbsp; // private variable<br /> &nbsp; &nbsp; var _name = &quot;test&quot;;</p><p>&nbsp; &nbsp;// public function<br /> &nbsp; &nbsp;this.getRandomColor = function( )<br /> &nbsp; {<br /> &nbsp; &nbsp; &nbsp;return Math.random() * 0xFFFFFF;<br /> &nbsp; }</p><p>&nbsp; // private function<br /> &nbsp; function getNiceColor()<br /> &nbsp; {<br /> &nbsp; &nbsp; &nbsp;return 0xffcc00;<br /> &nbsp; }<br /> }</p><p>// create instance of Color<br /> var color = new Color(0xFF0000);<br /> alert( color.value ); // returns red color<br /> alert( color.getRandomColor() ); // returns random color</p><p>// not possible :<br /> alert( color.getNiceColor() ); error in console; property does not exist, because function is private.<br /> alert( color._name ); // error in console; property does not exist, because variable is private.<br /> &nbsp;</div><p>I think with this principles (maybe in combination with namespaces, see below) you can create clean javascript code.</p><h2>Packages &gt; Namespaces</h2><p>Now before using classes in javascript I had some conflicts with function and variable names because there were unwanted duplicates. I have written a little helper tool to use namespaces. It helps to prevent those conflicts. Now it looks more like Actionscript 3, only there is no such thing like &#8216;imports&#8217;. This snippet works in all browsers.</p><div class="bbCSH" style="font-family: monospace;"> /// create namespace like &#8216;com.yourcompany.projectname&#8217;<br /> function Namespace(namespace)<br /> {<br /> &nbsp; &nbsp; var parts = namespace.split(&quot;.&quot;);<br /> &nbsp; &nbsp; var root = window;<br /> &nbsp; &nbsp; for(var i = 0; i &lt; parts.length; i++)<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; if(typeof root[parts[i]] == &quot;undefined&quot;) <br /> &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root[parts[i]] = {};<br /> &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; root = root[parts[i]];<br /> &nbsp; &nbsp; }<br /> }</p><p>// creating my own namespace here<br /> Namespace(&quot;nl.stroep.utils&quot;);<br /> nl.stroep.utils.Color = function(value) // create class inside package<br /> {<br /> &nbsp; this.value = value || 0xFFFFFF;<br /> }</p><p>var myRedColor = &nbsp;new nl.stroep.utils.Color(0xff0000);<br /> alert(myRedColor.value);<br /> &nbsp;</div><h2>Getters and Setters</h2><p>Now it is possible to use getters and setters. NOTE (!): Ofcourse this method does not work in IE, so this is pointless but also a bit cool to see how far we could go. Anyway there are 2 ways to define them. Read more about it <a href="http://ejohn.org/blog/javascript-getters-and-setters/">here</a>. I think the <em>__defineGetter__</em> way is better; it looks ugly but you still have access to private objects.</p><p>Take a look at this getter/setter declaration example. It&#8217;s not as clean as AS3 getters/setters but it works like a charm in my browser.</p><div class="bbCSH" style="font-family: monospace;"> function Color( value )<br /> {</p><p>&nbsp; &nbsp;/* public getter */<br /> &nbsp; &nbsp;this.__defineGetter__(&quot;value&quot;, function()<br /> &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp; alert(&quot;getter called; current value: &quot; +value);<br /> &nbsp; &nbsp; &nbsp; &nbsp; return value;<br /> &nbsp; &nbsp; });<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp;/* public setter */<br /> &nbsp; &nbsp;this.__defineSetter__(&quot;value&quot;, function(val)<br /> &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp; alert(&quot;setter called; new value: &quot; +val);<br /> &nbsp; &nbsp; &nbsp; &nbsp; value = val;<br /> &nbsp; &nbsp; });<br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;// public variable. For a strange reason I have to put this below the get/set definition.<br /> &nbsp; &nbsp;this.value = value || 0xFFFFFF;<br /> }</p><p>// create instance of Color<br /> var color = new Color(0xFF0000);<br /> color.value; // getter<br /> color.value = 0xff0000; // setter<br /> &nbsp;</div><h2>Constants</h2><p>Javascript has a <em>const</em> too, you could use it instead of <em>var</em>. Ofcourse this is not implemented in IE, so it is also pretty pointless to use.</p><h2>Mix them all</h2><p>Now lets use namespaces, getters/setters and private/public variables and functions together.<br /> This is a simplified ported version of <a href="http://code.google.com/p/stroep/source/browse/trunk/flashsources/utils%20classes/nl/stroep/utils/Color.as">this Color Class</a>.<br /> With this class you can modify the red,green and blue channels of a color individually. In the original class it is possible to lighten/darken the color too, but for this post I left these functions, because this only illustrates the possibilities of nice OO javascript.</p><div class="bbCSH" style="font-family: monospace;">Namespace(&quot;nl.stroep.utils&quot;);<br /> nl.stroep.utils.Color = function( color )<br /> {&nbsp; &nbsp;<br /> &nbsp; &nbsp; /* PUBLIC FUNCTIONS */<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; this.grayscale = function( val )<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; val = val || 0;<br /> &nbsp; &nbsp; &nbsp; &nbsp; if (val &lt; 0){ val = 0 }<br /> &nbsp; &nbsp; &nbsp; &nbsp; if (val &gt; 255) { val = 255 }<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; return (val &lt;&lt; 16) | (val &lt;&lt; 8 ) | val;<br /> &nbsp; &nbsp; }<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; /* PRIVATE FUNCTIONS */<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; function limit( val, lowerLimit, upperLimit )<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; if (val &lt; lowerLimit){ return lowerLimit }<br /> &nbsp; &nbsp; &nbsp; &nbsp; if (val &gt; upperLimit) { return upperLimit }<br /> &nbsp; &nbsp; &nbsp; &nbsp; return val;<br /> &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; /* PUBLIC GETTER FUNCTIONS */<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; this.__defineGetter__(&quot;value&quot;, function()<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; return (_red &lt;&lt; 16) | (_green &lt;&lt; 8 ) | _blue; <br /> &nbsp; &nbsp; })<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; this.__defineGetter__(&quot;red&quot;, function()<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; return _red;<br /> &nbsp; &nbsp; })<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; this.__defineGetter__(&quot;green&quot;, function()<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; return _green;<br /> &nbsp; &nbsp; })<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; this.__defineGetter__(&quot;blue&quot;, function()<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; return _blue;<br /> &nbsp; &nbsp; })<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; /* PUBLIC SETTER FUNCTIONS */<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; this.__defineSetter__(&quot;value&quot;, function(val)<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; _red &nbsp;= val &gt;&gt; 16 &amp; 0xFF; // red<br /> &nbsp; &nbsp; &nbsp; &nbsp; _green &nbsp;= val &nbsp;&gt;&gt; 8 &amp; 0xFF; // green<br /> &nbsp; &nbsp; &nbsp; &nbsp; _blue = val &amp; 0xFF; // blue<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; _value = val;<br /> &nbsp; &nbsp; })<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; this.__defineSetter__(&quot;red&quot;, function(val)<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; _red = val;<br /> &nbsp; &nbsp; &nbsp; &nbsp; _red = limit( _red, 0, 255 );<br /> &nbsp; &nbsp; })<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; this.__defineSetter__(&quot;green&quot;, function(val)<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; _green = val;<br /> &nbsp; &nbsp; &nbsp; &nbsp; _green = limit( _green, 0, 255 );<br /> &nbsp; &nbsp; })<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; this.__defineSetter__(&quot;blue&quot;, function(val)<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; _blue = val;<br /> &nbsp; &nbsp; &nbsp; &nbsp; _blue = limit( _blue, 0, 255 );<br /> &nbsp; &nbsp; })<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; /* PRIVATE VARIABLES */<br /> &nbsp; &nbsp; var _value = color;<br /> &nbsp; &nbsp; var _red;<br /> &nbsp; &nbsp; var _green;<br /> &nbsp; &nbsp; var _blue;<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; /* PUBLIC VARIABLES */<br /> &nbsp; &nbsp; this.value = _value;<br /> &nbsp; &nbsp; <br /> };<br /> &nbsp;</div><p>With this javascript class, you could use it like this:</p><div class="bbCSH" style="font-family: monospace;"> var color = new nl.stroep.utils.Color(0xFFCC00) // define orange.<br /> color.green = 0; // remove green.. now it is red..<br /> color.blue = 255; // add some blue.. now it is purple..<br /> alert(color.value.toString(16)) // alerts FF00FF and that is purple.<br /> &nbsp;</div><p>Hope you enjoyed this article. Feel free to share or comment.</p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1146&amp;md5=2a3c43bbcb2a14cb40dd0ee0e476f64f" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/01/javascript-for-as3-developers/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Quick way to create an auto-increment index AS3</title><link>http://blog.stroep.nl/2010/08/auto-increment-as3-class/</link> <comments>http://blog.stroep.nl/2010/08/auto-increment-as3-class/#comments</comments> <pubDate>Sun, 22 Aug 2010 13:39:16 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Code snippets]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[class]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=977</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/snippet.jpg" alt="" title="snippet" width="100" height="100" class="alignleft size-full wp-image-588">Quick post here. I'd like to share this very quick way to create an automatic ID or index to your class instances. Mostly I pass an index as parameter to the class instances, or I use a public var to set the index. Using this way it is very easy to create an automatically filled index, since you have to set this up once and never worry again :)]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/snippet.jpg" alt="" title="snippet" width="100" height="100" class="alignleft size-full wp-image-588">Quick post here. I&#8217;d like to share this very quick way to create an automatic ID or index to your class instances. Mostly I pass an index as parameter to the class instance, or I use a public var to set the index. Using this way it is very easy to create an automatically filled index, since you have to set this up once and never worry again <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Take a look at this code:</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">package</span><br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">class</span> MyObject<br /> &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; ">var</span> global_index:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;<br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> const <span style="color: #0066CC;">INDEX</span>:<span style="color: #0066CC;">int</span> = global_index ++;<br /> &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>As you see, I have created a static variable global_index, which is always the same to all MyObject classes. I also created a public constant &#8216;INDEX&#8217;, which would be unique in every instance. When the MyObject instance is created the index will be set to the global_index, and the global_index will increase by one. So that&#8217;s basically the trick to create the auto-increment index for your AS3 class.</p><div class="bbCSH" style="font-family: monospace;">update: Changed global_index to a private static + removed constructor</div><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=977&amp;md5=84ec0bda1ad30fd8af7b85c6c931d79c" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2010/08/auto-increment-as3-class/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Multiple keys made easy with Dictionary</title><link>http://blog.stroep.nl/2010/07/multiple-keys-made-easy-with-dictionary/</link> <comments>http://blog.stroep.nl/2010/07/multiple-keys-made-easy-with-dictionary/#comments</comments> <pubDate>Sun, 11 Jul 2010 11:18:45 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Code snippets]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[game]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=964</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/behind.jpg" alt="Multiple keys made easy with Dictionary" width="100" height="100" class="alignleft size-full wp-image-586">Quick post here, a simple solution I found to have multiple keys enabled. Maybe most real game developers know better or more elegant solutions, but I found this useful enough to share it with you.]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/behind.jpg" alt="Multiple keys made easy with Dictionary" width="100" height="100" class="alignleft size-full wp-image-586">Quick post here, a simple solution I found to have multiple keys enabled. Maybe most real game developers know better or more elegant solutions, but I found this useful enough to share it with you.</p><p>Here we go. Add these variable to your class. This is a Dictionary, which allows you to associate a value with an object key.</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> currentKeys:Dictionary = <span style="color: #000000; ">new</span> Dictionary<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp;</div><p>Then, in your constructor or wherever you assign eventListeners, add these (well-known) listeners, with the callback functions:</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">KeyboardEvent</span>;</p><p><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_DOWN</span>, <span style="color: #0066CC;">onKeyDown</span><span style="color: #66cc66;">&#41;</span>;<br /> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_UP</span>, <span style="color: #0066CC;">onKeyUp</span><span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">onKeyDown</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; currentKeys<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #000000; ">true</span>;<br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">onKeyUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; currentKeys<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #000000; ">false</span>;<br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>Inside your enterframe-event or timer (were you want to detect which keys are pressed), you could these kind of detection.</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">ui</span>.<span style="color: #006600;">Keyboard</span>;<br /> <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;</p><p><span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">onUpdate</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> currentKeys<span style="color: #66cc66;">&#91;</span> Keyboard.<span style="color: #0066CC;">SPACE</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; tank.<span style="color: #006600;">shoot</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> currentKeys<span style="color: #66cc66;">&#91;</span> Keyboard.<span style="color: #0066CC;">RIGHT</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; tank.<span style="color: #006600;">targetDirection</span> -= <span style="color: #cc66cc;">0.1</span>;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp;<br /> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> currentKeys<span style="color: #66cc66;">&#91;</span> Keyboard.<span style="color: #0066CC;">LEFT</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; tank.<span style="color: #006600;">targetDirection</span> += <span style="color: #cc66cc;">0.1</span>;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp;<br /> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> currentKeys<span style="color: #66cc66;">&#91;</span> Keyboard.<span style="color: #0066CC;">UP</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; tank.<span style="color: #006600;">speed</span> += tank.<span style="color: #006600;">acceleration</span>;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp;<br /> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> currentKeys<span style="color: #66cc66;">&#91;</span> Keyboard.<span style="color: #0066CC;">DOWN</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; tank.<span style="color: #006600;">speed</span> /= <span style="color: #cc66cc;">1.8</span>;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>I found that if you use some 3 or 4+ combinations of keys at the same time, the keyboard events are not triggered anymore, which is a bit of annoying bug in the FlashPlayer. I mean pressing forward and left and shooting at the same time could be a problem? Well; Hope this helps, I think its very easy and a great usage of the Dictionary.</p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=964&amp;md5=614986660ceb7df7c7459292b51ea0bb" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2010/07/multiple-keys-made-easy-with-dictionary/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Update Image class &#8211; added contextMenu</title><link>http://blog.stroep.nl/2009/11/add-contextmenu-to-images/</link> <comments>http://blog.stroep.nl/2009/11/add-contextmenu-to-images/#comments</comments> <pubDate>Fri, 06 Nov 2009 17:35:13 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Other]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[code]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=812</guid> <description><![CDATA[<img src="/wp-content/uploads/image-contextmenu.jpg" alt="" class="alignleft" />I've updated my <a href="http://blog.stroep.nl/2009/06/nlstroeputilsimage/">Image class</a>. It is irritating flashsites break the right-click contextmenu. Well, I can't fix that and Adobe should look at that, but I think it would nice to add some of the browser - features to my image class. ]]></description> <content:encoded><![CDATA[<p><img src="/wp-content/uploads/image-contextmenu.jpg" alt="" class="alignleft" />I&#8217;ve updated my <a href="http://blog.stroep.nl/2009/06/nlstroeputilsimage/">Image class</a>. It is irritating flashsites break the right-click contextmenu. Well, I can&#8217;t fix that and Adobe should look at that, but I think it would nice to add some of the browser &#8211; features to my image class.</p><p>Currently I have these options added to the Image class:</p><blockquote><p> <strong>View image</strong><br /> Views image in new window/tab. I used NavigateToURL to make this happen.</p><p><strong>Save Image as..</strong><br /> Saves image on your computer. I used my ImageClass.saveLocal() to make this happen. This is only available within FP10, but I think this is no problem anymore because < a href = "http://www.adobe.com/products/player_census/flashplayer/version_penetration.html" > 93 %</a> (September 2009) has FlashPlayer 10, so most people have it, and I don&#8217;t support outdated software <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p><strong>Copy Image location</strong><br /> Copies the url to the clipboard, using System.setClipboard(url). It&#8217;s a pity I can&#8217;t create a &#8216;Copy Image&#8217; function, because pushing bitmapdata into the clipboard is only supported in AIR.</p><p><strong>Send Image</strong><br /> Sends the url to the mail-client, using &#8220;mailto:&#038;body=&#8221; + src. Also a pity; I can&#8217;t add the image directly into the mail.</p></blockquote><p><strong>How to enable the contextmenu:</strong></p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">import</span> nl.<span style="color: #006600;">stroep</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Image</span>;</p><p><span style="color: #000000; ">var</span> myImage:Image = <span style="color: #000000; ">new</span> Image<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myImage.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;<br /> myImage.<span style="color: #006600;">enableContextMenu</span> = <span style="color: #000000; ">true</span>; <span style="color: #808080; font-style: italic;">// enable it!</span><br /> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>myImage<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp;</div><p> I still love this class, I use it a lot. I want to encourage you to please add these kind of usability things to your apps / websites. And share them! Yes, it takes some extra time to create/add it, because this IS the finishing touch, but a lot of people will like this kind of features.</p><p><strong>Download</strong><br /> Check out the <a href="http://code.google.com/p/stroep/source/browse/trunk/nl/stroep/utils/Image.as">Image class</a> at<a href="http://code.google.com/p/stroep">googlecode</a></p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/11/add-contextmenu-to-images/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>getBounds for TextFields = getBitmapBounds()</title><link>http://blog.stroep.nl/2009/11/getbitmapbounds/</link> <comments>http://blog.stroep.nl/2009/11/getbitmapbounds/#comments</comments> <pubDate>Thu, 05 Nov 2009 18:05:32 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Code snippets]]></category> <category><![CDATA[bitmapdata]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=799</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/snippet.jpg" alt="Code snippet" align="left" class="alignleft size-full wp-image-588" />I found out the getBounds()-function gives not exactly the right rectangle with a TextField. It always matches the border bounds, even if the borders are invisible. So i've created a more accurate function using getColorBoundsRect().]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/snippet.jpg" alt="Code snippet" align="left" class="alignleft size-full wp-image-588" />I found out the getBounds()-function gives not exactly the right rectangle with a TextField. It always matches the border bounds, even if the borders are invisible. So I&#8217;ve created a more accurate function using getColorBoundsRect().</p><p>Click on the words. Switch between getRect() and getTextFieldBounds() by clicking on the buttons below to see the difference.</p><p><object type="application/x-shockwave-flash" data="http://projects.stroep.nl/getBitmapBounds/GetBitmapBounds.swf" width="550" height="140"><param name="movie" value="http://projects.stroep.nl/getBitmapBounds/GetBitmapBounds.swf" /></object></p><p>» <a href="http://projects.stroep.nl/getBitmapBounds/GetBitmapBounds.zip"><b>Download source</b></a></p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/11/getbitmapbounds/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Liquid menu: Better proportions with Math.sqrt</title><link>http://blog.stroep.nl/2009/09/better-proportions-with-square-root/</link> <comments>http://blog.stroep.nl/2009/09/better-proportions-with-square-root/#comments</comments> <pubDate>Tue, 01 Sep 2009 09:27:56 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Code snippets]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[Math]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=740</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/square-root.jpg" alt="Square root" title="Square root" width="100" height="100" class="alignleft size-full wp-image-751" />Found out something useful, which I'd like to share with you. It's about calculating the width of menu-items perfectly.Imaging you are creating a liquid website with a menu. If you want all items to have the same width, you could set the width of each item to totalMenuWidth / items.length. In most cases this will work out. But what is your menu is very small or the items doesn't fit in that fixed width because the text is too long?]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/square-root.jpg" alt="Square root" title="Square root" width="100" height="100" class="alignleft size-full wp-image-751" />Found out something useful, which I&#8217;d like to share with you. It&#8217;s about calculating the width of menu-items perfectly.</p><p>Imaging you are creating a liquid website with a menu. If you want all items to have the same width, you could set the width of each item to totalMenuWidth / items.length. In most cases this will work out. But what is your menu is very small or the items doesn&#8217;t fit in that fixed width because the text is too long?</p><p>Well you could hardcode the width&#8217;s to make your own perfect proportions and spacing, but if your menu is xml-driven and you/someone else adds new menu-items, you have to re-assign the hardcoded widths and you feel unhappy <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Most hardcoded stuff is evil anyway because it is laziness. (I use it a lot <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )</p><p>Well, I&#8217;d like to calculate the perfect scaling menu, so I don&#8217;t have to worry the menu will break. You can use the text-length of the menu-item as input for the width calculation. The more letters, the bigger the menu-item, right? So, If you multiply all menu-text-lengths and divide this to the current text-length, you&#8217;ll get a ratio which can be divided from the total menu width. I like this theory. So we need to do this in 2 steps; first get the ratios and get the total menu-text-lengths (with a loop), then calculate and apply this on each item.<br /> Pseudocode:<br /><blockquote>itemwidth = fullMenuWidth / (totalTextLength / menuitem.text.length)</p></blockquote><p>This works fine, and its actually very cool. Now we have a function which actually use some proportions to create a liquid menu. After a while I realized that the proportions weren&#8217;t really right. If the menu text have odd text-length differences (eg 5 letters vs 25 letters), it looks weird. Larger texts take too much width. I wanted the same proportions kinda like a html-table.</p><p>So the menu-items needs to have better proportions. Bigger text should be a smaller and the smaller text should be bigger. After some searching I &#8216;discovered&#8217; <a href="http://en.wikipedia.org/wiki/Square_root">Square root</a>, a.k.a. <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00001839.html">Math.sqrt()</a> in actionscript. With this function you could &#8216;normalize&#8217; numbers. Bigger numbers are getting smaller, smaller numbers are getting bigger. This was exactly what I needed!</p><p>You can see the result below:</p><p><object type="application/x-shockwave-flash" data="http://projects.stroep.nl/PerfectWidth/PerfectWidth.swf" width="100%" height="235"><param name="movie" value="http://projects.stroep.nl/PerfectWidth/PerfectWidth.swf" /><param name="wmode" value="transparent" /></object></p><p>You can see the differences between the menubars and you&#8217;ll agree to me that the last one is the best <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I think this theory could be applied to a lot more things, like graphs or grids.</p><p>In case anyone is interested in the code; it can be downloaded <a href="http://projects.stroep.nl/PerfectWidth/perfect-width-src.zip">here</a> (AS3).</p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/09/better-proportions-with-square-root/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>How to crop with AS3</title><link>http://blog.stroep.nl/2009/05/how-to-crop/</link> <comments>http://blog.stroep.nl/2009/05/how-to-crop/#comments</comments> <pubDate>Tue, 05 May 2009 20:03:41 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Code snippets]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=510</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/crop.jpg" alt="" title="Crop" width="100" height="100" class="alignleft size-full wp-image-571" />Quick post; How to crop the bitmap of your stage with AS3<br/><br/><br/>]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/crop.jpg" alt="" title="Crop" width="100" height="100" class="alignleft size-full wp-image-571" />Quick post; How to crop a bitmap / displayobject / Movieclip / Sprite or just the stage with Flash/AIR/AS3.</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #000000; ">function</span> crop<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">_x</span>:<span style="color: #0066CC;">Number</span>, <span style="color: #0066CC;">_y</span>:<span style="color: #0066CC;">Number</span>, <span style="color: #0066CC;">_width</span>:<span style="color: #0066CC;">Number</span>, <span style="color: #0066CC;">_height</span>:<span style="color: #0066CC;">Number</span>, displayObject:DisplayObject = <span style="color: #000000; ">null</span><span style="color: #66cc66;">&#41;</span>:Bitmap<br /> <span style="color: #66cc66;">&#123;</span><br /> <span style="color: #000000; ">var</span> cropArea:Rectangle = <span style="color: #000000; ">new</span> Rectangle<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">_width</span>, <span style="color: #0066CC;">_height</span> <span style="color: #66cc66;">&#41;</span>;<br /> <span style="color: #000000; ">var</span> croppedBitmap:Bitmap = <span style="color: #000000; ">new</span> Bitmap<span style="color: #66cc66;">&#40;</span> <span style="color: #000000; ">new</span> BitmapData<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">_width</span>, <span style="color: #0066CC;">_height</span> <span style="color: #66cc66;">&#41;</span>, PixelSnapping.<span style="color: #006600;">ALWAYS</span>, <span style="color: #000000; ">true</span> <span style="color: #66cc66;">&#41;</span>;<br /> croppedBitmap.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span>displayObject!=<span style="color: #000000; ">null</span><span style="color: #66cc66;">&#41;</span> ? displayObject : <span style="color: #0066CC;">stage</span>, <span style="color: #000000; ">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span>, -<span style="color: #0066CC;">_x</span>, -<span style="color: #0066CC;">_y</span><span style="color: #66cc66;">&#41;</span> , <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, cropArea, <span style="color: #000000; ">true</span> <span style="color: #66cc66;">&#41;</span>;<br /> <span style="color: #b1b100;">return</span> croppedBitmap;<br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>Usage:</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #000000; ">var</span> myCroppedImage:Bitmap = crop<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">100</span>, <span style="color: #cc66cc;">100</span>, <span style="color: #cc66cc;">200</span>, <span style="color: #cc66cc;">200</span> <span style="color: #66cc66;">&#41;</span>;<br /> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span> <span style="color: #66cc66;">&#40;</span> myCroppedImage <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp;</div><p><strong>Download</strong><br/><br /> » <a href="http://code.google.com/p/stroep/source/browse/#svn%2Ftrunk%2Fflashsources%2Futils%20classes%2Fnl%2Fstroep%2Futils">Download CropUtil class</a> on <a href="http://code.google.com/p/stroep/">googlecode</a>.</p><p>ps. To save the capture, use the <a href="/2008/09/as3-imagesaver-class-updated/">ImageSaver class</a></p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=510&amp;md5=452dadaaa8d2278b45ed4709428ee457" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/05/how-to-crop/feed/</wfw:commentRss> <slash:comments>21</slash:comments> </item> <item><title>Faster Math.abs()</title><link>http://blog.stroep.nl/2009/01/faster-mathabs/</link> <comments>http://blog.stroep.nl/2009/01/faster-mathabs/#comments</comments> <pubDate>Wed, 28 Jan 2009 18:52:04 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Code snippets]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=298</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/snippet.jpg" alt="" title="snippet" width="100" height="100" class="alignleft size-full wp-image-588" />Quick post :) This function returns the absolute value of a specified number. This is +/- 24x faster than the regular Math.abs().<br/><br/>]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/snippet.jpg" alt="" title="snippet" width="100" height="100" class="alignleft size-full wp-image-588" />Quick post <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> This function returns the absolute value of a specified number. This is +/- 24x faster than the regular Math.abs().</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span> value:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span><br /> <span style="color: #66cc66;">&#123;</span><br /> <span style="color: #b1b100;">return</span> value &lt; <span style="color: #cc66cc;">0</span> ? -value : value;<br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/01/faster-mathabs/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> </channel> </rss>
