{"id":97,"date":"2007-03-17T08:42:17","date_gmt":"2007-03-17T15:42:17","guid":{"rendered":"http:\/\/labs.zeh.com.br\/blog\/?page_id=97"},"modified":"2008-11-09T08:14:51","modified_gmt":"2008-11-09T15:14:51","slug":"projects","status":"publish","type":"page","link":"https:\/\/labs.zeh.com.br\/blog\/?page_id=97","title":{"rendered":"Projects"},"content":{"rendered":"<p>This is the list of all Actionscript classes I&#8217;ve been working. These are classes and extensions that I use on my day to day work, and they might also be useful for someone else.<\/p>\n<p>Random disclaimer: please notice that all the content available here is provided as-is. Supplied code is free to use but without the guarantee of support of any kind.<\/p>\n<p><a name=\"svn\"><\/a><strong>Please notice<\/strong>: Unless otherwise stated, these classes are freely available from my <em>Subversion<\/em> repository, located <a href=\"http:\/\/svn.zeh.com.br\/actionscript_classes\/\">here<\/a>. And while you can download the files directly using your web browser, I would recommend using some subversion client instead. <a href=\"http:\/\/tortoisesvn.net\/\">TortoiseSVN<\/a> is generally considered a good Subversion client; there&#8217;s a few nice tutorials about it <a href=\"http:\/\/www.mind.ilstu.edu\/research\/robots\/iris4\/developers\/svntutorial\/\">here<\/a>. This might seem complicated at first, but subversion is the easiest and safest way to have update source code delivered to your folder of choice.<\/p>\n<h2>Fnk<\/h2>\n<p>Fnk is an online visual programming environment that uses a dataflow approach for the analysis, processing and synthesis of image and sound in real-time. It\u2019s my main bachelor graduation thesis (under the Digital Interface Design course at Senac), and still under construction, due only on dec\u201908.<\/p>\n<p><a href=\"http:\/\/ffnnkk.org\">Visit the Fnk Website<\/a><\/p>\n<p><a name=\"tweener\"><\/a><\/p>\n<h2>caurina.transitions.Tweener (AS2 and AS3)<\/h2>\n<p><code>Tweener<\/code> is an animation and transition class. It&#8217;s what I use for creating dynamic animations via code, like button rollover states, fades, and other visual effects (and to avoid using the timeline for just about anything). And, although it obeys a slightly different syntax philosophy, it&#8217;s the spiritual successor to my <a href=\"http:\/\/hosted.zeh.com.br\/mctween\/index.html\">MC Tween<\/a>.<\/p>\n<p><strong>Download:<\/strong> Tweener is <a href=\"http:\/\/code.google.com\/p\/tweener\/\">hosted on Google Code<\/a>, so one can find documentation and download information there.<\/p>\n<p><a name=\"lzw\"><\/a><\/p>\n<h2>zeh.compression.LZW (AS2)<\/h2>\n<p><code>LZW<\/code> is a static class that allows string compression using the <a href=\"http:\/\/en.wikipedia.org\/wiki\/LZW\">Lempel-Ziv-Welch<\/a> &#8211; or LZW &#8211; algorithm. It provides good compression with a fast engine that can have split iterations and is ideal to send large amounts of compressible data to a server, like the points that form an image.<\/p>\n<p>How to use:<\/p>\n<pre>import zeh.compression.LZW;\r\nvar myString = \"This is a test string\";\r\nvar myCompressedString = LZW.compress(myString);<\/pre>\n<p>Sometimes, however, big strings might take too long to compress, and this can&#8217;t be done at once because it could halt the player execution and could potentially lead to displaying the &#8220;<em>This script is taking too long<\/em>&#8221; warning, which allows the user to cancel script execution.<\/p>\n<p>To avoid this, the <code>LZW<\/code> class allows compression to be split between frames and be executed in the background. It&#8217;s done like this:<\/p>\n<pre>import zeh.compression.LZW;\r\nvar myString = \"This is a test string\";\r\nvar myID = LZW.slowCompress(myString);<\/pre>\n<p>This starts the string compression in the background. Of course this <em>will<\/em> slow down Flash execution due to the complexity of the algorithm (it compresses 1000 chars per frame); however, it will avoid freezing the movie altogether.<\/p>\n<p>After the compression has started, you can get the percentage of completion by using the <code>getSlowCompressFactor()<\/code> function. For example:<\/p>\n<pre>trace (\"The string compression is \" + (LZW.getSlowCompressFactor(myID) * 100) + \"% complete.\");<\/pre>\n<p>When this value reaches <code>1<\/code>, it has completed. You can then get the compressed data:<\/p>\n<pre>myCompressedString = LZW.getSlowCompressString(myID);\r\nLZW.dispose(myID); \/\/ delete the string compression data to clean up memory<\/pre>\n<p>If you need it, the decompression works in the same way, either with a quick decompression&#8230;:<\/p>\n<pre>var myDecompressedString = LZW.decompress(myCompressedString);<\/pre>\n<p>&#8230;or with a background decompression:<\/p>\n<pre>var myID2 = LZW.slowDecompress(myCompressedString);\r\n...\r\ntrace (\"The string decompression is \" + (LZW.getSlowDecompressFactor(myID2) * 100) + \"% complete.\");\r\n...\r\nmyDecompressedString = LZW.getSlowDecompressString(myID2);\r\nLZW.dispose(myID2); \/\/ delete the string and its data to clean up memory<\/pre>\n<p>Compressed strings can then be sent to server-side scripts just as they where normal strings, using <code>LoadVars<\/code> or similar interfaces. After that is done, the data sent to the server would then have to be decoded by a server script who recognizes LZW data streams.<\/p>\n<p>References used in the creation of this class are the <a href=\"http:\/\/en.wikipedia.org\/wiki\/LZW\">Wikipedia entry for LZW<\/a>, including parts of the Python code, and <a href=\"http:\/\/marknelson.us\/1989\/10\/01\/lzw-data-compression\/\">this article<\/a> on LZW compression.<\/p>\n<p>As a last note, keep in mind that not all tasks that involve transmitting huge chunks of data are better solved with LZW compressing. Depending on the kind of data you&#8217;re working with, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Run-length_encoding\">RLE<\/a> compression might be easier to implement on both sides and might be as good as LZW would; other times, you might not even need compression because the TCP\/IP protocol already compresses data on the fly and the time spent with LZW compression would actually be greater than the time saved when uploading the data. Deciding which approach is the correct one on each specific case is an important step that must not be overlooked; LZW will come in handy sometimes, but due to Actionscript 2&#8217;s lack of execution speed, it&#8217;s not a definitive solution that can be applied on all cases.<\/p>\n<p><strong>Download:<\/strong> <code>LZW<\/code> is available on the <a href=\"#svn\">subversion repository<\/a>.<\/p>\n<p><a name=\"imageloader\"><\/a><\/p>\n<h2>zeh.loading.ImageLoader (AS2)<\/h2>\n<p><code>ImageLoader<\/code> is a straightforward image loader. It simplifies the job of loading images by automatically creating a list of images being loaded, controlling its queue with priority features (by way of the <code>LoadingQueue<\/code> class), and by caching images locally using <code>BitmapData<\/code> instances. This means that when you try to load a new image, it actually loads the image, saves its <code>BitmapData<\/code>, and attaches the image to the container (with <code>smooth<\/code> turned on by default). Additional image loadings will simply be skipped and the cached bitmap is used instead. Simultaneous downloads also &#8220;understand&#8221; each other so if you&#8217;re loading the same image on two different containers at the same time, they will have the correct loading percent set and events fired.<\/p>\n<p>How to use:<\/p>\n<pre>import zeh.loading.ImageLoader;\r\n\r\nvar myImgLoader:ImageLoader = new ImageLoader(whateverMC);\r\nmyImgLoader.onStart = function() {\r\n\ttrace (\"loading is started\");\r\n};\r\nmyImgLoader.onUpdate = function(f:Number) {\r\n\ttrace (\"loading is \" + (f*100) + \" percent complete\");\r\n};\r\nmyImgLoader.onComplete = function() {\r\n\ttrace (\"loading has finished\");\r\n};\r\nmyImgLoader.loadImage(\"whatever.jpg\");<\/pre>\n<p>To control priority, use the second parameter:<\/p>\n<pre>var loader1:ImageLoader = new ImageLoader(whateverMC1);\r\nloader1.loadImage(\"whatever1.jpg\", 5);\r\nvar loader2:ImageLoader = new ImageLoader(whateverMC2);\r\nloader2.loadImage(\"whatever2.jpg\", 0);<\/pre>\n<p>On the above case, in case there&#8217;s a queue of different loadings taking place, <code>loader2<\/code> will load before <code>loader1<\/code>, because the second parameter (priority) is lower.<\/p>\n<p>Priority is just a comparison number; two imageloaders can have the same priority (the first one loads first). Default priority is 5.<\/p>\n<p>Images are attached to the target <code>MovieClip<\/code> with smoothing set to on. If you don&#8217;t want the loaded image to be smoothed, however, just specify the third parameter of the <code>loadImage()<\/code> method as being <code>false<\/code>:<\/p>\n<pre>var iLoader:ImageLoader = new ImageLoader(whateverMC1);\r\niLoader.loadImage(\"whatever2.jpg\", undefined, false);<\/pre>\n<p>Using <code>true<\/code> as the third parameter will use smoothing instead. But since this is the default setting, it&#8217;s not needed.<\/p>\n<p>It&#8217;s important to notice that <code>ImageLoader<\/code> makes use of two loading queue slots by default; that way, no more than 2 loadings take place at the same time globally. This can be changed by using the static <code>setSlots<\/code> method at any time:<\/p>\n<pre>ImageLoader.setSlots(2);<\/pre>\n<p><strong>Dependencies:<\/strong> <code>ImageLoader<\/code> also needs <a href=\"#loadingqueue\"><code>zeh.loading.LoadingQueue<\/code><\/a> present.<\/p>\n<p><strong>Download:<\/strong> <code>ImageLoader<\/code> is available on the <a href=\"#svn\">subversion repository<\/a>.<\/p>\n<p><a name=\"loadingqueue\"><\/a><\/p>\n<h2>zeh.loading.LoadingQueue (AS2)<\/h2>\n<p><code>LoadingQueue<\/code> is a simple loading proxy function that controls queuing of loading actions, so you can better control what gets loaded, when, in what order, without being forced to call a bunch of loads and pray that they don&#8217;t timeout in case there are too many files to load.<\/p>\n<p>How to use:<\/p>\n<pre>import zeh.loading.LoadingQueue;\r\n\r\nvar lq:LoadingQueue = new LoadingQueue();\r\nlq.addMovie(myMovie, \"picture.jpg\");\r\nlq.addXML(myXML, \"data.xml\");\r\nlq.start();<\/pre>\n<p>The above code creates a new simple queue and then start loading the content on the containers.<\/p>\n<p>New <code>LoadingQueue<\/code> instances take a parameter that refers to the group that loading queue takes part. This is unrelated to the loading scope. For example:<\/p>\n<pre>\/\/ Creates two different loading queues\r\nvar lq1:LoadingQueue = new LoadingQueue();\r\nvar lq2:LoadingQueue = new LoadingQueue(this);\r\n\r\n\/\/ Creates two different loading queues but that act as one loading queue only\r\nvar lq1:LoadingQueue = new LoadingQueue();\r\nvar lq2:LoadingQueue = new LoadingQueue();<\/pre>\n<p>Each queue has also a number of maximum loading slots. The default number of slots is 1 per queue. You can change it when creating new loadings:<\/p>\n<pre>var lq:LoadingQueue = new LoadingQueue(this, 3);<\/pre>\n<p>That way, 3 loadings will take place simultaneously. This can also be changed after creating your loading queue instances by using the <code>setSlots<\/code> method:<\/p>\n<pre>lq.setSlots(2);<\/pre>\n<p>Existing loadings are finished even if they take more slots than the new value (they are not cancelled); but new loadings won&#8217;t start until there are available slots on that queue.<\/p>\n<p>Finally, you can also use priority when adding containers to the loading queue:<\/p>\n<pre>lq.addMovie(myMovie1, \"a.jpg\", 5);\r\nlq.addMovie(myMovie2, \"b.jpg\", 0);<\/pre>\n<p>Or:<\/p>\n<pre>lq.addXML(myXML, \"data.xml\", 5);\r\nlq.addXML(myXML2, \"data2.xml\", 0);<\/pre>\n<p>On the first example, in case there&#8217;s a queue, <code>myMovie2<\/code> will be take priority over <code>myMovie1<\/code> because its priority number (0) is lower. The same applies to the XML example. The default priority is 5.<\/p>\n<p>Please notice that this class is not meant to replace the normal preloading procedures one might use when loading content into a Flash movie. It is, instead, meant to juggle the process of triggering loadings according to some specific needs, using priorities and a defined number of slots; you can then use whichever solution you want to measure the progress of the loading procedure inside your content.<\/p>\n<p><strong>Download:<\/strong> <code>LoadingQueue<\/code> is available on the <a href=\"#svn\">subversion repository<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the list of all Actionscript classes I&#8217;ve been working. These are classes and extensions that I use on my day to day work, and they might also be useful for someone else. Random disclaimer: please notice that all the content available here is provided as-is. Supplied code is free to use but without [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=\/wp\/v2\/pages\/97"}],"collection":[{"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=97"}],"version-history":[{"count":0,"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=\/wp\/v2\/pages\/97\/revisions"}],"wp:attachment":[{"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}