<?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; flash</title> <atom:link href="http://blog.stroep.nl/tag/flash/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>JSFL dialog</title><link>http://blog.stroep.nl/2011/12/jsfl-dialog/</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>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/12/jsfl-dialog/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Lights and shadows experiment</title><link>http://blog.stroep.nl/2011/11/lights-and-shadows/</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>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/11/lights-and-shadows/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Handy Flash IDE tool: Name it right.jsfl</title><link>http://blog.stroep.nl/2011/11/name-it-right-jsfl/</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>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/11/name-it-right-jsfl/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Remove eventListeners automatically  in AS3</title><link>http://blog.stroep.nl/2010/09/remove-eventlisteners-in-as3/</link> <comments>http://blog.stroep.nl/2010/09/remove-eventlisteners-in-as3/#comments</comments> <pubDate>Tue, 28 Sep 2010 18:05:51 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Code snippets]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[events]]></category> <category><![CDATA[flash]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=991</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">I hate removing listeners in AS3. So I created a work-around to autoremove them :) I know there are already some solutions for this, but some of them requires a complete new event system and it is just fun to create your own sources. This class overrides the default behavior of the <em>addEventListener</em> function. It stores references of the listeners inside a Dictionary. The class it selfs listens to the REMOVED_FROM_STAGE event, and when it is removed, then it removes all stored events. ]]></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">I hate removing listeners in AS3. So I created a work-around to autoremove them <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I know there are already some solutions for this, but some of them requires a complete new event system and it is just fun to create your own sources. This class overrides the default behavior of the <em>addEventListener</em> function. It stores references of the listeners inside a Dictionary. The class it selfs listens to the REMOVED_FROM_STAGE event, and when it is removed, then it removes all stored events.</p><blockquote><p> UPDATE 11-10-2010: This code below is a bit outdated. <br/>You&#8217;d better use <a href="http://code.google.com/p/stroep/source/browse/#svn%2Ftrunk%2Fflashsources%2Fflashflowfactory%20framework%2Fnl%2Fstroep%2Fflashflowfactory%2Fdisplay">this EventManagedSprite</a> and <a href="http://code.google.com/p/stroep/source/browse/#svn%2Ftrunk%2Fflashsources%2Fflashflowfactory%20framework%2Fnl%2Fstroep%2Fflashflowfactory%2Futils%253Fstate%253Dclosed">this EventRemover</a>. BTW: This is all included in <a href="http://code.google.com/p/stroep/wiki/FlashFlowFactory">FlashFlowFactory</a>. This lightweight framework helps you to easily setup a flash website.</p></blockquote><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; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Dictionary</span>;<br /> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br /> &nbsp; &nbsp; &nbsp;* Simple event managing sprite which automatically removes eventlisteners when the sprite is removed from stage. This class should be extended.<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> EventManagedSprite <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> eventsList:<span style="color: #808080; font-style: italic;">/*Array*/</span>Dictionary = <span style="color: #000000; ">new</span> Dictionary<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> EventManagedSprite<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; <span style="color: #0066CC;">super</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">REMOVED_FROM_STAGE</span>, onRemoveEventManagedSprite<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> onRemoveEventManagedSprite<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; <span style="color: #0066CC;">super</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">REMOVED_FROM_STAGE</span>, onRemoveEventManagedSprite<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; ">var</span> <span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> eventsList<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: #000000; ">var</span> events:<span style="color: #0066CC;">Array</span> = eventsList<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#93;</span> as <span style="color: #0066CC;">Array</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; ">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i &lt; events.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> eventObject:EventObject = events<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">type</span>, eventObject.<span style="color: #006600;">listener</span>, eventObject.<span style="color: #006600;">useCapture</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//trace(&quot;Auto removed listener &quot;, type, eventObject.listener, &quot;from&quot;, this);</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eventObject.<span style="color: #006600;">listener</span> = <span style="color: #000000; ">null</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eventObject = <span style="color: #000000; ">null</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>events.<span style="color: #0066CC;">length</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">delete</span> eventsList<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#93;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</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; override <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> addEventListener<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, listener:<span style="color: #000000; ">Function</span>, useCapture:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; ">false</span>, priority:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>, useWeakReference:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; ">false</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;">super</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, listener, useCapture, priority, useWeakReference<span style="color: #66cc66;">&#41;</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>!eventsList<span style="color: #66cc66;">&#91;</span> <span style="color: #0066CC;">type</span> <span style="color: #66cc66;">&#93;</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; eventsList<span style="color: #66cc66;">&#91;</span> <span style="color: #0066CC;">type</span> <span style="color: #66cc66;">&#93;</span> = <span style="color: #66cc66;">&#91;</span> <span style="color: #000000; ">new</span> EventObject<span style="color: #66cc66;">&#40;</span> listener, useCapture <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#93;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eventsList<span style="color: #66cc66;">&#91;</span> <span style="color: #0066CC;">type</span> <span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; ">new</span> EventObject<span style="color: #66cc66;">&#40;</span> listener, useCapture <span style="color: #66cc66;">&#41;</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></p><p>final internal <span style="color: #000000; ">class</span> EventObject<br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">var</span> listener:<span style="color: #000000; ">Function</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">var</span> useCapture:<span style="color: #0066CC;">Boolean</span><br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> final <span style="color: #000000; ">function</span> EventObject <span style="color: #66cc66;">&#40;</span> listener:<span style="color: #000000; ">Function</span>, useCapture:<span style="color: #0066CC;">Boolean</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">listener</span> = listener;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">useCapture</span> = useCapture;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span></div><p>Make sure every class you add listeners extends this class to make the most out of it. Otherwise you just need to remove the listeners yourself. Let me know what you think about it.</p><p>Disclaimer: This class does not detect the eventlisteners on the children of the class. These children should extend the EventManagedSprite class too, otherwise you should remove it manually.</p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=991&amp;md5=b7031677e27933368da6d52257caeb76" 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/09/remove-eventlisteners-in-as3/feed/</wfw:commentRss> <slash:comments>11</slash:comments> </item> <item><title>FindClosest</title><link>http://blog.stroep.nl/2010/03/findclosest/</link> <comments>http://blog.stroep.nl/2010/03/findclosest/#comments</comments> <pubDate>Sun, 14 Mar 2010 19:08:03 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[experiment]]></category> <category><![CDATA[flash]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=934</guid> <description><![CDATA[<img alt="findClosest" src="http://farm3.static.flickr.com/2577/4424864751_ccdbbc0ee4_m.jpg" class="alignleft" width="100" height="100" />Who follows me on twitter already noticed I've created a little app inspired by <a href="http://www.zefrank.com/scribbler/">scribbler</a> from <a href="http://www.zefrank.com">zefrank</a>. I also found another cool version of Mario Klingemann aka Quasimondo called <a href="http://www.zefrank.com/scribbler/new_about/scribtoo.jpg">scribblerToo</a>. But the one where it all started is the javascript version of <a href="http://mrdoob.com/blog">Mr.Doob</a>. I wanted to try this in flash, and called it findClosest. It's not such great as the other versions, but I really think there are some interesting things in here.]]></description> <content:encoded><![CDATA[<p><img alt="findClosest" src="http://farm3.static.flickr.com/2577/4424864751_ccdbbc0ee4_m.jpg" class="alignleft" width="100" height="100" />Who follows me on twitter already noticed I&#8217;ve created a little app inspired by <a href="http://www.zefrank.com/scribbler/">scribbler</a> from <a href="http://www.zefrank.com">zefrank</a>. I also found another cool version of Mario Klingemann aka Quasimondo called <a href="http://www.zefrank.com/scribbler/new_about/scribtoo.jpg">scribblerToo</a>. But the one where it all started is the javascript version of <a href="http://mrdoob.com/blog">Mr.Doob</a>. I wanted to try this in flash, and called it findClosest. It&#8217;s not as great as the other versions, but I really think there are some interesting things in here.</p><p><strong>See it in action</strong><br /> &raquo; <a href="http://projects.stroep.nl/findClosest/">FindClosest</a></p><p>The trick in this little application is to store each mouse position, locate the mouse position and find the closest points around it (from the stored data) and draw some lines between those points. Well that code isn&#8217;t very exiting, because most people know how to find the distance between 2 points, and basically there are 2 ways find this:<div class="bbCSH" style="font-family: monospace;"><span style="color: #808080; font-style: italic;">// option 1: Using the build-in function</span><br /> <span style="color: #000000; ">var</span> distance:<span style="color: #0066CC;">Number</span> = Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span> point1, point2 <span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// option 2: Using Math</span><br /> <span style="color: #000000; ">var</span> distance:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sqrt</span><span style="color: #66cc66;">&#40;</span> point1.<span style="color: #006600;">x</span> * point2.<span style="color: #006600;">x</span> + point1.<span style="color: #006600;">y</span> * point2.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&#41;</span>;</div><p>The results are amazing and I love the fact that even if you can&#8217;t draw, it looks really cool <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><h2>Store lines as small as you can</h2><p>I was already trying to find a way to store lines in a format I can reuse for my artworks. Most artworks are random but I am looking for a way to have more control. The first step would be the ability to control the (what I call) movements. So in this little experiment I&#8217;ve tried to find a way to store the lines into a compact file, which can be redrawed by the app. I&#8217;m really exited about this. So I&#8217;ve started to save as a plain-text file writing something like this:<br /><blockquote>{x:100,y:300},{x:110,y:340},{x:125,y:350},{x:125,y:350}</p></blockquote><p>It&#8217;s readable code, and easy to These are 56 chars for 4 points. So I tried to make it more smaller using this:<br /><blockquote>{100,300},{110,340},{125,350},{125,350}</p></blockquote><p>I&#8217;ve removed the x and y from the file, because I know that it&#8217;s always a pair of x and y values. Alright.. now I have 40 chars which represents 4 points, so that saves me 16 chars. Can this be done more smaller?<br /><blockquote>100,300,110,340,125,350,125,350</p></blockquote><p>Yes, sometimes basic is the best. I removed the brackets. I know the odds are the x values, and the evens are the y values. It&#8217;s always x,y,x,y,x,y,x,y etc. So now I have 32 chars to store 4 points.</p><p>The application doesn&#8217;t know where I start pressing and releasing the mousebuttons. I have to know this, otherwise all my lines are just 1 big line instead of multiple lines. When pressing the mouse, I want to start with an <em>graphics.moveTo</em> function.</p><p>So what I did is this:<br /><blockquote>100,300,110,340,125,350,125,350&#038;m=0,2</p></blockquote><p>&#038;m=0,2 means I have released the mouse on point 0 and point 2. A point referrers to the x and y position.</p><p>I think this is almost the smallest I can get. It&#8217;s easily to revert these values back to usable values using <em>String.split()</em>.</p><p>But.. In real life there aren&#8217;t ints, but Numbers. The values mostly looks like 452.12070158. I stripped the value, and only use decimals. You don&#8217;t actually see the difference when redrawing between 10.04 and 10.042. This saves me a lot of chars too.</p><p><strong>Compress it!</strong><br /> When saving the file, I push the data into a ByteArray using the <em>bytes.writeUTFBytes()</em> function. I realized ByteArrays can be compressed, so I also use the <em>bytes.compress();</em> to make the file smaller again. This saves me about 50%! When importing the lines, I used <em>bytes.uncompress();</em> to make it a normal string again.</p><p>This flower is 14kb <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Import <a href="http://projects.stroep.nl/findClosest/flower2.stroep">this file</a> in the app to see how I haved drawed it. You can also load it from an url: http://projects.stroep.nl/findClosest/flower2.stroep<br /> <a href="http://projects.stroep.nl/findClosest/"><img src="http://farm3.static.flickr.com/2703/4424864601_44764eb538.jpg" width="500" height="375" alt="flower" /></a><br /> <a href="http://www.flickr.com/photos/markknol/4424864601/" title="flower by mark knol, on Flickr">flower  on Flickr</a></p><p>Well this is a next step and I hope to create one day an editor for simple lines and merge this into my artwork process. I think it needs to be more complex but for now this will work. I hope you like it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2010/03/findclosest/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>Game &#8211; block.game</title><link>http://blog.stroep.nl/2009/07/block-game/</link> <comments>http://blog.stroep.nl/2009/07/block-game/#comments</comments> <pubDate>Fri, 31 Jul 2009 06:30:03 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Games]]></category> <category><![CDATA[braindump]]></category> <category><![CDATA[flash]]></category> <category><![CDATA[game]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=674</guid> <description><![CDATA[<img class="alignleft size-full wp-image-675" title="block-game" src="http://blog.stroep.nl/wp-content/block-game-small.jpg" alt="" width="100" height="100" /> AS3 puzzle block game. Just for fun I created this puzzle-game. It is not very innovative, but it's cool (and hard) to explore how to build this kind of game.  Don’t know the exact name for this game, so I called it block.game.Read more to find out how I created the game.]]></description> <content:encoded><![CDATA[<p><a title="block.game" href="http://games.stroep.nl/block-game"><img src="http://farm4.static.flickr.com/3537/3772846005_0bc1af831b_o.jpg" alt="block.game" width="593" /></a></p><h2>Introduction</h2><p>AS3 puzzle block game. Just for fun I created this puzzle-game. It is not very innovative, but it&#8217;s cool (and a little bit hard) to explore how to build this kind of game.  Don’t know the exact name for this game, so I called it block.game <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><h2>How to play</h2><p>Click on groups of the same color. The bigger group, the more score. You get a message when no moves can be done, or when the board is empty.</p><h2>How I created it &#8211; braindump</h2><p>I&#8217;ve learned you need to think twice before starting coding. This game had some really challenges in it.</p><p><strong>Challenge 1:</strong><br /> I know what you are thinking; the map is just an array. Well; that&#8217;s true. A challenge while creating the game was to find out what a left or right side in the game was. My array doesn&#8217;t know what rows are, because I choose to not use a multidimensional one. So I created a way to calculate what a row was. I used modulo for this. Take a look at this code to see how easy the problem could be fixed. It just took me a long time to get to this point, I guess. <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><div class="bbCSH" style="font-family: monospace;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">index</span> % mapWidth == <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// left side of board }</span><br /> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">index</span> % mapWidth == mapWidth <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// right side of board }</span><br /> &nbsp;</div><p>Conclusion: Modulo makes live easy. We need to use it more.</p><p><strong>Challenge 2:</strong><br /> How to find all blocks around the active block? It loops around the active block to see if they had the same type (=color). If not; stop looping. If it does; repeat function from that point again with exception below the imaginary boundaries created in challenge 1. Well, this is a typical example to use recursive loops; I used it for this. Recursive programming is a bit hard to understand if you don&#8217;t work a lot with them. My conclusion: Learning recursive function is cool.</p><p><strong>Challenge 3: </strong><br /> When you clear a column, the column should move to the left, right? I thought that would be very easy; just move all columns after the newest empty column just one position to the left and that&#8217;s it.<br /> But it wasn&#8217;t that easy. I needed to loop through all the columns after the empty one, and push it them the left. But.. At the right side of the board there are empty columns too (if you clicked a empty row before). So Flash was thinking; Cool I&#8217;ve found some empty rows at the right side of the board. Yeah; put more to the left. <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> But there wasn&#8217;t more, because the column before the last empty column at the right side is the last one (you still get me?). Flash was recursively looping and after 15 seconds he gave up.. an infinite never ending loop. Conclusion; I needed to calculate the last not-empty-column first. Then find the empty columns between the first empty column in the middle of the board and the calculated not-empty-column. If found it; move that columns one position to the left.</p><p>I hope you like the game. I haven&#8217;t implemented a highscore (yet).</p><p>Code will be available soon on flashden.</p><p>Play @ <strong><a href="http://games.stroep.nl/">games.stroep.nl</a></strong><br /> Buy source @ <strong><a href="http://activeden.net/item/blockgame/51930?ref=mknol">flashden.net</a></strong></p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=674&amp;md5=2e7b0b0035abb5ac7bf7239a2d588920" 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/07/block-game/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Generative art &#8211; wild.colorcurves</title><link>http://blog.stroep.nl/2009/01/generative-wildcolorcurves/</link> <comments>http://blog.stroep.nl/2009/01/generative-wildcolorcurves/#comments</comments> <pubDate>Mon, 26 Jan 2009 10:21:25 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Generative art]]></category> <category><![CDATA[actionscript]]></category> <category><![CDATA[curves]]></category> <category><![CDATA[flash]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=290</guid> <description><![CDATA[Feeling creative; created a new serie with wild but odd colors. It has a happy abstract smoke-like feeling. It is hard to create good ribbons, but now I have find out a new way I kinda like. When I was experimenting with my 'curved series' (previous post), I already had the engine. But in this serie I left the borders, left the fade and added better movement and connection between the lines. It's getting better every time. The curves and movements are based on a perlin noise. It took a lot of time till I get these four. The engine was right, but I have to deal with randomness. Mostly it doesn't work and sometimes it does and now I have this:<a title="wild.colorcurve.03 by mark knol, on Flickr" href="http://www.flickr.com/photos/markknol/3226843168/"><img src="http://farm4.static.flickr.com/3125/3226843168_b018d0ee10.jpg" alt="wild.colorcurve.03"  /></a> <a title="wild.colorcurve.02 by mark knol, on Flickr" href="http://www.flickr.com/photos/markknol/3226843682/"><img src="http://farm4.static.flickr.com/3098/3226843682_91902d8e75_m.jpg" alt="wild.colorcurve.02"  /></a> <a title="wild.colorcurve.01 by mark knol, on Flickr" href="http://www.flickr.com/photos/markknol/3226842822/"><img src="http://farm4.static.flickr.com/3465/3226842822_e2087b165d_m.jpg" alt="wild.colorcurve.01" /></a> <a title="wild.colorcurve.04 by mark knol, on Flickr" href="http://www.flickr.com/photos/markknol/3226843384/"><img src="http://farm4.static.flickr.com/3443/3226843384_6b04ba1ef4.jpg" alt="wild.colorcurve.04"  /></a>I've created this one at 6000 x 6000 px. What do you think of it? If you are interested to buy one, please contact me info[at]stroep.nl.]]></description> <content:encoded><![CDATA[<p>Feeling creative; created a new serie with wild but odd colors. It has a happy abstract smoke-like feeling. It is hard to create good ribbons, but now I have find out a new way I kinda like. When I was experimenting with my &#8216;curved series&#8217; (previous post), I already had the engine. But in this serie I left the borders, left the fade and added better movement and connection between the lines. It&#8217;s getting better every time. The curves and movements are based on a perlin noise. It took a lot of time till I get these four. The engine was right, but I have to deal with randomness. Mostly it doesn&#8217;t work and sometimes it does and now I have this:</p><p><a title="wild.colorcurve.03 by mark knol, on Flickr" href="http://www.flickr.com/photos/markknol/3226843168/"><img src="http://farm4.static.flickr.com/3125/3226843168_b018d0ee10.jpg" alt="wild.colorcurve.03"  /></a><br /> <a title="wild.colorcurve.02 by mark knol, on Flickr" href="http://www.flickr.com/photos/markknol/3226843682/"><img src="http://farm4.static.flickr.com/3098/3226843682_91902d8e75_m.jpg" alt="wild.colorcurve.02"  /></a> <a title="wild.colorcurve.01 by mark knol, on Flickr" href="http://www.flickr.com/photos/markknol/3226842822/"><img src="http://farm4.static.flickr.com/3465/3226842822_e2087b165d_m.jpg" alt="wild.colorcurve.01"  /></a><br /> <a title="wild.colorcurve.04 by mark knol, on Flickr" href="http://www.flickr.com/photos/markknol/3226843384/"><img src="http://farm4.static.flickr.com/3443/3226843384_6b04ba1ef4.jpg" alt="wild.colorcurve.04"  /></a></p><p>I&#8217;ve created this one at 6000 x 6000 px. What do you think of it? if you are interested in buying one, please contact me info[at]stroep.nl.</p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/01/generative-wildcolorcurves/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Generative curved series</title><link>http://blog.stroep.nl/2009/01/generative-curved-series/</link> <comments>http://blog.stroep.nl/2009/01/generative-curved-series/#comments</comments> <pubDate>Sun, 25 Jan 2009 23:05:22 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Generative art]]></category> <category><![CDATA[actionscript]]></category> <category><![CDATA[flash]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=285</guid> <description><![CDATA[New experiments with movements, curves, lines and perlin noise. Most movements are created using this function (this is pseudo code)sprite.point1.x += ( -128 + noiseColor.green) / 5;
sprite.point1.y += ( -128 + noiseColor.blue) / 5;noiseColor is the colorvalue of getPixel() from the perlin noise.<a href="http://www.flickr.com/photos/markknol/3184198235/" title="ribbon.curve-09 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3128/3184198235_94e4ca5ce8.jpg" width="500" height="320" alt="ribbon.curve-09" /></a><a href="http://www.flickr.com/photos/markknol/3191823030/" title="ribbon.leaf-06 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3535/3191823030_4e5635dd14_m.jpg" width="210"  alt="ribbon.leaf-06" /></a> <a href="http://www.flickr.com/photos/markknol/3190973677/" title="ribbon.leaf-02 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3474/3190973677_b64daca417_m.jpg" width="210" alt="ribbon.leaf-02" /></a> <a href="http://www.flickr.com/photos/markknol/3191823296/" title="ribbon.leaf-07 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3075/3191823296_06c24b0e09_m.jpg" width="210"  alt="ribbon.leaf-07" /></a> <a href="http://www.flickr.com/photos/markknol/3184198327/" title="ribbon.curve-10 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3444/3184198327_1ffe175a01_m.jpg" width="210" alt="ribbon.curve-10" /></a>Some curves with gradient fills and 2 different stroke sizes. I found in the Matrix-class a createGradientBox() function, witch actually is a very cool and handy function. The colors are based on photos with cool colors, this gives a nice natural look.<a href="http://www.flickr.com/photos/markknol/3219309140/" title="curves-354247508 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3098/3219309140_76358fb486_m.jpg" width="210"  alt="curves-354247508" /></a> <a href="http://www.flickr.com/photos/markknol/3218458371/" title="curves-90797965 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3083/3218458371_afc2f90d25_m.jpg" width="210" alt="curves-90797965" /></a> <a href="http://www.flickr.com/photos/markknol/3219308776/" title="curves-120014133 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3506/3219308776_aa3ca8203b.jpg" width="500" height="400" alt="curves-120014133" /></a>]]></description> <content:encoded><![CDATA[<p>New experiments with movements, curves, lines and perlin noise. Most movements are created using this function (this is pseudo code)<div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">sprite</span>.<span style="color: #006600;">point1</span>.<span style="color: #006600;">x</span> += <span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">-128</span> + noiseColor.<span style="color: #006600;">green</span><span style="color: #66cc66;">&#41;</span> / <span style="color: #cc66cc;">5</span>;<br /> <span style="color: #0066CC;">sprite</span>.<span style="color: #006600;">point1</span>.<span style="color: #006600;">y</span> += <span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">-128</span> + noiseColor.<span style="color: #006600;">blue</span><span style="color: #66cc66;">&#41;</span> / <span style="color: #cc66cc;">5</span>;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp;</div><p>noiseColor is the colorvalue of getPixel() from the perlin noise.</p><p><a href="http://www.flickr.com/photos/markknol/3184198235/" title="ribbon.curve-09 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3128/3184198235_94e4ca5ce8.jpg" width="500" height="320" alt="ribbon.curve-09" /></a></p><p><a href="http://www.flickr.com/photos/markknol/3191823030/" title="ribbon.leaf-06 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3535/3191823030_4e5635dd14_m.jpg" width="210"  alt="ribbon.leaf-06" /></a> <a href="http://www.flickr.com/photos/markknol/3190973677/" title="ribbon.leaf-02 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3474/3190973677_b64daca417_m.jpg" width="210" alt="ribbon.leaf-02" /></a><br /> <a href="http://www.flickr.com/photos/markknol/3191823296/" title="ribbon.leaf-07 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3075/3191823296_06c24b0e09_m.jpg" width="210"  alt="ribbon.leaf-07" /></a> <a href="http://www.flickr.com/photos/markknol/3184198327/" title="ribbon.curve-10 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3444/3184198327_1ffe175a01_m.jpg" width="210" alt="ribbon.curve-10" /></a></p><p>Some curves with gradient fills and 2 different stroke sizes. I found in the Matrix-class a createGradientBox() function, witch actually is a very cool and handy function. The colors are based on photos with cool colors, this gives a nice natural look.</p><p><a href="http://www.flickr.com/photos/markknol/3219309140/" title="curves-354247508 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3098/3219309140_76358fb486_m.jpg" width="210"  alt="curves-354247508" /></a> <a href="http://www.flickr.com/photos/markknol/3218458371/" title="curves-90797965 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3083/3218458371_afc2f90d25_m.jpg" width="210" alt="curves-90797965" /></a><br /> <a href="http://www.flickr.com/photos/markknol/3219308776/" title="curves-120014133 by mark knol, on Flickr"><img src="http://farm4.static.flickr.com/3506/3219308776_aa3ca8203b.jpg" width="500" height="400" alt="curves-120014133" /></a></p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/01/generative-curved-series/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
