<?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; experiment</title> <atom:link href="http://blog.stroep.nl/tag/experiment/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>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>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>Perlin noise &#8211; more experiments</title><link>http://blog.stroep.nl/2008/11/perlin-noise-more-experiments/</link> <comments>http://blog.stroep.nl/2008/11/perlin-noise-more-experiments/#comments</comments> <pubDate>Fri, 07 Nov 2008 23:00:42 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Generative art]]></category> <category><![CDATA[experiment]]></category> <category><![CDATA[flash]]></category> <category><![CDATA[noise]]></category> <category><![CDATA[perlin]]></category> <category><![CDATA[render]]></category> <category><![CDATA[video]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=237</guid> <description><![CDATA[After writing a post of using perlin noise, I'll did some more experiments making cool things. I draw lines using Perlin noise as input. Check this out:<object type="application/x-shockwave-flash" width="420" height="210" data="http://www.flickr.com/apps/video/stewart.swf?v=61761" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&#38;photo_secret=4ca0066c61&#38;photo_id=3011939774"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=61761"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=61761" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&#38;photo_secret=4ca0066c61&#38;photo_id=3011939774" height="210" width="420"></embed></object>]]></description> <content:encoded><![CDATA[<p>After writing <a href="http://blog.stroep.nl/2008/11/make-things-less-static-add-some-movement-with-perlin-noise/">this post</a> of using perlin noise, I&#8217;ll did some more experiments making cool things. I draw lines using Perlin noise as input. Check this out:</p><p><object type="application/x-shockwave-flash" width="420" height="210" data="http://www.flickr.com/apps/video/stewart.swf?v=61761" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&amp;photo_secret=4ca0066c61&amp;photo_id=3011939774"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=61761"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=61761" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&amp;photo_secret=4ca0066c61&amp;photo_id=3011939774" height="210" width="420"></embed></object></p><p>I was also experimenting/figuring out how to convert a actionscript generated movie to video. I never knew it was possible (or that easy) with the Flash CS3 (maybe because I never tried). Just choose file > export movie > and choose .mov extension. The video isn&#8217;t smooth, because (when I save it) it is not really rendering, it&#8217;s just like an invisible screencapture, I guess. So I can&#8217;t use more heavy CPU things. Thats a pity.</p><p>But maybe I could use my <a href="http://blog.stroep.nl/2008/09/as3-imagesaver-class-updated/">ImageSaver Class</a> to create a movie-sequence by saving frame by frame as PNG.</p> ]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2008/11/perlin-noise-more-experiments/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Saving images with AIR - Create a wallpaper using AS3 only</title><link>http://blog.stroep.nl/2008/09/saving-images-with-air-create-a-wallpaper-using-as3-only/</link> <comments>http://blog.stroep.nl/2008/09/saving-images-with-air-create-a-wallpaper-using-as3-only/#comments</comments> <pubDate>Sat, 13 Sep 2008 13:20:34 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Generative art]]></category> <category><![CDATA[AIR]]></category> <category><![CDATA[experiment]]></category> <category><![CDATA[flash]]></category> <category><![CDATA[wallpaper]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=99</guid> <description><![CDATA[I'm experimenting with AIR, because I heard saving a ByteArray ( for example encoded PNG or JPG ) should be quite simple. You don't need PHP or another serverside script for this, just write directly on you disk. Well, just check it out.I created an example of how to get it work. The image will be save in the same directory as your AIR application.<img src="/wp-content/uploads/small-wallpaper.jpg" alt="Cool wallpaper created with AS3" width="430" /> Click the read-more button to find out how to create a cool AS3 wallpaper.]]></description> <content:encoded><![CDATA[<p>Looking for class to save images? <a href="/2008/08/as3-imagesaver-class-v10/">Check out ImageSaver.as</a></p><p>I&#8217;m experimenting with AIR, because I heard saving a ByteArray ( for example encoded PNG or JPG ) should be quite simple. You don&#8217;t need PHP or another serverside script for this, just write directly on you disk. Well, just check it out.</p><p>See this example of how to get it work. The image will be save on the same directory as your AIR application.<div class="bbCSH" style="font-family: monospace;"><span style="color: #808080; font-style: italic;">// use adobe&#8217;s encoder to create a byteArray</span><br /> <span style="color: #000000; ">var</span> jpgEncoder:JPGEncoder = <span style="color: #000000; ">new</span> JPGEncoder<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">&#41;</span>;<br /> <span style="color: #000000; ">var</span> byteArray:ByteArray = jpgEncoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span> bitmapData <span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// set an filename</span><br /> <span style="color: #000000; ">var</span> filename:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;cool-image.jpg&quot;</span>;</p><p><span style="color: #808080; font-style: italic;">// get current path</span><br /> <span style="color: #000000; ">var</span> file:File = File.<span style="color: #006600;">applicationDirectory</span>.<span style="color: #006600;">resolvePath</span><span style="color: #66cc66;">&#40;</span> filename <span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// get the native path </span><br /> <span style="color: #000000; ">var</span> wr:File = <span style="color: #000000; ">new</span> File<span style="color: #66cc66;">&#40;</span> file.<span style="color: #006600;">nativePath</span> <span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// create filestream </span><br /> <span style="color: #000000; ">var</span> stream:FileStream = <span style="color: #000000; ">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// &nbsp;open/create the file, set the filemode to write in order to save.</span><br /> stream.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span> wr , FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// write your byteArray into the file. </span><br /> stream.<span style="color: #006600;">writeBytes</span> <span style="color: #66cc66;">&#40;</span> byteArray, <span style="color: #cc66cc;">0</span>, byteArray.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// close the file. </span><br /> stream.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// That&#8217;s it.</span><br /> &nbsp;</div><p><strong>Is that it? This would be a boring post if I stopped right now <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </strong><br /> I experimented to <em>create a colorful cool wallpaper using AS3 only</em> and save it using AIR. If you don&#8217;t got AIR or just don&#8217;t want to use it, I recommend using my ImageSave class.</p><p><a href="http://www.flickr.com/photos/markknol/2852527273/" target="_blank"><img src="/wp-content/uploads/cool-wallpaper.jpg" alt="Cool wallpaper created with AS3" width="430" /></a><script type="text/javascript">google_ad_client = "pub-8026631169002810";
/* 468x15, gemaakt 30-6-08 */
google_ad_slot = "6262097246";
google_ad_width = 430;
google_ad_height = 15;</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead show_ads.js"></script><br/><br/></p><p><strong>This is my code to create this wallpaper:</strong><br /> Feel free to play with the code, but post a link to your experiment / wallpaper here.</p><div class="bbCSH" style="font-family: monospace;"><span style="color: #0066CC;">package</span> <br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">images</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filters</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> nl.<span style="color: #006600;">stroep</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">class</span> Main <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;">public</span> <span style="color: #000000; ">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> bitmapData:BitmapData = <span style="color: #000000; ">new</span> BitmapData <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1280</span>, <span style="color: #cc66cc;">1024</span>, <span style="color: #000000; ">false</span>, 0&#215;000000 <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create colorful radial lines</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> shape:Shape = <span style="color: #000000; ">new</span> Shape<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <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> i:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>; i &lt; <span style="color: #cc66cc;">1900</span>; i++<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: #808080; font-style: italic;">// create some weird colors using sinus</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">30</span>, <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span> i * <span style="color: #cc66cc;">9</span> <span style="color: #66cc66;">&#41;</span> * i / <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span> * 0xffffff, <span style="color: #cc66cc;">0.4</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// do some weird sin/cos moves</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span> i/<span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">&#41;</span>*i/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, &nbsp;<span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span> i/<span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">&#41;</span>*i/<span style="color: #cc66cc;">2</span><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>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// add it multiple times using other blendmodes, isn&#8217;t that what we do all the time in PhotoShop?</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> shape, <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #006600;">NORMAL</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> shape, <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #0066CC;">ADD</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> shape, <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #006600;">MULTIPLY</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> shape, <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #006600;">OVERLAY</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// cool! filters! Add some blur to our lines to make a nice blurry background</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">applyFilter</span><span style="color: #66cc66;">&#40;</span> bitmapData, bitmapData.<span style="color: #006600;">rect</span>, <span style="color: #000000; ">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> , <span style="color: #000000; ">new</span> BlurFilter<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">40</span>, <span style="color: #cc66cc;">40</span>, <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create colorful radial lines</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> anotherShape:Shape = <span style="color: #000000; ">new</span> Shape<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anotherShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;&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> j:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>; j &lt; <span style="color: #cc66cc;">1900</span>; j++<span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create some weird lines with weird sizes</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> lineWidth:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">50</span> &#8211; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>j / <span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> &gt;&gt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> <span style="color: #0066CC;">color</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span> j <span style="color: #66cc66;">&#41;</span> * j / <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span> * 0xFFFFFF<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anotherShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span> lineWidth, <span style="color: #0066CC;">color</span>, <span style="color: #cc66cc;">0.2</span>, <span style="color: #000000; ">false</span>, LineScaleMode.<span style="color: #006600;">NORMAL</span>, CapsStyle.<span style="color: #006600;">SQUARE</span>, JointStyle.<span style="color: #006600;">MITER</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anotherShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span> j/<span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">&#41;</span>*j/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, &nbsp;<span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span> j/<span style="color: #cc66cc;">4</span> <span style="color: #66cc66;">&#41;</span>*j/<span style="color: #cc66cc;">2</span><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>&nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// cool! filters! Add some blur to our lines to make a little blurry</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">applyFilter</span><span style="color: #66cc66;">&#40;</span> bitmapData, bitmapData.<span style="color: #006600;">rect</span>, <span style="color: #000000; ">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> , <span style="color: #000000; ">new</span> BlurFilter<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// blendmode ADD is awesome</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> anotherShape, <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #006600;">OVERLAY</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create some text</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> <span style="color: #0066CC;">textfield</span>:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; ">new</span> <span style="color: #0066CC;">TextField</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textfield</span>.<span style="color: #006600;">antiAliasType</span> = AntiAliasType.<span style="color: #006600;">NORMAL</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">htmlText</span> = <span style="color: #ff0000;">&quot;&lt;font face=&#8217;Arial&#8217; color=&#8217;#FFFFFF&#8217; size=&#8217;60&#8242;&gt;FUN WITH BITMAPDATA&lt;/font&gt; &lt;br/&gt; &lt;font face=&#8217;verdana&#8217; color=&#8217;#FFFFFF&#8217; size=&#8217;20&#8242;&gt;&lt;B&gt;CREATE YOUR OWN WALLPAPER WITH FLASH&lt;/b&gt;&lt;/font&gt;&quot;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">autoSize</span> = TextFieldAutoSize.<span style="color: #0066CC;">LEFT</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// cool! filters! Add blur to your text</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textfield</span>.<span style="color: #006600;">filters</span> = <span style="color: #66cc66;">&#91;</span> <span style="color: #000000; ">new</span> BlurFilter<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span>,<span style="color: #cc66cc;">20</span>,<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#93;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// draw textfield into bitmapdata, and use a matrix to set its position to center screen</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">textfield</span>, <span style="color: #000000; ">new</span> Matrix<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> &#8211; <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">textWidth</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> ,<span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> &#8211; <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">textHeight</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #0066CC;">ADD</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// reset the filters, just add DropShadow</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textfield</span>.<span style="color: #006600;">filters</span> = <span style="color: #66cc66;">&#91;</span> <span style="color: #000000; ">new</span> DropShadowFilter<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">45</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0.3</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#93;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// draw textfield again</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">textfield</span>, <span style="color: #000000; ">new</span> Matrix<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> &#8211; <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">textWidth</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> ,<span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> &#8211; <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">textHeight</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// show the bitmapData, just add it to the stage, using the Bitmap Class</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; ">new</span> Bitmap <span style="color: #66cc66;">&#40;</span> bitmapData <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// use adobe&#8217;s encoder to create a byteArray</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> jpgEncoder:JPGEncoder = <span style="color: #000000; ">new</span> JPGEncoder<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> byteArray:ByteArray = jpgEncoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span> bitmapData <span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// set an filename</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> filename:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;cool-wallpaper.jpg&quot;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// get current path</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> file:File = File.<span style="color: #006600;">applicationDirectory</span>.<span style="color: #006600;">resolvePath</span><span style="color: #66cc66;">&#40;</span> filename <span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// get the native path </span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> wr:File = <span style="color: #000000; ">new</span> File<span style="color: #66cc66;">&#40;</span> file.<span style="color: #006600;">nativePath</span> <span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create filestream </span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> stream:FileStream = <span style="color: #000000; ">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// &nbsp;open/create the file, set the filemode to write; because we are going to save</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span> wr , FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// write your byteArray into the file. </span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.<span style="color: #006600;">writeBytes</span> <span style="color: #66cc66;">&#40;</span> byteArray, <span style="color: #cc66cc;">0</span>, byteArray.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// close the file. That&#8217;s it.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp;&nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span></div><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=99&amp;md5=4159aa2abe4f863d94cd05087775031c" 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/2008/09/saving-images-with-air-create-a-wallpaper-using-as3-only/feed/</wfw:commentRss> <slash:comments>11</slash:comments> </item> </channel> </rss>
