<?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; code</title> <atom:link href="http://blog.stroep.nl/tag/code/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>Optimized loops</title><link>http://blog.stroep.nl/2011/07/optimized-loops-for-actionscript/</link> <comments>http://blog.stroep.nl/2011/07/optimized-loops-for-actionscript/#comments</comments> <pubDate>Sun, 17 Jul 2011 13:33:07 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[code]]></category> <category><![CDATA[optimalisation]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=1225</guid> <description><![CDATA[<img src="http://farm4.static.flickr.com/3430/3757660341_2b4d557f18_t.jpg" alt="Optimized loops" class="alignleft"/>Every one should write code that performs well. Do you use loops in your code? This is a simple trick everyone could apply to his loops. ]]></description> <content:encoded><![CDATA[<p><img src="http://farm4.static.flickr.com/3430/3757660341_2b4d557f18_t.jpg" alt="Optimized loops" class="alignleft"/>Every one should write code that performs well. Do you use loops in your code? This is a simple trick everyone could apply to his loops.</p><h2>How you write a loop</h2><p>Mostly when people are writing loops, it looks like this:</p><div class="bbCSH" style="font-family: monospace;"> <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; <span style="color: #0066CC;">list</span>.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span><br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp;<span style="color: #000000; ">var</span> item:MyItem = <span style="color: #0066CC;">list</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;<br /> &nbsp; &nbsp;item.<span style="color: #006600;">doSomething</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp;item.<span style="color: #006600;">doAnotherThing</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>Now this loops works, but there are some small things that could be improved. If you use lots of loops it should be needed to improve your loops, but I hope this is just nice to know anyway.</p><h2>The optimized version</h2><p>Take a look at the improved loop:</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #000000; ">var</span> item:MyItem;<br /> <span style="color: #000000; ">var</span> total:uint = <span style="color: #0066CC;">list</span>.<span style="color: #0066CC;">length</span>;<br /> <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; ">var</span> i:uint; i &lt; total; i++<span style="color: #66cc66;">&#41;</span><br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp;item = <span style="color: #0066CC;">list</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> as MyItem;<br /> &nbsp; &nbsp;item.<span style="color: #006600;">doSomething</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp;item.<span style="color: #006600;">doAnotherThing</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>What is improved in this loop? If you take a close look in both loops you will see I access the list-item once using <em>list[i]</em>, and assign it to a variable called <em>item</em>. I don&#8217;t what it is, but for me it looks like most people who write javascript always use <em>list[i]</em> instead of creating a <em>var</em> of it, is that right? It is important to know you don&#8217;t need to create the var inside the loop, but create it once outside the loop, and (re-)use it while looping. I forget this most of the times, but it is a good practice to check if all the variables you are using inside a loop. Most of the times variables could be defined outside the loop, which could increase performance big time.</p><p>The second thing is to define a variable called total, which pre-calculates the length of the loop as a local variable. If you don&#8217;t define it, the FlashPlayer checks the length of the Array every time in the loop, now it is like a constant. Note, when you are removing items from the list, you should ajust the <em>total</em>-variable too, since the total does not equal the length of the list anymore ofcourse. <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>Another thing you probably noticed is that I used the &#8216;as&#8217; keyword to give the FlashPlayer a direct hint of the type of variable. This another way of casting, and slightly faster than <em>MyItem(list[i])</em>.<br /><blockquote>Update: Take a look at this great article about the performance of this casting method. <a href="http://jacksondunstan.com/articles/1305" target="_blank">http://jacksondunstan.com/articles/1305</a></p></blockquote><p>Some other small things are to use uints for <em>i</em> and <em>total</em> in loops if you are using positive numbers. Another small thing is that you don&#8217;t have to define <em>i = 0</em>, only when you are using nested loops or re-using the <em>i</em> or <em>j</em> in the same function/scope.</p><p>Want a more freaky way to define the same optimized loop?</p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; ">var</span> i:uint, item:MyItem, total:uint = <span style="color: #0066CC;">list</span>.<span style="color: #0066CC;">length</span>; i &lt; total; i++<span style="color: #66cc66;">&#41;</span><br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp;item = <span style="color: #0066CC;">list</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> as MyItem;<br /> &nbsp; &nbsp;item.<span style="color: #006600;">doSomething</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp;item.<span style="color: #006600;">doAnotherThing</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> <span style="color: #66cc66;">&#125;</span><br /> &nbsp;</div><p>Are you using FlashDevelop? You could <a href="http://projects.stroep.nl/flashdevelop/" title="For loop snippet" target="_blank">this for-loop snippet</a> (scroll down).</p><p>Most of the loop-optimisation tips also applies to javascript.</p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=1225&amp;md5=ba0c22d1d31dead4db61c598af01c3a2" 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/07/optimized-loops-for-actionscript/feed/</wfw:commentRss> <slash:comments>12</slash:comments> </item> <item><title>Web Design Tips for 2011:How to be a Better Flash Developer</title><link>http://blog.stroep.nl/2011/01/tips-to-start-a-flash-project/</link> <comments>http://blog.stroep.nl/2011/01/tips-to-start-a-flash-project/#comments</comments> <pubDate>Sun, 02 Jan 2011 19:31:00 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[code]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=958</guid> <description><![CDATA[<img alt="" src="http://blog.stroep.nl/wp-content/3370961087_3779c4f4e7-150x150.jpg" title="Tips" class="alignleft" width="100" height="100" />I hope 2011 will be a successful year! This post is mostly targeting to developers who like to dive deeper into actionscript and are searching for a another way to start a project. ]]></description> <content:encoded><![CDATA[<p><img alt="" src="http://blog.stroep.nl/wp-content/3370961087_3779c4f4e7-150x150.jpg" title="Tips" class="alignleft" width="100" height="100" /><br /><h3>I hope 2011 will be a successful year!</h3><p>This post is mostly targeting to developers who like to dive deeper into actionscript and are searching for a another way to start a project, and not so much for the newbies to web design or those just starting out in <a href="http://www.onlinewebdesigndegree.com/">online web design</a> degree programs. In my opinion there are missing a lot of these types of posts, so I just share mine. This post is a collection of post I have never posted in 2010. I hope it will trigger more flashdevelopers to share there view on this topic. Disclaimer: There are several ways to start a flashproject, and I don&#8217;t think my examples are the best way, but I hope they challenge you to think about your setup. In case you work in a webteam, it&#8217;s important to work in a way that is understandable and transparent. You should talk to each other what you really need and expect from each others code.</p><h2>Use existing frameworks (?|!)</h2><p>There are companies who use very transparent architecture frameworks like <a href="http://puremvc.org/">PureMVC</a> or <a href="http://www.robotlegs.org/">RobotLegs</a>, others use there own frameworks and build on that. Personally I don&#8217;t use that big frameworks (yet) as architecture base, because I don&#8217;t create that large applications/sites and for now its more overkill than helpful I guess. There are also some helper frameworks like <a href="http://casalib.org/">casalib</a> and <a href="http://code.google.com/p/templelibrary/">templelibrary</a> around, which can provide you a set of (util-)classes and interfaces. This post is not created to discuss if its better or not to use these already accepted frameworks. If it fits your needs and you want to standardize flash coding; just use it; they are great and very helpful. At the other hand some (mostly larger) frameworks are hard to understand and requires some learning curves / basic skills. I am currently working on <a href="http://flashflowfactory.stroep.nl/">flashflowfactory</a>, which is designed to be an easy-to-learn framework, mostly for medium/small websites which needs deeplinking and page transitions; you should check it out. So at the other hand, it is cool to create your own framework and you will learn a lot from it, but there is already lots of good stuff on the internets.</p><h2>Building</h2><p><strong>Get your tools</strong><br /> For most projects I&#8217;d love to use FlashDevelop. It&#8217;s my code editor of choice. I&#8217;m Dutch and this is a free tool, so there is no need to look at other tools <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Download and install it and follow the instructions. Install the <a href="http://www.adobe.com/support/flashplayer/downloads.html">latest debug activeX player</a> and download <a href="http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK">the latest Flex SDK</a>. After you tried FlashDevelop for a while, just donate some money to support the project. Even if your Dutch. Just give back. Oh, and download the <a href="http://www.flashdevelop.org/community/viewtopic.php?t=2993">duplicate plugin</a> and you don&#8217;t want to switch to another tool ever.</p><p><strong>Setup of the site assets</strong><br /> I love to store my assets inside an SWC, which are viewable (with some logic) in Flash IDE too. Mostly I use the Flash IDE to generate an SWC. All my &#8216;views&#8217; like pages, vectorimages, bitmaps, icons and advanced animations are stored inside that SWC. This of course except the assets I want to load from external sources. I don&#8217;t use much code on the timeline, except some play/stop()-commandos, because it stopping an animation cannot be done more clear than on the timeline. I don&#8217;t feel ashamed anymore to say that I sometimes put code on the timeline (think of a preloader, framelabel jumps etc). As long as you keep the project structured, this should never be a problem. All my views (that need to be accessible from code) are linked to external classes. In this way I can get the most out of the Flash IDE too; there are lots of animation- and designthings that cannot be done quickly with code. So don&#8217;t forget the Flash IDE; It&#8217;s a really powerful tool. Don&#8217;t loose your creativity on code only.</p><p><strong>So what is the plan?</strong><br /> It&#8217;s important to plan your website/application. If you want to be serious, at least just make a small plan. In case of a webteam: Make a checklist what should be done, where you are currently working on and what is done. Having a list of todo&#8217;s helps to be more open. In case of a personal project: Most projects fail if you don&#8217;t write things down, because you loose overview and also the interest for your potential killer-app. Just break things down into small peaces.</p><h2>Getting control</h2><p><strong>What do you need to get started?</strong><br /> Some people start creating cool UML diagrams, others just grab some piece of paper. Others start in Photoshop creating the design rightaway, but it would be helpful to create a wireframe in some cases. What the most important thing is, is to be aware of what you are going to create and which classes you need. Don&#8217;t start to think about the features (yet), think plain. What is the essence of this app? What does it needs to do before it &#8216;works&#8217;? What is needed to get to this point, and how would you built it? Think about how to setup a useful way for navigation. You want to use deeplinking? At what point/place should this happen? What kind of events do we need? Are there recurring elements? Which things should be (dynamic) components, what should be fixed/hardcoded? Which creative parts are hard to develop, and which parts should be more creative? Also add to your todo-list the hours you think it would take to build it; you get more awareness of how to deal with time managing.</p><p><strong>Start collecting puzzle pieces</strong><br /> It&#8217;s time to collect things we need. It maybe sounds stupid, but why wouldn&#8217;t you start with collection the global things? These things are important. Think about if you want to use frameworks and which parts you would code yourself. Are you going to use programmatic tweens? You could use a tween engine. Create a basic HTML file, embed the flash already. Create your package-structure. I don&#8217;t know if its is the way, but I love to write down stub- or pseudo code. Create as much empty classes which need to be filled. Keep in mind you need to refactor a lot of times if you start like this, but I don&#8217;t mind. This forces me to keep thinking about the structure, refactoring is a good thing, right?</p><p><strong>Learn from the past; find recurring elements</strong><br /> Now I have created a mini framework for setting up a website with pages. In my professional life I use Flash to create a lot of viral websites. Most of the pages are not the same, every design is different and has it&#8217;s own &#8216;thing&#8217;. So most of the times I find it difficult to fit this into a system. At the other hand, I like to prevent to have too much abstract classes; I want too keep things clear.  However the challenge is to find the recurring elements and create a system which can be reused later. This is one of the reasons why I am developing flashflowfactory. Some examples; I always want to have deeplinking, I want to have a transition when I go from <em>page A</em> to <em>page B</em>. And I would love to have the ability to go from <em>page A</em> to <em>page C</em> etc. I also want to send simple events/notifications to anywhere in the application. Well the framework covers that already, however it is still in progress. I love to keep its simplicity in usage, but also the fact I already used it in multiple projects and it slowly satisfies my everchanging needs.</p><p><strong>Keep the freedom</strong><br /> From the coding perspective, I love to have a structured project, even if the designs are not that consequent. Mostly I start with creating the raw pages. These are mostly the starting point. I have already said I am using SWC&#8217;s for the views; I point the base Class of a MovieClip to my classfiles (.as). Inside my class file I say it extends Sprite. As Classname I mostly give the same path, only I add <em>VC</em> (ViewComponent) after the name. For example; When creating a contact page, I use &#8216;<em>ContactPage</em>&#8216; as base class, and &#8216;<em>ContactPageVC</em>&#8216; as class name. This allows me to add the view from code (by adding the view-component) or to just put it directly from the library on the stage inside the Flash IDE. Yes, it is a bit pain in the ass to apply this to lots of pages/components, but it gives freedom of how to use your assets. If anyone knows a better/more simple solution, let me know!</p><p>Happy 2011! <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> Please share your thoughts.</p><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=958&amp;md5=5a05fd499e4e32bb6eb076a555438a83" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2011/01/tips-to-start-a-flash-project/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Update Image class &#8211; added contextMenu</title><link>http://blog.stroep.nl/2009/11/add-contextmenu-to-images/</link> <comments>http://blog.stroep.nl/2009/11/add-contextmenu-to-images/#comments</comments> <pubDate>Fri, 06 Nov 2009 17:35:13 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Other]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[code]]></category> <category><![CDATA[snippet]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=812</guid> <description><![CDATA[<img src="/wp-content/uploads/image-contextmenu.jpg" alt="" class="alignleft" />I've updated my <a href="http://blog.stroep.nl/2009/06/nlstroeputilsimage/">Image class</a>. It is irritating flashsites break the right-click contextmenu. Well, I can't fix that and Adobe should look at that, but I think it would nice to add some of the browser - features to my image class. ]]></description> <content:encoded><![CDATA[<p><img src="/wp-content/uploads/image-contextmenu.jpg" alt="" class="alignleft" />I&#8217;ve updated my <a href="http://blog.stroep.nl/2009/06/nlstroeputilsimage/">Image class</a>. It is irritating flashsites break the right-click contextmenu. Well, I can&#8217;t fix that and Adobe should look at that, but I think it would nice to add some of the browser &#8211; features to my image class.</p><p>Currently I have these options added to the Image class:</p><blockquote><p> <strong>View image</strong><br /> Views image in new window/tab. I used NavigateToURL to make this happen.</p><p><strong>Save Image as..</strong><br /> Saves image on your computer. I used my ImageClass.saveLocal() to make this happen. This is only available within FP10, but I think this is no problem anymore because < a href = "http://www.adobe.com/products/player_census/flashplayer/version_penetration.html" > 93 %</a> (September 2009) has FlashPlayer 10, so most people have it, and I don&#8217;t support outdated software <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p><strong>Copy Image location</strong><br /> Copies the url to the clipboard, using System.setClipboard(url). It&#8217;s a pity I can&#8217;t create a &#8216;Copy Image&#8217; function, because pushing bitmapdata into the clipboard is only supported in AIR.</p><p><strong>Send Image</strong><br /> Sends the url to the mail-client, using &#8220;mailto:&#038;body=&#8221; + src. Also a pity; I can&#8217;t add the image directly into the mail.</p></blockquote><p><strong>How to enable the contextmenu:</strong></p><div class="bbCSH" style="font-family: monospace;"> <span style="color: #0066CC;">import</span> nl.<span style="color: #006600;">stroep</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Image</span>;</p><p><span style="color: #000000; ">var</span> myImage:Image = <span style="color: #000000; ">new</span> Image<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myImage.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;<br /> myImage.<span style="color: #006600;">enableContextMenu</span> = <span style="color: #000000; ">true</span>; <span style="color: #808080; font-style: italic;">// enable it!</span><br /> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>myImage<span style="color: #66cc66;">&#41;</span>;<br /> &nbsp;</div><p> I still love this class, I use it a lot. I want to encourage you to please add these kind of usability things to your apps / websites. And share them! Yes, it takes some extra time to create/add it, because this IS the finishing touch, but a lot of people will like this kind of features.</p><p><strong>Download</strong><br /> Check out the <a href="http://code.google.com/p/stroep/source/browse/trunk/nl/stroep/utils/Image.as">Image class</a> at<a href="http://code.google.com/p/stroep">googlecode</a></p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/11/add-contextmenu-to-images/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Stroep @ Googlecode</title><link>http://blog.stroep.nl/2009/06/stroep-googlecode/</link> <comments>http://blog.stroep.nl/2009/06/stroep-googlecode/#comments</comments> <pubDate>Thu, 04 Jun 2009 19:33:32 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Code snippets]]></category> <category><![CDATA[code]]></category> <category><![CDATA[google]]></category> <category><![CDATA[googlecode]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=647</guid> <description><![CDATA[<img src="http://blog.stroep.nl/wp-content/googlecode.jpg" alt="" title="googlecode" width="100" height="100" class="alignleft size-full wp-image-652" />Today I created a <a href="http://code.google.com/">googlecode </a>account. Now I can easily share code with you guys. :)<strong>check it out</strong> <a href="http://code.google.com/p/stroep/">http://code.google.com/p/stroep/</a> ..or directly go to the source: <a href="http://code.google.com/p/stroep/source/browse/">http://code.google.com/p/stroep/source/browse/</a>]]></description> <content:encoded><![CDATA[<p><img src="http://blog.stroep.nl/wp-content/googlecode.jpg" alt="" title="googlecode" width="100" height="100" class="alignleft size-full wp-image-652" />Today I created a <a href="http://code.google.com/">googlecode </a>account. Now I can easily share actionscript classes with you guys <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p><strong>check it out</strong><br /> <a href="http://code.google.com/p/stroep/">http://code.google.com/p/stroep/</a><br /> ..or directly go to the source:<br /> <a href="http://code.google.com/p/stroep/source/browse/">http://code.google.com/p/stroep/source/browse/</a></p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2009/06/stroep-googlecode/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
