<?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; actionscript</title> <atom:link href="http://blog.stroep.nl/category/actionscript/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, 07 Sep 2010 07:08:59 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>Quick way to create an auto-increment index AS3</title><link>http://blog.stroep.nl/2010/08/auto-increment-as3-class/</link> <comments>http://blog.stroep.nl/2010/08/auto-increment-as3-class/#comments</comments> <pubDate>Sun, 22 Aug 2010 13:39:16 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Code snippets]]></category> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[class]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=977</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/snippet.jpg" alt="" title="snippet" width="100" height="100" class="alignleft size-full wp-image-588">Quick post here. I'd like to share this very quick way to create an automatic ID or index to your class instances. Mostly I pass an index as parameter to the class instances, or I use a public var to set the index. Using this way it is very easy to create an automatically filled index, since you have to set this up once and never worry again :)]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/snippet.jpg" alt="" title="snippet" width="100" height="100" class="alignleft size-full wp-image-588">Quick post here. I&#8217;d like to share this very quick way to create an automatic ID or index to your class instances. Mostly I pass an index as parameter to the class instance, or I use a public var to set the index. Using this way it is very easy to create an automatically filled index, since you have to set this up once and never worry again <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Take a look at this code:</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">package</span><br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">class</span> MyObject<br /> &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; ">var</span> global_index:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;<br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> const <span style="color: #0066CC;">INDEX</span>:<span style="color: #0066CC;">int</span> = global_index ++;<br /> &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>As you see, I have created a static variable global_index, which is always the same to all MyObject classes. I also created a public constant &#8216;INDEX&#8217;, which would be unique in every instance. When the MyObject instance is created the index will be set to the global_index, and the global_index will increase by one. So that&#8217;s basically the trick to create the auto-increment index for your AS3 class.</p><div class="bbCSH" style="font-family: monospace;">update: Changed global_index to a private static + removed constructor</div> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2010/08/auto-increment-as3-class/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Multiple keys made easy with Dictionary</title><link>http://blog.stroep.nl/2010/07/multiple-keys-made-easy-with-dictionary/</link> <comments>http://blog.stroep.nl/2010/07/multiple-keys-made-easy-with-dictionary/#comments</comments> <pubDate>Sun, 11 Jul 2010 11:18:45 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Code snippets]]></category> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[game]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=964</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/behind.jpg" alt="Multiple keys made easy with Dictionary" width="100" height="100" class="alignleft size-full wp-image-586">Quick post here, a simple solution I found to have multiple keys enabled. Maybe most real game developers know better or more elegant solutions, but I found this useful enough to share it with you.]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/behind.jpg" alt="Multiple keys made easy with Dictionary" width="100" height="100" class="alignleft size-full wp-image-586">Quick post here, a simple solution I found to have multiple keys enabled. Maybe most real game developers know better or more elegant solutions, but I found this useful enough to share it with you.</p><p>Here we go. Add these variable to your class. This is a Dictionary, which allows you to associate a value with an object key.</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #b1b100;">private</span> <span style="color: #000000; ">var</span> currentKeys:Dictionary = <span style="color: #000000; ">new</span> Dictionary<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp;</div><p>Then, in your constructor or wherever you assign eventListeners, add these (well-known) listeners, with the callback functions:</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">KeyboardEvent</span>;</p><p><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_DOWN</span>, <span style="color: #0066CC;">onKeyDown</span><span style="color: #66cc66;">&#41;</span>;<br /> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_UP</span>, <span style="color: #0066CC;">onKeyUp</span><span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">onKeyDown</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; currentKeys<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #000000; ">true</span>;<br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> <span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">onKeyUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; currentKeys<span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #000000; ">false</span>;<br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>Inside your enterframe-event or timer (were you want to detect which keys are pressed), you could these kind of detection.</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">ui</span>.<span style="color: #006600;">Keyboard</span>;<br /> <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;</p><p><span style="color: #b1b100;">private</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">onUpdate</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> currentKeys<span style="color: #66cc66;">&#91;</span> Keyboard.<span style="color: #0066CC;">SPACE</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; tank.<span style="color: #006600;">shoot</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> currentKeys<span style="color: #66cc66;">&#91;</span> Keyboard.<span style="color: #0066CC;">RIGHT</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; tank.<span style="color: #006600;">targetDirection</span> -= <span style="color: #cc66cc;">0.1</span>;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp;<br /> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> currentKeys<span style="color: #66cc66;">&#91;</span> Keyboard.<span style="color: #0066CC;">LEFT</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; tank.<span style="color: #006600;">targetDirection</span> += <span style="color: #cc66cc;">0.1</span>;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp;<br /> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> currentKeys<span style="color: #66cc66;">&#91;</span> Keyboard.<span style="color: #0066CC;">UP</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; tank.<span style="color: #006600;">speed</span> += tank.<span style="color: #006600;">acceleration</span>;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp;<br /> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> currentKeys<span style="color: #66cc66;">&#91;</span> Keyboard.<span style="color: #0066CC;">DOWN</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; tank.<span style="color: #006600;">speed</span> /= <span style="color: #cc66cc;">1.8</span>;<br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>I found that if you use some 3 or 4+ combinations of keys at the same time, the keyboard events are not triggered anymore, which is a bit of annoying bug in the FlashPlayer. I mean pressing forward and left and shooting at the same time could be a problem? Well; Hope this helps, I think its very easy and a great usage of the Dictionary.</p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2010/07/multiple-keys-made-easy-with-dictionary/feed/</wfw:commentRss> <slash:comments>3</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>6</slash:comments> </item> <item><title>Particle test center</title><link>http://blog.stroep.nl/2009/12/particle-test-center/</link> <comments>http://blog.stroep.nl/2009/12/particle-test-center/#comments</comments> <pubDate>Tue, 29 Dec 2009 00:05:26 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=842</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/particlecenter.jpg" alt="" title="particle center" width="100" height="100" class="alignleft size-full wp-image-844" />For a while now, I am experimenting with this new experiment. I created an algorithm with nested sinus/cosinus, to show of some cool 3d looking particles (no there is no 3d in it). It is amazing to see how many particles flash can move. I used components from bit-101 to have some interaction.<strong>Check:</strong> <a href="http://projects.stroep.nl/particles/">http://projects.stroep.nl/particles/</a>]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/particlecenter.jpg" alt="" title="particle center" width="100" height="100" class="alignleft size-full wp-image-844" />For a while now, I am experimenting with this new experiment. I created an algorithm with nested sinus/cosinus, to show of some cool 3d looking particles (no there is no 3d in it). It is amazing to see how many particles flash can move. I used components from bit-101 to have some interaction.</p><p><strong>Check:</strong> <a href="http://projects.stroep.nl/particles/">http://projects.stroep.nl/particles/</a></p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/12/particle-test-center/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Chain: Delayed function calling [updated]</title><link>http://blog.stroep.nl/2009/11/delayed-function-calling-chain/</link> <comments>http://blog.stroep.nl/2009/11/delayed-function-calling-chain/#comments</comments> <pubDate>Sat, 14 Nov 2009 12:00:36 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Code snippets]]></category> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[chain]]></category> <category><![CDATA[class]]></category> <category><![CDATA[googlecode]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=824</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/chain.jpg" alt="Chain" title="Chain" width="100" height="100" class="alignleft size-full wp-image-832" />I created a useful util-class to make delayed function calling easy. You can make a chain of functions, by adding them with a delay in milliseconds. This chain can be executed multiple times, even in reversed order. ]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/chain.jpg" alt="Chain" title="Chain" width="100" height="100" class="alignleft size-full wp-image-832" />I created a useful util-class to make delayed function calling easy. You can make a chain of functions, by adding them with a delay in milliseconds. This chain can be executed multiple times, even in reversed order.</p><p>Let&#8217;s take a look at a simple example of Chain.<br clear="both"/><div class="bbCSH" style="font-family: monospace;"><span style="color: #000000; ">var</span> myChain:Chain = <span style="color: #000000; ">new</span> Chain<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; <br /> myChain.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">COMPLETE</span>, onComplete<span style="color: #66cc66;">&#41;</span>;<br /> myChain.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>one, <span style="color: #cc66cc;">2000</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>two, <span style="color: #cc66cc;">500</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>three, <span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #000000; ">function</span> one<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;one&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #000000; ">function</span> two<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;two&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #000000; ">function</span> three<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;three&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #000000; ">function</span> onComplete<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> <span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;done.&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span></p><p><span style="color: #808080; font-style: italic;">/* trace output:<br /> one two three one two three done.<br /> */</span><br /> &nbsp;</div><p>What is happening here? At the first line we are instantiating the class, and the second line represents what chain does. There is a public function called &#8216;add&#8217;, which is an important part of the class. <em>add(one, 2000)</em> means: execute a function called &#8216;one&#8217; after 2000 milliseconds. <em>add(two,500).add(three,1000)</em> are functions that are called after one is finished, with other delays. You can create your own rhythm/sequence/pattern. At the end we see <em>play(2)</em>, which means: Execute the sequence of functions defined before, and repeat them 2 times. After that, dispatch event COMPLETE.</p><p>So that&#8217;s basically it. A cool part is you can play it reversed, using <em>playReversed()</em>. I am inspired by jQuery (which has nothing to do with this) to enable the ability to stick functions, but thats optional.</p><div class="bbCSH" style="font-family: monospace;"> myChain.<span style="color: #006600;">playReversed</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">/* trace output:<br /> three two one three two one<br /> */</span><br /> &nbsp;</div><p>Of course you can pauze/continue when you are playing, by calling <em>stop() / doContinue()</em>, and you can determine if it is currently playing using the <em>isPlaying</em>-getter.</p><p>These are all the public functions.</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #808080; font-style: italic;">/// Constructor</span><br /> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> Chain<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></p><p><span style="color: #808080; font-style: italic;">/// Adds a function at a specified interval (in milliseconds).</span><br /> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>func:<span style="color: #000000; ">Function</span>, delay:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>:Chain</p><p><span style="color: #808080; font-style: italic;">/// Start playing the sequence and calling functions</span><br /> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span>repeatCount:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></p><p><span style="color: #808080; font-style: italic;">/// Start playing the sequence reversed</span><br /> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> playReversed<span style="color: #66cc66;">&#40;</span>repeatCount:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></p><p><span style="color: #808080; font-style: italic;">/// Clears sequence list. Data will be removed.</span><br /> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Chain</p><p><span style="color: #808080; font-style: italic;">/// Stop playing, use doContinue to play futher from current point</span><br /> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></p><p><span style="color: #808080; font-style: italic;">/// Continue playing after a stop</span><br /> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> doContinue<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Chain</p><p><span style="color: #808080; font-style: italic;">/// Reset indexes</span><br /> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> reset<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></p><p><span style="color: #808080; font-style: italic;">/// Returns the string representation of the Chain private vars.</span><br /> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span></p><p><span style="color: #808080; font-style: italic;">/// Return chain is playing, stopped or completed</span><br /> <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> <span style="color: #0066CC;">get</span> isPlaying<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span><br /> &nbsp;</div><p>Hope you like it, let me know if you like to see extra/other related features.</p><p><strong>Download: <a href="http://code.google.com/p/stroep/source/browse/#svn/trunk/nl/stroep/chain">Chain</a></strong> (googlecode)</p><p><strong>Updates</strong><br /> - Private functions are protected<br /> - <em>add</em>-functions is now add(function, delay), where function is required.<br /> - Class now extends EventDispatcher and <em>play/playReversed</em> dispatches <em>Event.COMPLETE</em> after playing sequence, instead of calling onComplete function<br /> - Cleaned up code</p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/11/delayed-function-calling-chain/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Update Image class &#8211; added contextMenu</title><link>http://blog.stroep.nl/2009/11/add-contextmenu-to-images/</link> <comments>http://blog.stroep.nl/2009/11/add-contextmenu-to-images/#comments</comments> <pubDate>Fri, 06 Nov 2009 17:35:13 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[code]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=812</guid> <description><![CDATA[<img src="/wp-content/uploads/image-contextmenu.jpg" alt="" class="alignleft" />I've updated my <a href="http://blog.stroep.nl/2009/06/nlstroeputilsimage/">Image class</a>. It is irritating flashsites break the right-click contextmenu. Well, I can't fix that and Adobe should look at that, but I think it would nice to add some of the browser - features to my image class. ]]></description> <content:encoded><![CDATA[<p><img src="/wp-content/uploads/image-contextmenu.jpg" alt="" class="alignleft" />I&#8217;ve updated my <a href="http://blog.stroep.nl/2009/06/nlstroeputilsimage/">Image class</a>. It is irritating flashsites break the right-click contextmenu. Well, I can&#8217;t fix that and Adobe should look at that, but I think it would nice to add some of the browser &#8211; features to my image class.</p><p>Currently I have these options added to the Image class:</p><blockquote><p> <strong>View image</strong><br /> Views image in new window/tab. I used NavigateToURL to make this happen.</p><p><strong>Save Image as..</strong><br /> Saves image on your computer. I used my ImageClass.saveLocal() to make this happen. This is only available within FP10, but I think this is no problem anymore because < a href = "http://www.adobe.com/products/player_census/flashplayer/version_penetration.html" > 93 %</a> (September 2009) has FlashPlayer 10, so most people have it, and I don&#8217;t support outdated software <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p><strong>Copy Image location</strong><br /> Copies the url to the clipboard, using System.setClipboard(url). It&#8217;s a pity I can&#8217;t create a &#8216;Copy Image&#8217; function, because pushing bitmapdata into the clipboard is only supported in AIR.</p><p><strong>Send Image</strong><br /> Sends the url to the mail-client, using &#8220;mailto:&#038;body=&#8221; + src. Also a pity; I can&#8217;t add the image directly into the mail.</p></blockquote><p><strong>How to enable the contextmenu:</strong></p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">import</span> nl.<span style="color: #006600;">stroep</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Image</span>;</p><p><span style="color: #000000; ">var</span> myImage:Image = <span style="color: #000000; ">new</span> Image<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myImage.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;<br /> myImage.<span style="color: #006600;">enableContextMenu</span> = <span style="color: #000000; ">true</span>; <span style="color: #808080; font-style: italic;">// enable it!</span><br /> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>myImage<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp;</div><p> I still love this class, I use it a lot. I want to encourage you to please add these kind of usability things to your apps / websites. And share them! Yes, it takes some extra time to create/add it, because this IS the finishing touch, but a lot of people will like this kind of features.</p><p><strong>Download</strong><br /> Check out the <a href="http://code.google.com/p/stroep/source/browse/trunk/nl/stroep/utils/Image.as">Image class</a> at<a href="http://code.google.com/p/stroep">googlecode</a></p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/11/add-contextmenu-to-images/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>getBounds for TextFields = getBitmapBounds()</title><link>http://blog.stroep.nl/2009/11/getbitmapbounds/</link> <comments>http://blog.stroep.nl/2009/11/getbitmapbounds/#comments</comments> <pubDate>Thu, 05 Nov 2009 18:05:32 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Code snippets]]></category> <category><![CDATA[actionscript]]></category> <category><![CDATA[bitmapdata]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=799</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/snippet.jpg" alt="Code snippet" align="left" class="alignleft size-full wp-image-588" />I found out the getBounds()-function gives not exactly the right rectangle with a TextField. It always matches the border bounds, even if the borders are invisible. So i've created a more accurate function using getColorBoundsRect().]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/snippet.jpg" alt="Code snippet" align="left" class="alignleft size-full wp-image-588" />I found out the getBounds()-function gives not exactly the right rectangle with a TextField. It always matches the border bounds, even if the borders are invisible. So I&#8217;ve created a more accurate function using getColorBoundsRect().</p><p>Click on the words. Switch between getRect() and getTextFieldBounds() by clicking on the buttons below to see the difference.</p><p><object type="application/x-shockwave-flash" data="http://projects.stroep.nl/getBitmapBounds/GetBitmapBounds.swf" width="550" height="140"><param name="movie" value="http://projects.stroep.nl/getBitmapBounds/GetBitmapBounds.swf" /></object></p><p>» <a href="http://projects.stroep.nl/getBitmapBounds/GetBitmapBounds.zip"><b>Download source</b></a></p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/11/getbitmapbounds/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Liquid menu: Better proportions with Math.sqrt</title><link>http://blog.stroep.nl/2009/09/better-proportions-with-square-root/</link> <comments>http://blog.stroep.nl/2009/09/better-proportions-with-square-root/#comments</comments> <pubDate>Tue, 01 Sep 2009 09:27:56 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[Code snippets]]></category> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[Math]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=740</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/square-root.jpg" alt="Square root" title="Square root" width="100" height="100" class="alignleft size-full wp-image-751" />Found out something useful, which I'd like to share with you. It's about calculating the width of menu-items perfectly.Imaging you are creating a liquid website with a menu. If you want all items to have the same width, you could set the width of each item to totalMenuWidth / items.length. In most cases this will work out. But what is your menu is very small or the items doesn't fit in that fixed width because the text is too long?]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/square-root.jpg" alt="Square root" title="Square root" width="100" height="100" class="alignleft size-full wp-image-751" />Found out something useful, which I&#8217;d like to share with you. It&#8217;s about calculating the width of menu-items perfectly.</p><p>Imaging you are creating a liquid website with a menu. If you want all items to have the same width, you could set the width of each item to totalMenuWidth / items.length. In most cases this will work out. But what is your menu is very small or the items doesn&#8217;t fit in that fixed width because the text is too long?</p><p>Well you could hardcode the width&#8217;s to make your own perfect proportions and spacing, but if your menu is xml-driven and you/someone else adds new menu-items, you have to re-assign the hardcoded widths and you feel unhappy <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Most hardcoded stuff is evil anyway because it is laziness. (I use it a lot <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )</p><p>Well, I&#8217;d like to calculate the perfect scaling menu, so I don&#8217;t have to worry the menu will break. You can use the text-length of the menu-item as input for the width calculation. The more letters, the bigger the menu-item, right? So, If you multiply all menu-text-lengths and divide this to the current text-length, you&#8217;ll get a ratio which can be divided from the total menu width. I like this theory. So we need to do this in 2 steps; first get the ratios and get the total menu-text-lengths (with a loop), then calculate and apply this on each item.<br /> Pseudocode:<br /><blockquote>itemwidth = fullMenuWidth / (totalTextLength / menuitem.text.length)</p></blockquote><p>This works fine, and its actually very cool. Now we have a function which actually use some proportions to create a liquid menu. After a while I realized that the proportions weren&#8217;t really right. If the menu text have odd text-length differences (eg 5 letters vs 25 letters), it looks weird. Larger texts take too much width. I wanted the same proportions kinda like a html-table.</p><p>So the menu-items needs to have better proportions. Bigger text should be a smaller and the smaller text should be bigger. After some searching I &#8216;discovered&#8217; <a href="http://en.wikipedia.org/wiki/Square_root">Square root</a>, a.k.a. <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00001839.html">Math.sqrt()</a> in actionscript. With this function you could &#8216;normalize&#8217; numbers. Bigger numbers are getting smaller, smaller numbers are getting bigger. This was exactly what I needed!</p><p>You can see the result below:</p><p><object type="application/x-shockwave-flash" data="http://projects.stroep.nl/PerfectWidth/PerfectWidth.swf" width="100%" height="235"><param name="movie" value="http://projects.stroep.nl/PerfectWidth/PerfectWidth.swf" /><param name="wmode" value="transparent" /></object></p><p>You can see the differences between the menubars and you&#8217;ll agree to me that the last one is the best <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I think this theory could be applied to a lot more things, like graphs or grids.</p><p>In case anyone is interested in the code; it can be downloaded <a href="http://projects.stroep.nl/PerfectWidth/perfect-width-src.zip">here</a> (AS3).</p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/09/better-proportions-with-square-root/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>