<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Stroep</title> <link>http://blog.stroep.nl</link> <description>Just a collection of random works - Mark Knol</description> <lastBuildDate>Fri, 30 Mar 2012 19:25:37 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/stroep" /><feedburner:info uri="stroep" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-sa/2.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-sa/2.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><feedburner:emailServiceId>stroep</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>Generative canvas is fun (too)</title><link>http://feedproxy.google.com/~r/stroep/~3/yy2xXvpLm2k/</link> <comments>http://blog.stroep.nl/2012/03/generative-canvas-is-fun-too/#comments</comments> <pubDate>Fri, 30 Mar 2012 19:25:37 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Generative art]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[html5]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=1448</guid> <description><![CDATA[<a href="http://projects.stroep.nl/mapgen-doodle/v3.html"><img src="http://blog.stroep.nl/wp-content/love-of-lines.jpg" alt="" title="love of lines" width="570" class="image" /></a>Quick post.
I created a simple generative doodle using the canvas with javascript, check it out: <strong>&#187; <a href="http://projects.stroep.nl/mapgen-doodle/v3.html">Canvas Doodle</a></strong>]]></description> <content:encoded><![CDATA[<p><a href="http://projects.stroep.nl/mapgen-doodle/v3.html"><img src="http://blog.stroep.nl/wp-content/love-of-lines.jpg" alt="" title="love of lines" width="570" class="image" /></a>Quick post.<br /> I created a simple generative doodle using the canvas with javascript, check it out:<br /> <strong>&raquo; <a href="http://projects.stroep.nl/mapgen-doodle/v3.html">Canvas Doodle</a></strong></p><p>It is based on <a href="http://t.co/BemqpDR7">this experiment</a> by <a href="http://mrdoob.com/" title="the one">mr.doob</a>. For me it was a challenge to finally do a canvas experiment. It is kinda fun, you don&#8217;t have to compile and the surprise is very big if it works, since you don&#8217;t have such a thing as compile errors <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>A nice thing with the html-canvas is that you can set the line thickness to floats, where in actionscript you can only use an numbers that will be be rounded. That allows me to create nice thin lines. An annoying thing is that you have to use strings (with RGBA values) to define the color of the lines. Can this be a uint-value?</p><div class="bbCSH" style="font-family: monospace;">context.strokeStyle = &#8216;rgba(242, 43, 81, 0.8)&#8217;</div><p>Another thing that I noticed, it&#8217;s is hard to blend two canvas contexts, you&#8217;ll have to do it pixel per pixel.</p><div class="bbCSH" style="font-family: monospace;"> function merge(toContext, fromContext)<br /> {<br /> &nbsp; &nbsp; var imageData = fromContext.getImageData(0, 0, width, height)<br /> &nbsp; &nbsp; var pixelData1 = imageData.data;<br /> &nbsp; &nbsp; var pixelData2 = toContext.getImageData(0, 0, width, height).data;</p><p>&nbsp; &nbsp; if (pixelData1.length != pixelData2.length) return;<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; for (var i = 0, total = pixelData1.length; i &lt; total; i ++ )<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; pixelData1[i] = (pixelData1[i] + pixelData2[i]) / 2; // ugly blend<br /> &nbsp; &nbsp; }<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; toContext.putImageData(imageData, 0, 0);<br /> }<br /> &nbsp;</div><p>This works. Yeah yeah, I know if i want a normal blend, I should grab the RGB values separately and mix them per channel, but this works in the experiment.. <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> I&#8217;m open for suggestions and optimalisation of this thing. Is there a simple (actionscript-like) BitmapData.draw() or BitmapData.copyPixels() alternative for this?</p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1448&amp;md5=88c1c7d6b7ac95d6089826871c3161c0" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/Orkhf_9qAkd9ex7GUMU1rtZfFqs/0/da"><img src="http://feedads.g.doubleclick.net/~a/Orkhf_9qAkd9ex7GUMU1rtZfFqs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Orkhf_9qAkd9ex7GUMU1rtZfFqs/1/da"><img src="http://feedads.g.doubleclick.net/~a/Orkhf_9qAkd9ex7GUMU1rtZfFqs/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stroep?a=yy2xXvpLm2k:T-RUyWUqmoI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stroep?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=yy2xXvpLm2k:T-RUyWUqmoI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stroep?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=yy2xXvpLm2k:T-RUyWUqmoI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stroep?i=yy2xXvpLm2k:T-RUyWUqmoI:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stroep/~4/yy2xXvpLm2k" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2012/03/generative-canvas-is-fun-too/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <atom:link rel="payment" href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1448&amp;md5=88c1c7d6b7ac95d6089826871c3161c0" type="text/html" /> <feedburner:origLink>http://blog.stroep.nl/2012/03/generative-canvas-is-fun-too/</feedburner:origLink></item> <item><title>Generative art: mixup</title><link>http://feedproxy.google.com/~r/stroep/~3/_hP-en4_q1k/</link> <comments>http://blog.stroep.nl/2011/12/generative-art-mixup/#comments</comments> <pubDate>Sun, 11 Dec 2011 12:49:55 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Generative art]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=1418</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/mixup1.jpg" alt="" width="570" height="408" class="image" />]]></description> <content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/markknol/6492227179/in/photostream"><img src="http://blog.stroep.nl/wp-content/mixup1.jpg" alt="" width="570" height="408" class="image" /></a></p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1418&amp;md5=0b7b1dbf3999141158b3d3675211b2fa" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/1XmVXOM9cQ8eiTs4R-5HtL_AoTk/0/da"><img src="http://feedads.g.doubleclick.net/~a/1XmVXOM9cQ8eiTs4R-5HtL_AoTk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/1XmVXOM9cQ8eiTs4R-5HtL_AoTk/1/da"><img src="http://feedads.g.doubleclick.net/~a/1XmVXOM9cQ8eiTs4R-5HtL_AoTk/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stroep?a=_hP-en4_q1k:-B1sINfCA-M:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stroep?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=_hP-en4_q1k:-B1sINfCA-M:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stroep?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=_hP-en4_q1k:-B1sINfCA-M:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stroep?i=_hP-en4_q1k:-B1sINfCA-M:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stroep/~4/_hP-en4_q1k" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/12/generative-art-mixup/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <atom:link rel="payment" href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1418&amp;md5=0b7b1dbf3999141158b3d3675211b2fa" type="text/html" /> <feedburner:origLink>http://blog.stroep.nl/2011/12/generative-art-mixup/</feedburner:origLink></item> <item><title>JSFL dialog</title><link>http://feedproxy.google.com/~r/stroep/~3/ebMEKMgayWE/</link> <comments>http://blog.stroep.nl/2011/12/jsfl-dialog/#comments</comments> <pubDate>Wed, 30 Nov 2011 23:35:04 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Code snippets]]></category> <category><![CDATA[JSFL]]></category> <category><![CDATA[flash]]></category> <category><![CDATA[jsfl]]></category> <category><![CDATA[workflow]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=1392</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/flash-ide.jpg" width="100" height="100" class="alignleft" alt="JSFL Dialog"/>While playing with JSFL and trying to create a faster interface for my <a href="http://blog.stroep.nl/2011/11/name-it-right-jsfl/" target="_blank">name it right.jsfl</a> I stumbled across a very interesting function inside JSFL. There is a powerful function called <em>fl.getDocumentDOM().xmlPanel</em> which shows dialogs using .xml-files. Actually you could use XUL (XML User Interface Language), which kinda looks like a mix of HTML and Flex. If you need a GUI for your JSFL script, you can open a nice custom dialog using XUL.]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/flash-ide.jpg" width="100" height="100" class="alignleft" alt="JSFL Dialog"/>While playing with JSFL and trying to create a faster interface for my <a href="http://blog.stroep.nl/2011/11/name-it-right-jsfl/" target="_blank">name it right.jsfl</a> I stumbled across a very interesting function inside JSFL. There is a powerful function called <em>fl.getDocumentDOM().xmlPanel</em> which shows dialogs using .xml-files. Actually you could use XUL (XML User Interface Language), which kinda looks like a mix of HTML and Flex. If you need a GUI for your JSFL script, you can open a nice custom dialog using XUL.</p><h2>Why create tools inside a tool?</h2><p>Yes, the Flash is a very nice IDE. But with JSFL you can extend it. You can build your own snippets and tools. It could be very helpful to automate some boring things. I think it is very powerful to have the ability to extend your environment for your everyday tasks.</p><h2>Show a dialog with JSFL</h2><p><strong>Create a dialog file</strong><br /> This is an example of XUL. Save it as <em>test-dialog.xml</em> in your <a href="http://blog.stroep.nl/2011/11/name-it-right-jsfl/#command-locations">local commands folder</a>.</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;dialog</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;JSFL dialog&quot;</span> <span style="color: #000066;">buttons</span>=<span style="color: #ff0000;">&quot;accept, cancel&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><br /> &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;vbox<span style="font-weight: bold; color: black;">&gt;</span></span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;label</span> <span style="color: #000066;">control</span>=<span style="color: #ff0000;">&quot;myTextfield&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Enter some text&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span> &nbsp;<br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;textbox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myTextfield&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;label</span> <span style="color: #000066;">control</span>=<span style="color: #ff0000;">&quot;myColor&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Choose a nice color&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span> &nbsp;<br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;radiogroup</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myColor&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span> &nbsp;<br /> &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;radio</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Orange&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span> &nbsp;<br /> &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;radio</span> <span style="color: #000066;">selected</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Violet&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span> &nbsp;<br /> &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;radio</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Yellow&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span> &nbsp;<br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/radiogroup<span style="font-weight: bold; color: black;">&gt;</span></span></span> &nbsp;<br /> &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/vbox<span style="font-weight: bold; color: black;">&gt;</span></span></span><br /> <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/dialog<span style="font-weight: bold; color: black;">&gt;</span></span></span><br /> &nbsp;</div><p><strong>Open the dialog with JSFL</strong><br /> Save it as <em>test-dialog.jsfl</em> in the same folder as the .xml file.</p><div class="bbCSH" style="font-family: monospace;"> // xmlPanel returns an Object with values of the dialog. <br /> var xmlPanelOutput = fl.getDocumentDOM().xmlPanel(fl.configURI + &quot;/Commands/test-dialog.xml&quot;);</p><p>if (xmlPanelOutput.dismiss == &quot;accept&quot;) // user confirms dialog<br /> {<br /> &nbsp; fl.trace(&quot;myTextfield: &quot; + xmlPanelOutput.myTextfield);<br /> &nbsp; fl.trace(&quot;myColor: &quot; + xmlPanelOutput.myColor);<br /> }<br /> else // user canceled dialog<br /> {<br /> &nbsp; <br /> }<br /> &nbsp;</div><p>Run it by clicking <em>&#8216;Commands&#8217; > &#8216;test-dialog&#8217;</em> in Flash; our custom dialog will show up. Nice! <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></p><h2>Give me more; I want dynamic dialogs</h2><p>If you check out the documentation of <em>fl.getDocumentDOM().xmlPanel</em>, you see you only can pass a uri to a xml file, but there is no way to pass a XML or Object to it. Adobe if you read this post; that would be nice. But I found a hack to create a dialog from JSFL by dynamically create a XML and save it as temporary file and open that one as xmlDialog. The file will be removed after showing the dialog.</p><div class="bbCSH" style="font-family: monospace;">function showXMLPanel(xmlString)<br /> {<br /> &nbsp; var tempUrl = fl.configURI + &quot;/Commands/temp-dialog-&quot; + parseInt(777 * 777) + &quot;.xml&quot;<br /> &nbsp; FLfile.write(tempUrl, xmlString);<br /> &nbsp; var xmlPanelOutput = fl.getDocumentDOM().xmlPanel(tempUrl);<br /> &nbsp; FLfile.remove(tempUrl);<br /> &nbsp; return xmlPanelOutput;<br /> }</div><p>This function displays a dialog from a (xml) string and returns the values like you would expect from the <em>xmlPanel</em>-function. You could use a XML object for this too, but I think it&#8217;s easier to hack some variables into it or make templates with strings.</p><div class="bbCSH" style="font-family: monospace;"> // create an XUL with JSFL<br /> var dialogXML = &#8221;;<br /> dialogXML += &#8216;&lt;dialog title=&quot;JSFL dynamic dialog&quot; buttons=&quot;accept, cancel&quot;&gt;&#8217;;<br /> dialogXML += &nbsp; &#8216;&lt;hbox&gt;&#8217;;<br /> dialogXML += &nbsp; &nbsp; &#8216;&lt;label value=&quot;Enter 2x something&quot;/&gt;&#8217;;<br /> dialogXML += &nbsp; &nbsp; &#8216;&lt;textbox id=&quot;myText1&quot; value=&quot;&quot;/&gt;&#8217;;<br /> dialogXML += &nbsp; &nbsp; &#8216;&lt;textbox id=&quot;myText2&quot; value=&quot;&quot;/&gt;&#8217;;<br /> dialogXML += &nbsp; &#8216;&lt;/hbox&gt;&#8217;;<br /> dialogXML += &#8216;&lt;/dialog&gt;&#8217;;</p><p>var xmlPanelOutput = showXMLPanel(dialogXML);<br /> if (xmlPanelOutput.dismiss == &quot;accept&quot;) // user confirms dialog<br /> {<br /> &nbsp; fl.trace(&quot;myText1: &quot; + xmlPanelOutput.myText1);<br /> &nbsp; fl.trace(&quot;myText2: &quot; + xmlPanelOutput.myText2);<br /> }<br /> else // user canceled dialog<br /> {<br /> &nbsp; <br /> }<br /> &nbsp;</div><p>Since you are dealing with strings, you can manipulate and add extra elements. This allows you to pass data from JSFL to your dialog.</p><h2>So, can you make panels too?</h2><p>I really hate custom panels, because I never get my workspace right for two screens (moving/closing/opening panels the whole day), so there is no room for other panels. I start loving JSFL-scripts because you can assign a shortcut-key to it, which runs the tool, without having a panel in my workspace.</p><h2>Conclusion</h2><p>I like to create handy snippets and will share more in the future. But if you thought (just like me) this is some kind of a new feature: <a href="http://twitter.com/#!/bit101/status/142003152454041600" target="_blank">It&#8217;s not</a>. <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Let me know if you have some nice references or JSFL scripts to share.</p><h2>Learn more:</h2><ul><li><a href="http://help.adobe.com/en_US/flash/cs/extend/flash_cs5_extending.pdf" target="_blank">JSFL Reference</a> (PDF)</li><li><a href="https://developer.mozilla.org/en/XUL_controls" target="_blank">XUL controls</a></li><li><a href="http://www.mozilla.org/projects/xul/" target="_blank">XUL reference</a></li></ul><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1392&amp;md5=d89701ffee4197ea9f8c2ae86cd1b3dd" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/aVO42IvnURy7Cif9zlZtxyfNZwg/0/da"><img src="http://feedads.g.doubleclick.net/~a/aVO42IvnURy7Cif9zlZtxyfNZwg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/aVO42IvnURy7Cif9zlZtxyfNZwg/1/da"><img src="http://feedads.g.doubleclick.net/~a/aVO42IvnURy7Cif9zlZtxyfNZwg/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stroep?a=ebMEKMgayWE:jjtbiKAXAKM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stroep?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=ebMEKMgayWE:jjtbiKAXAKM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stroep?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=ebMEKMgayWE:jjtbiKAXAKM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stroep?i=ebMEKMgayWE:jjtbiKAXAKM:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stroep/~4/ebMEKMgayWE" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/12/jsfl-dialog/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <atom:link rel="payment" href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1392&amp;md5=d89701ffee4197ea9f8c2ae86cd1b3dd" type="text/html" /> <feedburner:origLink>http://blog.stroep.nl/2011/12/jsfl-dialog/</feedburner:origLink></item> <item><title>Lights and shadows experiment</title><link>http://feedproxy.google.com/~r/stroep/~3/jNCO4Os4pJ0/</link> <comments>http://blog.stroep.nl/2011/11/lights-and-shadows/#comments</comments> <pubDate>Mon, 28 Nov 2011 22:55:28 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Code snippets]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[experiment]]></category> <category><![CDATA[flash]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=1322</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/lights-150x150.png" alt="" title="lights and shadows" width="100" height="100" class="alignleft size-thumbnail wp-image-1332" />Recently I found an interesting question on FlashFocus.nl, about creating light and shadows in a 2D environment. I started experimenting with this to see how far I could take it. I love to share the results and some insides about this fun project.]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/lights-150x150.png" alt="" title="lights and shadows" width="100" height="100" class="alignleft size-thumbnail wp-image-1332" />Recently I found an <a href="http://www.flashfocus.nl/forum/showthread.php?t=63044">interesting question on FlashFocus.nl</a>, about creating light and shadows in a 2D environment. I started experimenting with this to see how far I could take it. I love to share the results and some insides about this fun project.</p><p><center><a href="http://projects.stroep.nl/lights/"><img src="http://blog.stroep.nl/wp-content/lights-shadows-experiment.jpg" alt="" title="Lights and shadows experiment" width="492" height="221" class="size-full wp-image-1367" /></a></center></p><h2>How to get started</h2><p><a href="http://www.flashfocus.nl/forum/showpost.php?p=416394&#038;postcount=11" title="Initial code on FlashFocus (Dutch)">The initial code</a> that the topic starter used a loop through all objects, and used <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html?filter_flash=cs5&#038;filter_flashplayer=10.2&#038;filter_air=2.6#hitTestPoint()" title="DisplayObject.hitTestPoint function on Adobe LiveDocs">hitTestPoint</a>-function to detect if the light hits a wall. Therefore he used a loop with 360 steps, used for all directions. In the innerloop it tries if it hits the wall, otherwise goes away from the light (using the direction of the outerloop), tries if it hits the wall. That loop goes on till it does hit a wall. It is a bit of trial and error, but I think it is very clever. At the end of each loop a lineTo is used to draw the light, so in the end it will be a shape with 360 vector points.</p><h2>Speed of light</h2><p>Now, that screams for optimization and speed. It&#8217;s a fun project to mix some things you have seen and want to try out for a long time. The first thing that I tried to make it faster, draw all objects into an <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html" title="BitmapData at Adobe LiveDocs">BitmapData</a>, and use the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#getPixel()">getPixel</a> function instead of <em>hitTestPoint</em>, which is notable faster if you don&#8217;t move objects. I used that <em>BitmapData</em> object only too check if the light hits the objects; no one actually sees it. To use <em>hitTestPoint</em>, you must loop through all objects and detect if they hit. With a lot of objects, it would be slower. With <em>BitmapData</em>, you don&#8217;t need that loop, and you are free to use unlimited objects with even custom shapes. Less looping == faster, unlimited objects == awesome <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><h2>More realism</h2><p>I also wanted to make it look more realistic. Having light only is not close enough to realism. It needs shadows. I created an inverted shape of the light-shape and filled it with black (a). This creates a nice shadow, however has very hard bounds, which is ugly. So then I took the shape again and drawed with a nice transparent to black gradient (b). Those 2 layers have the BlendMode ALPHA. The holder of those has a solid shape fill (as big as the stage) with BlendMode LAYER. This creates a nice &#8216;hole&#8217; which I think works very well as shadow if you make it half-transparent. Oh, the colored light-layer (c) is a gradient too, with the same shape as b, only with BlendMode ADD.</p><p><center><a href="http://projects.stroep.nl/lights/"><img src="http://blog.stroep.nl/wp-content/lights-shadows-layers.jpg" alt="" title="lights and shadows layers" width="560" height="221" class="alignnone size-full wp-image-1375" /></a></center></p><h2>Re-using shape data</h2><p>Another optimization I used was to use <a href='../07/the-new-lineto/' title='The new graphics.lineTo'>graphics data API</a>. In this case I have 1 shape which could be reused 3 times. So before even drawing, I collect all points and commands in an Vector. When I have all data collected, it draws the light-layer and shadow-layer at first, then it pushes some extra points to the Array to make the outer shadow-layer. So with 1 Array of (manipulated) data I could draw multiple shapes. That&#8217;s a good case of using the graphics data, I guess.</p><h2>Optimized trig functions</h2><p>I also used the <a href="http://jacksondunstan.com/articles/1190">TrigLUT</a>-class (Trigonometry LookUp Table) from <a href="http://www.jacksondunstan.com/">jacksondunstan.com</a>, since the loop heavily uses Math.sin and Math.cos. I could use the <em>valNormalizedPositive()</em> function from that class in this case. It&#8217;s very fast and for me it was fun to use that class. <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></p><h2>But it is still too slow..</h2><p>The most intense about this thing isn&#8217;t the calculation, but the rendering itself. The whole &#8216;canvas&#8217; needs to be updated and redrawed every frame with lots of layers and blendmodes, which is very intense for the CPU. I don&#8217;t know if this would be possible  with Stage3D, but that would be the last step to render really fast. And when that is possible, I&#8217;ll guess I could move the object real-time too, which makes it very interesting for games.</p><p><strong>Check out the experiment:<br /> » <a href="http://projects.stroep.nl/lights/">Lights and shadows</a></strong></p><p>Let me know what you think about it and how does it perform on your computer?</p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1322&amp;md5=42908c11d2d8a98ce7bbb949c7b586ec" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/M56UIIqkwMU-Dgnn0_U8UeZVSZU/0/da"><img src="http://feedads.g.doubleclick.net/~a/M56UIIqkwMU-Dgnn0_U8UeZVSZU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/M56UIIqkwMU-Dgnn0_U8UeZVSZU/1/da"><img src="http://feedads.g.doubleclick.net/~a/M56UIIqkwMU-Dgnn0_U8UeZVSZU/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stroep?a=jNCO4Os4pJ0:uQLzXwLbCTk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stroep?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=jNCO4Os4pJ0:uQLzXwLbCTk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stroep?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=jNCO4Os4pJ0:uQLzXwLbCTk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stroep?i=jNCO4Os4pJ0:uQLzXwLbCTk:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stroep/~4/jNCO4Os4pJ0" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/11/lights-and-shadows/feed/</wfw:commentRss> <slash:comments>6</slash:comments> <atom:link rel="payment" href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1322&amp;md5=42908c11d2d8a98ce7bbb949c7b586ec" type="text/html" /> <feedburner:origLink>http://blog.stroep.nl/2011/11/lights-and-shadows/</feedburner:origLink></item> <item><title>Handy Flash IDE tool: Name it right.jsfl</title><link>http://feedproxy.google.com/~r/stroep/~3/Z-b-Zj9Kp14/</link> <comments>http://blog.stroep.nl/2011/11/name-it-right-jsfl/#comments</comments> <pubDate>Mon, 28 Nov 2011 19:45:10 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[JSFL]]></category> <category><![CDATA[flash]]></category> <category><![CDATA[jsfl]]></category> <category><![CDATA[workflow]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=1353</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/flash-ide.jpg" width="100" height="100" class="alignleft" />I have created a JSFL script for those who are using the Flash IDE a lot. Renaming movieclips over a timeline with motion-tweens cost a lot of time. Assigning and replacing classes to a certain movieclip could also be done faster, and mostly name of the symbol relates to the names on stage. I have created a 3-step wizard called 'name it right!', to speed up your everyday workflow. This command helps you to update a layer name, base class, symbol name and instances on the timeline very fast.]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/flash-ide.jpg" width="100" height="100" class="alignleft" />I have created a JSFL script for those who are using the Flash IDE a lot. Renaming movieclips over a timeline with motion-tweens cost a lot of time. Assigning and replacing classes to a certain movieclip could also be done faster, and mostly name of the symbol relates to the names on stage. I have created a 3-step wizard called &#8216;name it right!&#8217;, to speed up your everyday workflow. This command helps you to update a layer name, base class, symbol name and instances on the timeline very fast.</p><p><strong>Download/Save the .jsfl file directly:<br /> » <a href="http://projects.stroep.nl/name-it-right/%5B0%5D%20Name%20it%20right!.jsfl">Name it right.jsfl</a> </strong>(v1.1)</p><p>To indicate what happens when you run the command/script:</p><p>First select an instance on stage. Go to <em>&#8216;Commands&#8217; > &#8216;Name it right!&#8217;</em>.<br /> You&#8217;ll get these three questions.</p><li>1/3 <strong>Rename library symbol name?</strong><ul><li>Enter the new symbol name in the prompt.</li><li>When you have selected &#8216;Export voor ActionScript&#8217;, it will automatically fill the &#8216;Class&#8217; according this convention: &#8216;fileName.SymbolName&#8217;.</li></ul></li><li>2/3 <strong>The library symbol already has a base class, change it?</strong><ul><li>Enter the new base class in the prompt.</li><li>If there is no base class defined, it will turn on &#8216;Export voor ActionScript&#8217; and fill &#8216;Class&#8217; as mentioned above.</li></ul></li><li>3/3 <strong>Rename instance name across timeline?</strong><ul><li>This renames a movieclip instance on the complete timeline. It does not matter if there is a motion-tween on it. You only need to insure there is only one clip on that layer. Otherwise it will give you a note.</li><li>It will give you a name suggestion based on you Symbol name, like &#8216;mcSymbolname&#8217;</li></ul></li><p><em>Cancel</em> means: do nothing.<br /> <a id='command-locations' name='command-locations'></a></p><h2>Install / use the JSFL script</h2><p>To get it inside the Flash IDE under &#8216;Commands&#8217;, copy the .jsfl file to:</p><p><em>Windows 7</em><br /> <small>C:\Users\{username}\AppData\Local\Adobe\Flash CS5 or CS5.5\en_US\Configuration\Commands</small></p><p><em>Windows Vista:</em><br /> <small>C:\Users\{username}\Local Settings\Application Data\Adobe\Flash CS5 or CS5.5\en_US\Configuration\Commands</small></p><p><em>Windows XP:</em><br /> <small>C:\Documents and Settings\{username}\Local Settings\Application Data\Adobe\Flash CS5 or CS5.5\en_US\Configuration\Commands</small></p><p><em>Mac OS X: </em><br /> <small>C:/Users/{username}/Library/Application Support/Adobe/Flash CS5 or CS5.5/en_US/Configuration/Commands</small></p><p>Run it by clicking the &#8216;Name it right!&#8217; under &#8216;Commands&#8217;.</p><p>You could assign a key-combination under &#8216;Edit&#8217; > &#8216;Keyboard shortcuts&#8217; and then expand the &#8216;commands&#8217;-folder. I used CTRL-ALT-SHIFT-W for it.</p><p>Hope you could use it, post your feedback/suggestions below.</p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1353&amp;md5=8db202d8bb7fc93865e893e379581b02" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/jBvaDrXbcuDj7R1XI_AT7gjqCQg/0/da"><img src="http://feedads.g.doubleclick.net/~a/jBvaDrXbcuDj7R1XI_AT7gjqCQg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/jBvaDrXbcuDj7R1XI_AT7gjqCQg/1/da"><img src="http://feedads.g.doubleclick.net/~a/jBvaDrXbcuDj7R1XI_AT7gjqCQg/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stroep?a=Z-b-Zj9Kp14:txPbg5ZJCvE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stroep?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=Z-b-Zj9Kp14:txPbg5ZJCvE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stroep?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=Z-b-Zj9Kp14:txPbg5ZJCvE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stroep?i=Z-b-Zj9Kp14:txPbg5ZJCvE:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stroep/~4/Z-b-Zj9Kp14" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/11/name-it-right-jsfl/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <atom:link rel="payment" href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1353&amp;md5=8db202d8bb7fc93865e893e379581b02" type="text/html" /> <feedburner:origLink>http://blog.stroep.nl/2011/11/name-it-right-jsfl/</feedburner:origLink></item> <item><title>Design pattern – Behaviors</title><link>http://feedproxy.google.com/~r/stroep/~3/PzEuZnbFKfA/</link> <comments>http://blog.stroep.nl/2011/10/behaviors/#comments</comments> <pubDate>Sun, 16 Oct 2011 18:07:22 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[oop]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=1295</guid> <description><![CDATA[<img alt="Design pattern - Behaviors" src="http://farm3.static.flickr.com/2631/3753675658_2904c86297_t.jpg" class="alignleft" width="100" height="100" />I recently started working at <a href="http://www.mediamonks.com/" target="_blank">MediaMonks</a> where they are using this interesting pattern of coding; behaviors as a class. I started playing with 'behaviors' myself to see how this could work for me. If you use this pattern once, you'll wonder why you did not use it ever before ;) This post will lead you through some examples and shows some benefits of using it. ]]></description> <content:encoded><![CDATA[<p><img alt="Design pattern - Behaviors" src="http://farm3.static.flickr.com/2631/3753675658_2904c86297_t.jpg" class="alignleft" width="100" height="100" />I recently started working at <a href="http://www.mediamonks.com/" target="_blank">MediaMonks</a> where they are using this interesting pattern of coding; behaviors as a class. I started playing with &#8216;behaviors&#8217; myself to see how this could work for me. If you use this pattern once, you&#8217;ll wonder why you did not use it ever before <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> This post will lead you through some examples and shows some benefits of using it. This post is written with focus on actionscript 3 developers, who can read code and knows already something about object oriented programming. The goal is to learn more and become a better developer.</p><h2>What is a behavior?</h2><p>Well I guess everybody knows what it means, but in terms of code I would say that a behavior-class is some kind of a simple controller with a target. It does one thing, it controls the target with a specific feature/goal. The idea is to add functionality by assigning a behavior to an object (<a href="http://en.wikipedia.org/wiki/Composition_in_object-oriented_programming">composition</a>), instead of extending it to get the functionality (<a href="http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)">inheritance</a>). That sound complicated, so why not check out what it practically means?</p><h2>Difference between inheritance and composition</h2><p>Let&#8217;s say you want to program an object that follows your mouse. How would you create it? I would create a class named <em>MouseFollowingSprite </em>which has all functions to do that. Then I would extend or create an instance of that <em>MouseFollowingSprite</em>-class and BANG I&#8217;m done <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p><strong>Typical example of inheritance</strong></p><blockquote><p>class MouseFollowingSprite extends Sprite</p></blockquote><p>Okay, lets write down that killer class:</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">package</span> nl.<span style="color: #006600;">stroep</span>.<span style="color: #006600;">display</span><br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">Sprite</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br /> &nbsp; &nbsp; &nbsp;* @author Mark Knol<br /> &nbsp; &nbsp; &nbsp;*/</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">class</span> MouseFollowingSprite <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">Sprite</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _ease:<span style="color: #0066CC;">Number</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> MouseFollowingSprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, handleEnterFrame<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> handleEnterFrame<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 /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> update<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">x</span> += <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">mouseX</span> &#8211; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> / _ease;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> += <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">mouseY</span> &#8211; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span> / _ease;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>(You see that? It&#8217;s nicely done with some eased motion <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> )</p><p>I have never seen a problem with extending, but I had troubles with finding a good way to add other kind of functions to this type of classes. In terms of OOP, is a rule to write classes with a <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">single responsibility</a>, and we already passed that one. But imaging you want your mouse following sprite also to scale when you scroll with your mouse wheel. Well that would be easy: Just create a class named <em>ScrollWheelScalingSprite</em>, which extends <em>MouseFollowingSprite</em>. Now it has both functionality, when you would create an instance of it.</p><p>Let&#8217;s create our ScrollWheelScalingSprite, it would like this:</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">package</span> nl.<span style="color: #006600;">stroep</span>.<span style="color: #006600;">display</span><br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br /> &nbsp; &nbsp; &nbsp;* &#8230;<br /> &nbsp; &nbsp; &nbsp;* @author Mark Knol<br /> &nbsp; &nbsp; &nbsp;*/</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">class</span> ScrollwheelScaleSprite <span style="color: #0066CC;">extends</span> MouseFollowingSprite<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _ease:<span style="color: #0066CC;">Number</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _targetScale:<span style="color: #0066CC;">Number</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _hasListener:<span style="color: #0066CC;">Boolean</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _deltaRatio:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0.1</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _minimum:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">NaN</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _maximum:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">NaN</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> ScrollwheelScaleSprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _targetScale = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">scaleX</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p><p>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_WHEEL</span>, handleMouseWheel<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addEnterFrameListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> handleMouseWheel<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _targetScale += <span style="color: #0066CC;">e</span>.<span style="color: #006600;">delta</span> * _deltaRatio;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0066CC;">isNaN</span><span style="color: #66cc66;">&#40;</span>_minimum<span style="color: #66cc66;">&#41;</span> &amp;&amp; _targetScale &lt; _minimum<span style="color: #66cc66;">&#41;</span> _targetScale = _minimum;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0066CC;">isNaN</span><span style="color: #66cc66;">&#40;</span>_maximum<span style="color: #66cc66;">&#41;</span> &amp;&amp;_targetScale &gt; _maximum<span style="color: #66cc66;">&#41;</span> _targetScale = _maximum;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addEnterFrameListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> addEnterFrameListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!_hasListener<span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, handleEnterFrame<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _hasListener = <span style="color: #000000; ">true</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> removeEnterFrameListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, handleEnterFrame<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _hasListener = <span style="color: #000000; ">false</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> handleEnterFrame<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 /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> update<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">scaleX</span> += <span style="color: #66cc66;">&#40;</span>_targetScale &#8211; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">scaleX</span> <span style="color: #66cc66;">&#41;</span> / _ease;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">scaleY</span> = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">scaleX</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">scaleX</span> &#8211; _targetScale<span style="color: #66cc66;">&#41;</span> &lt; .<span style="color: #cc66cc;">01</span><span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeEnterFrameListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>Let&#8217;s go some deeper. What if you want a <em>ScrollwheelScaleSprite </em>which should not follow our mouse? That would be a problem, because it already has that functionality. However you could hack around around by adding some protected booleans, to enable the actual functions of the class. Name them like <em>_mouseFollowingEnabled</em>. When your class extend some other classes, you&#8217;ll probably need a <em>_scrollWheelScalingEnabled</em> too. In the constructor of the new class you just turn on/off the booleans and your done. But then again, if you want to use this to Bitmap, you have a problem, you cannot extend a Sprite and a Bitmap at the same time.</p><p>I mean, this is how we code, right? All classes have one responsibility, but could this example been done better? While writing, this post reminds me in a way to <a href="http://www.bit-101.com/blog/?p=2173">this older post</a> of Keith Peters; you should read it. It also has a interesting discussion.</p><h2>Create behaviors</h2><p>As already stated, a behavior class is a controller. It deals with an object (we call it target) to add the actual behavior. Now I don&#8217;t think extending is bad, but I think we should use it with care.</p><p>Let&#8217;s create an abstract behavior class, which can be extended. (This is not needed, but very helpful for accessing the target and prevent duplicate code)</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">package</span> nl.<span style="color: #006600;">stroep</span>.<span style="color: #006600;">behaviors</span> <br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br /> &nbsp; &nbsp; &nbsp;* @author Mark Knol<br /> &nbsp; &nbsp; &nbsp;*/</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">class</span> AbstractBehavior <br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; ">var</span> <span style="color: #0066CC;">_target</span>: DisplayObject;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> AbstractBehavior<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>: DisplayObject<span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_target</span> = <span style="color: #0066CC;">target</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>I think this does not require lots of explanation. We have a class, it saves a target<br /> that is passed from the constructor. We can do lot&#8217;s of stuff inside a behavior from this point.</p><p>Now, let&#8217;s convert our <em>MouseFollowingSprite </em>to a <em>MouseFollowingBehavior</em>, which should extends the AbstractBehavior. Most drastic change is to convert &#8216;<em>this</em>&#8216;, to &#8216;<em>_target</em>&#8216; and change the constructor to make it an actual behavior:</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">package</span> nl.<span style="color: #006600;">stroep</span>.<span style="color: #006600;">behaviors</span> <br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br /> &nbsp; &nbsp; &nbsp;* @author Mark Knol<br /> &nbsp; &nbsp; &nbsp;*/</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">class</span> MouseFollowBehavior <span style="color: #0066CC;">extends</span> AbstractBehavior <br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _ease:<span style="color: #0066CC;">Number</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> MouseFollowBehavior<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>: DisplayObject, ease:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _ease = ease;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, handleEnterFrame<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> handleEnterFrame<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 /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> update<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">x</span> += <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_target</span>.<span style="color: #006600;">mouseX</span> &#8211; <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> / _ease;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">y</span> += <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_target</span>.<span style="color: #006600;">mouseY</span> &#8211; <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span> / _ease;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>This is not magic, but it is very powerful. We can assign this behavior to a <em>Sprite</em>, but also to a <em>Bitmap</em> or <em>Video</em> etc. This would not that easy / possible with inheritance only. The class works standalone and we don&#8217;t need booleans to enable or disable the behavior.</p><p>Ok, let&#8217;s also create the scroll wheel scale behavior:</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">package</span> nl.<span style="color: #006600;">stroep</span>.<span style="color: #006600;">art</span>.<span style="color: #006600;">behaviors</span> <br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br /> &nbsp; &nbsp; &nbsp;* &#8230;<br /> &nbsp; &nbsp; &nbsp;* @author Mark Knol<br /> &nbsp; &nbsp; &nbsp;*/</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">class</span> ScrollwheelScaleBehavior <span style="color: #0066CC;">extends</span> AbstractBehavior <br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _ease:<span style="color: #0066CC;">Number</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _targetScale:<span style="color: #0066CC;">Number</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _hasListener:<span style="color: #0066CC;">Boolean</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _deltaRatio:<span style="color: #0066CC;">Number</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _minimum:<span style="color: #0066CC;">Number</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> _maximum:<span style="color: #0066CC;">Number</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> ScrollwheelScaleBehavior<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>: DisplayObject, ease:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">5</span>, deltaRatio:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0.1</span>, minimum:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">NaN</span>, maximum:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">NaN</span><span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _ease = ease;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _deltaRatio = deltaRatio;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _minimum = minimum;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _maximum = maximum;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _targetScale = <span style="color: #0066CC;">target</span>.<span style="color: #006600;">scaleX</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">_target</span>.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_WHEEL</span>, handleMouseWheel<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addEnterFrameListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> handleMouseWheel<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _targetScale += <span style="color: #0066CC;">e</span>.<span style="color: #006600;">delta</span> * _deltaRatio;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0066CC;">isNaN</span><span style="color: #66cc66;">&#40;</span>_minimum<span style="color: #66cc66;">&#41;</span> &amp;&amp; _targetScale &lt; _minimum<span style="color: #66cc66;">&#41;</span> _targetScale = _minimum;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0066CC;">isNaN</span><span style="color: #66cc66;">&#40;</span>_maximum<span style="color: #66cc66;">&#41;</span> &amp;&amp;_targetScale &gt; _maximum<span style="color: #66cc66;">&#41;</span> _targetScale = _maximum;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addEnterFrameListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> addEnterFrameListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!_hasListener<span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, handleEnterFrame<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _hasListener = <span style="color: #000000; ">true</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> removeEnterFrameListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, handleEnterFrame<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _hasListener = <span style="color: #000000; ">false</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> handleEnterFrame<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 /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> update<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">scaleX</span> += <span style="color: #66cc66;">&#40;</span>_targetScale &#8211; <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">scaleX</span> <span style="color: #66cc66;">&#41;</span> / _ease;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">scaleY</span> = <span style="color: #0066CC;">_target</span>.<span style="color: #006600;">scaleX</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_target</span>.<span style="color: #006600;">scaleX</span> &#8211; _targetScale<span style="color: #66cc66;">&#41;</span> &lt; .<span style="color: #cc66cc;">01</span><span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeEnterFrameListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>Now we can assign a behavior very easy:<br /> <strong>Example of applying the behaviors</strong></p><blockquote><p>var sprite:Sprite = new Sprite();<br /> new MouseFollowBehavior(sprite);<br /> new ScrollwheelScaleBehavior(sprite);</p></blockquote><p>You are now free to add the behaviors you&#8217;ll need, and leave the one you don&#8217;t need. It&#8217;s like creating little plugins. Fun eh? It&#8217;s nice to add parameters to the constructor, to make it less static. The other fun part is that if you build a behavior right, you could copy/paste it to another project or in you library, because it has no dependencies to classes you don&#8217;t want or need. Of course, this is not something new, you could have seen this in <a href="http://code.google.com/p/templelibrary/source/browse/trunk#trunk%2Flib%2Ftemple%2Fui%2Fbehaviors">temple-lib</a> but also the <a href="https://github.com/hype/hype/tree/master/src/hype/extended/behavior">Hype-framework</a> too, and maybe lots of other framework probably use this pattern in a way.</p><p>Now we know the difference:<br /> <strong>Inheritence:</strong> <em>&#8220;I want a Sprite that follows my mouse&#8221;</em><br /> <strong>Behaviors:</strong> <em>&#8220;I want something that makes a Sprite follow my mouse&#8221;</em></p><h2>Killing the behaviors</h2><p>The code examples in this post does not have any function to remove it, but if you want to remove a behavior, it would be wise to assign the behavior to a variable, and create a destruct() or destroy() function inside the behaviors to remove listeners and references to the target etc, and then set it to <em>null</em>.</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #808080; font-style: italic;">// Anywhere in your code:</span><br /> <span style="color: #000000; ">var</span> myBehavior:MouseFollowBehavior = <span style="color: #000000; ">new</span> MouseFollowBehavior<span style="color: #66cc66;">&#40;</span>myMc<span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// Somewhere in your code where you want to remove the behavior:</span><br /> myBehavior.<span style="color: #006600;">destroy</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// a public function which removes all listeners, references etc </span><br /> myBehavior = <span style="color: #000000; ">null</span>;<br /> &nbsp;</div><h2>Conclusion</h2><p>Behaviors are a cool and give clean reusable classes and I think we should use it more. It&#8217;s probably not new for you and the inheritence-example is not very realistic, but I hope it&#8217;s refreshing to look at it again. If you want to learn more design patterns, I also recommend <a href="http://www.as3dp.com/">this site</a>.</p><p>If you think back on how you have coded in the past, what would you change now you know this pattern? BTW I want to learn more too, so don&#8217;t hesitate to leave some nice feedback below.</p><p><small style='color:#777'>Oh, maybe you haven&#8217;t heard, but something unexpected will happen if you hold CTRL and click on the facebook like-button (found that in a YouTube comment; very lame).</small></p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1295&amp;md5=c5800b6caadc18178824a5e54b1c07a6" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/ZMAncS6GUuivQyB9OyYuTkLgDnE/0/da"><img src="http://feedads.g.doubleclick.net/~a/ZMAncS6GUuivQyB9OyYuTkLgDnE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ZMAncS6GUuivQyB9OyYuTkLgDnE/1/da"><img src="http://feedads.g.doubleclick.net/~a/ZMAncS6GUuivQyB9OyYuTkLgDnE/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stroep?a=PzEuZnbFKfA:w49A5ROqbds:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stroep?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=PzEuZnbFKfA:w49A5ROqbds:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stroep?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=PzEuZnbFKfA:w49A5ROqbds:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stroep?i=PzEuZnbFKfA:w49A5ROqbds:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stroep/~4/PzEuZnbFKfA" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/10/behaviors/feed/</wfw:commentRss> <slash:comments>7</slash:comments> <atom:link rel="payment" href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1295&amp;md5=c5800b6caadc18178824a5e54b1c07a6" type="text/html" /> <feedburner:origLink>http://blog.stroep.nl/2011/10/behaviors/</feedburner:origLink></item> <item><title>Actionscript 3 Event Generator</title><link>http://feedproxy.google.com/~r/stroep/~3/1AEqJH4XTUg/</link> <comments>http://blog.stroep.nl/2011/10/actionscript-3-event-generator/#comments</comments> <pubDate>Mon, 10 Oct 2011 19:54:55 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[events]]></category> <category><![CDATA[tool]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=1283</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/as3-event-generator.png" alt="" width="100" height="100" class="alignleft size-full wp-image-1286" />Finally I have created and finalized my Actionscript 3 <a href="http://projects.stroep.nl/EventGenerator/">Event Generator</a>, which was buggy but now it is very nice :)  As <a href="http://twitter.com/#!/mknol/status/120917893415321600">stated on twitter</a>, if you are a flashdeveloper and use custom events in actionscript 3, you should use this tool because it helps you create custom event classes very fast.]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/as3-event-generator.png" alt="" width="100" height="100" class="alignleft size-full wp-image-1286" />Finally I have created and finalized my Actionscript 3 <a href="http://projects.stroep.nl/EventGenerator/">Event Generator</a>, which was buggy but now it is very nice <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> As <a href="http://twitter.com/#!/mknol/status/120917893415321600">stated on twitter</a>, if you are a flashdeveloper and use custom events in actionscript 3, you should use this tool because it helps you create custom event classes very fast.</p><p><strong>Features:</strong><br /> - Fast variable adding<br /> - Event type generation (static constants). Just use lower camelCased variables and they will be formatted nicely.<br /> - Meta data for a event dispatcher class.<br /> - Automatic clone() function<br /> - Automatic toString() function</p><p><strong>URL</strong><br /> » <strong><a href="http://projects.stroep.nl/EventGenerator/">http://projects.stroep.nl/EventGenerator/</a></strong></p><p>Don&#8217;t forget to first fill your name at @author on the right. The package and @author will be saved for next time.</p><p>I have also created a dropdown-menu on the top-right to switch to other tools. Happy coding!</p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1283&amp;md5=d6900eafca74d75ae064d94ab4f01d1d" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/bTp6s2hMAabqikb42GfaTgX1D4Q/0/da"><img src="http://feedads.g.doubleclick.net/~a/bTp6s2hMAabqikb42GfaTgX1D4Q/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/bTp6s2hMAabqikb42GfaTgX1D4Q/1/da"><img src="http://feedads.g.doubleclick.net/~a/bTp6s2hMAabqikb42GfaTgX1D4Q/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stroep?a=1AEqJH4XTUg:DmJROnDjTV0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stroep?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=1AEqJH4XTUg:DmJROnDjTV0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stroep?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=1AEqJH4XTUg:DmJROnDjTV0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stroep?i=1AEqJH4XTUg:DmJROnDjTV0:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stroep/~4/1AEqJH4XTUg" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/10/actionscript-3-event-generator/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <atom:link rel="payment" href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1283&amp;md5=d6900eafca74d75ae064d94ab4f01d1d" type="text/html" /> <feedburner:origLink>http://blog.stroep.nl/2011/10/actionscript-3-event-generator/</feedburner:origLink></item> <item><title>Actionscript 3 Extended valueobject generator</title><link>http://feedproxy.google.com/~r/stroep/~3/MS42LC26aDw/</link> <comments>http://blog.stroep.nl/2011/09/enumgenerator/#comments</comments> <pubDate>Tue, 20 Sep 2011 06:19:22 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[tool]]></category> <category><![CDATA[ValueObject]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=1272</guid> <description><![CDATA[<img src="http://img.youtube.com/vi/A-fCGKQySmI/0.jpg" class="alignleft" width="100" height="100" />I created a tool to created 'grouped' value objects nicely and very fast. It is using private classes. I found it useful enough to share it with you, so maybe if you are in need of such a tool, you are free to use it.Click on <em>read more</em> to see more details.]]></description> <content:encoded><![CDATA[<p><iframe width="100%" height="375" src="http://www.youtube.com/embed/A-fCGKQySmI" frameborder="0" allowfullscreen></iframe></p><p>I created a tool to created &#8216;grouped&#8217; value objects nicely and very fast. It is using private classes. I found it useful enough to share it with you, so maybe if you are in need of such a tool, you are free to use it.</p><p>» <strong>Check it out: <a href="http://projects.stroep.nl/enumGenerator/">http://projects.stroep.nl/enumGenerator/</a></strong></p><p>Oh, if you want to create normal value objects, use the <a href="http://projects.stroep.nl/ValueObjectGenerator/">value object generation tool</a>. For creating custom events classes, I have an <a href="http://projects.stroep.nl/EventGenerator/">custom event generator</a>.</p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1272&amp;md5=86e44790ca307ef70ef3eb3eab24a99b" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/u2y3zBNhYHO0WAAo1ts5PjtERkE/0/da"><img src="http://feedads.g.doubleclick.net/~a/u2y3zBNhYHO0WAAo1ts5PjtERkE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/u2y3zBNhYHO0WAAo1ts5PjtERkE/1/da"><img src="http://feedads.g.doubleclick.net/~a/u2y3zBNhYHO0WAAo1ts5PjtERkE/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/stroep?a=MS42LC26aDw:CPGUegtqKso:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/stroep?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=MS42LC26aDw:CPGUegtqKso:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/stroep?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/stroep?a=MS42LC26aDw:CPGUegtqKso:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/stroep?i=MS42LC26aDw:CPGUegtqKso:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/stroep/~4/MS42LC26aDw" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/09/enumgenerator/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <atom:link rel="payment" href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1272&amp;md5=86e44790ca307ef70ef3eb3eab24a99b" type="text/html" /> <feedburner:origLink>http://blog.stroep.nl/2011/09/enumgenerator/</feedburner:origLink></item> </channel> </rss>

