<?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>Carlo Alducente&#039;s Blog &#187; AS3</title>
	<atom:link href="http://labs.alducente.com/category/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.alducente.com</link>
	<description></description>
	<lastBuildDate>Thu, 12 Nov 2009 01:04:57 +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>AS3 Edge Detection Demo</title>
		<link>http://labs.alducente.com/2009/11/11/as3-edge-detection-demo/</link>
		<comments>http://labs.alducente.com/2009/11/11/as3-edge-detection-demo/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 01:04:57 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[DIFFERENCE]]></category>
		<category><![CDATA[edge detection]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[Webcam]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=178</guid>
		<description><![CDATA[So after posting about a technique to detect edges in AS3, I decided to take a little bit of time today to actually play with it. Check out the vid: The demo used BitmapData along with the &#8220;difference&#8221; blendmode to extract the edges from the webcam feed. Using BitmapData&#8217;s hitTest method, I was able to [...]]]></description>
			<content:encoded><![CDATA[<p>So after posting about a <a href="http://labs.alducente.com/2009/10/16/blendmode-difference-and-why-its-awesome/">technique to detect edges</a> in AS3, I decided to take a little bit of time today to actually play with it. Check out the vid:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/YD7soPmI_wQ&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;feature=player_embedded&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/YD7soPmI_wQ&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;feature=player_embedded&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"></embed></object></p>
<p>The demo used BitmapData along with the &#8220;difference&#8221; blendmode to extract the edges from the webcam feed. Using BitmapData&#8217;s hitTest method, I was able to check whether my sprite is hitting an edge. This was a pretty quick and simple demo (1hr and 147 lines of code! Woot!), so that I could actually see this thing in action. &#8220;Line Rider&#8221; anyone?</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2009/11/11/as3-edge-detection-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Shape Detection</title>
		<link>http://labs.alducente.com/2009/11/10/flash-shape-detection/</link>
		<comments>http://labs.alducente.com/2009/11/10/flash-shape-detection/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 02:08:41 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[gesture]]></category>
		<category><![CDATA[shape detection]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=166</guid>
		<description><![CDATA[I&#8217;ve playing with a lot of motion/gesture detection in flash lately, and this week I got into some shape detection based on user input. In this demo, I used the &#8220;difference&#8221; blend mode to compare the user&#8217;s drawing with a bunch of vector shapes that I&#8217;ve baked in to the swf file. Press down, drag, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve playing with a lot of motion/gesture detection in flash lately, and this week I got into some shape detection based on user input. In this demo, I used the <a href="http://labs.alducente.com/2009/10/16/blendmode-difference-and-why-its-awesome/" target="_self">&#8220;difference&#8221; blend mode</a> to compare the user&#8217;s drawing with a bunch of vector shapes that I&#8217;ve baked in to the swf file.</p>
<p>Press down, drag, and release when your doodle is done. Try to draw the 4 shapes and test out its accuracy.</p>
<p>
<object width="400" height="350">
<param name="movie" value="http://labs.alducente.com/wp-content/uploads/2009/11/shapes.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="400" height="350" src="http://labs.alducente.com/wp-content/uploads/2009/11/shapes.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>When you release the mouse, the shape it detects should light up, if it doesn&#8217;t recognize it then none of the 4 shapes should light up. What I like about this method is that you don&#8217;t need to &#8220;close&#8221; the shapes you draw. You can draw a spiral and it should detect that it&#8217;s a circle.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2009/11/10/flash-shape-detection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BlendMode.DIFFERENCE and why it&#8217;s awesome.</title>
		<link>http://labs.alducente.com/2009/10/16/blendmode-difference-and-why-its-awesome/</link>
		<comments>http://labs.alducente.com/2009/10/16/blendmode-difference-and-why-its-awesome/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 15:01:48 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[BlendMode]]></category>
		<category><![CDATA[DIFFERENCE]]></category>
		<category><![CDATA[edge detection]]></category>
		<category><![CDATA[Webcam]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=135</guid>
		<description><![CDATA[Straight from the CS3 Help section: Compares the constituent colors of the display object with the colors of its background, and subtracts the darker of the values of the two constituent colors from the lighter value. This setting is commonly used for more vibrant colors. For example, if the display object has a pixel with [...]]]></description>
			<content:encoded><![CDATA[<p><em>Straight from the CS3 Help section:</em></p>
<blockquote><p>Compares the constituent colors of the display object with the colors of its background, and subtracts the darker of the values of the two constituent colors from the lighter value. This setting is commonly used for more vibrant colors.</p>
<p>For example, if the display object has a pixel with an RGB value of 0xFFCC33, and the background pixel has an RGB value of 0xDDF800, the resulting RGB value for the displayed pixel is 0x222C33 (because 0xFF &#8211; 0xDD = 0&#215;22, 0xF8 &#8211; 0xCC = 0x2C, and 0&#215;33 &#8211; 0&#215;00 = 0&#215;33).</p></blockquote>
<p>So as an example, let&#8217;s say I have two Sprites, sprite &#8220;A&#8221; &amp; sprite &#8220;B&#8221;:</p>
<p><a href="http://labs.alducente.com/wp-content/uploads/2009/10/difference_a_b.jpg"><img class="aligncenter size-full wp-image-137" title="difference_a_b" src="http://labs.alducente.com/wp-content/uploads/2009/10/difference_a_b.jpg" alt="difference_a_b" width="244" height="120" /></a></p>
<p>If I was to set sprite B&#8217;s blendMode property to BlendMode.DIFFERENCE and place it on top of sprite A, I would end up with something like this:</p>
<p><a href="http://labs.alducente.com/wp-content/uploads/2009/10/difference_result.jpg"><img class="aligncenter size-full wp-image-145" title="difference_result" src="http://labs.alducente.com/wp-content/uploads/2009/10/difference_result.jpg" alt="difference_result" width="100" height="98" /></a></p>
<p><strong>So why is this useful?</strong></p>
<p>Other than for creating cool visuals, we can use this feature to detect edges within any display object. So let&#8217;s pretend I used a second instance of sprite A in place of sprite B and went through the same steps, I would pretty much end up with a black box since there is no difference in pixels between the two sprites. But if I was to move that second instance of sprite A 1 pixel down and 1 pixel right, I would end up with something like this:</p>
<p><a href="http://labs.alducente.com/wp-content/uploads/2009/10/difference_a.jpg"><img class="aligncenter size-full wp-image-150" title="difference_a" src="http://labs.alducente.com/wp-content/uploads/2009/10/difference_a.jpg" alt="difference_a" width="97" height="95" /></a></p>
<p>Notice how only the edges of our star symbol is visible, making everything else (close to) black. Because of the gradient background we used in our sprites, there is a difference between the pixel values in the black areas when we moved our second sprite to be slightly unaligned with the first. The difference isn&#8217;t visible, but it is there. To solve this problem we can use <strong>BitmapData</strong> to &#8220;flatten&#8221; these two sprites and using the <strong>threshold() </strong>method, we can turn any pixels that have a value close to black into any color we choose, including pure black (0&#215;000000).</p>
<p><strong>Okay&#8230;now what?</strong></p>
<p>Since blendMode is a property of DisplayObject, we can use it with any objects that inherit from it, including Video:</p>
<p>
<object width="320" height="240">
<param name="movie" value="http://labs.alducente.com/wp-content/uploads/2009/10/blendmode_difference.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="320" height="240" src="http://labs.alducente.com/wp-content/uploads/2009/10/blendmode_difference.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>This example uses 2 video objects in place of the 2 sprites we used in the earlier examples, we could probably increase performance by taking &#8220;snapshots&#8221; of the video and doing the same steps using 2 bitmaps instead of 2 Video instances, but I decided to keep it simple.</p>
<p>Using this info, we can then interact with edges extracted from the webcam to do some real-time edge detection, a cool webcam game perhaps? <a href="http://www.gskinner.com/blog/archives/2005/08/flash_8_webcam.html" onclick="urchinTracker('/outgoing/www.gskinner.com/blog/archives/2005/08/flash_8_webcam.html?referer=');">Or catching some snowflakes</a>*? but I&#8217;ll save that for another post.</p>
<p>Over &amp; out.</p>
<p>*Grant&#8217;s example was created in Flash 8(as2), which might have used a method similar to what I mentioned here, but I&#8217;m not completely sure.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2009/10/16/blendmode-difference-and-why-its-awesome/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Globequest</title>
		<link>http://labs.alducente.com/2009/10/12/globequest/</link>
		<comments>http://labs.alducente.com/2009/10/12/globequest/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 21:24:50 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[A World Of Wonders]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Globequest]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=110</guid>
		<description><![CDATA[A World of Wonders has just launched Globequest, a game that lets you &#8220;travel&#8221; around the world to learn about different cultures and places. Learn more about the television series on their website. While developing the game was loads of fun, there were a couple challenges that we had to overcome in order to get [...]]]></description>
			<content:encoded><![CDATA[<p>A World of Wonders has just launched <strong><a href="http://www.aworldofwonders.tv/games/globequest.php" target="_blank" onclick="urchinTracker('/outgoing/www.aworldofwonders.tv/games/globequest.php?referer=');">Globequest</a></strong>, a game that lets you &#8220;travel&#8221; around the world to learn about different cultures and places. Learn more about the television series on <a href="http://www.aworldofwonders.tv/" target="_blank" onclick="urchinTracker('/outgoing/www.aworldofwonders.tv/?referer=');">their website</a>.</p>
<p style="text-align: center;"><a href="http://www.aworldofwonders.tv/games/globequest.php" target="_blank" onclick="urchinTracker('/outgoing/www.aworldofwonders.tv/games/globequest.php?referer=');"><img class="aligncenter size-full wp-image-115" title="Globequest Title Screen" src="http://labs.alducente.com/wp-content/uploads/2009/10/Untitled-11.jpg" alt="Globequest Title Screen" width="400" height="300" /></a></p>
<p>While developing the game was loads of fun, there were a couple challenges that we had to overcome in order to get this game off the ground&#8230;(OH SNAP! See what I did there? off the ground? traveling? airplane? no?&#8230;okay)</p>
<p>After being presented with the idea, the first thing that came to mind was how to manage the HUGE map the player had to travel around in. I&#8217;m talkin&#8217; loading and moving a 6400&#215;1600 bitmap without sacrificing image quality or performance.</p>
<p>Many tests later, we decided that the best way to solve the filesize issue was to seperate the map into 800&#215;600 tiles, keeping low resolution tiles embedded in the swf file so the player can start the game as soon as possible. While the player travels, the high resolution tiles are being loaded in the background, replacing the low res images one by one as they finish loading. Not only does this reduce the total filesize of the main swf, but it also lets the player continue without having to wait for the giant map to load.</p>
<p style="text-align: center;"><a style="text-decoration: none;" href="http://www.aworldofwonders.tv/games/globequest.php" target="_blank" onclick="urchinTracker('/outgoing/www.aworldofwonders.tv/games/globequest.php?referer=');"><img class="aligncenter size-full wp-image-118" title="Globequest Big Map" src="http://labs.alducente.com/wp-content/uploads/2009/10/Untitled-2.jpg" alt="Globequest Big Map" width="400" height="300" /></a></p>
<p>As for performance, most of us know that moving something as big as 6400&#215;1600 around on screen can be choppy. To improve the animation, I used the display object&#8217;s scrollRect property. For those who aren&#8217;t familiar with this handy feature, it basically acts like a mask, displaying only a section of a display object on screen but with way better performance than a mask. <a href=" http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#scrollRect" target="_blank">Read more about it in the docs here</a>.</p>
<p><strong>So that takes care of the map, but what about the mini games?</strong></p>
<p style="text-align: center;"><a href="http://www.aworldofwonders.tv/games/globequest.php" target="_blank" onclick="urchinTracker('/outgoing/www.aworldofwonders.tv/games/globequest.php?referer=');"><img class="aligncenter size-full wp-image-121" title="Globequest Puzzle" src="http://labs.alducente.com/wp-content/uploads/2009/10/Untitled-3.jpg" alt="Globequest Puzzle" width="400" height="300" /></a></p>
<p>In order to keep the games organized, each one is a separate swf file that gets loaded. This let&#8217;s me encapsulate each mini game, keeping its functionality hidden from the rest of the game. A manager had to be created in order to keep track of all the different games and is in charge of displaying a game when needed, communicating the user&#8217;s performance to the main swf, and cleaning up after a game so the game engine can be reused.</p>
<p><strong>Videos&#8230;so many videos&#8230;</strong></p>
<p style="text-align: center;"><strong><a href="http://www.aworldofwonders.tv/games/globequest.php" target="_blank" onclick="urchinTracker('/outgoing/www.aworldofwonders.tv/games/globequest.php?referer=');"><img class="aligncenter size-full wp-image-124" title="Globequest Video" src="http://labs.alducente.com/wp-content/uploads/2009/10/Untitled-4.jpg" alt="Globequest Video" width="400" height="300" /></a><br />
</strong></p>
<p>For the videos, we wanted to do something simple, using only basic controls to toggle between play and pause states plus a couple events that we can listen for. The FLVPlayback component, while convenient, has too many bells and whistles for our purpose and using the Video class didn&#8217;t give us the amount of control that we wanted. So I decided to go with the built-in VideoPlayer class, which is also a subclass of the Video object but a lot simpler than the FLVPlayback component.</p>
<p><strong>#$%@#!!!</strong></p>
<p>While this wasn&#8217;t an issue, it was something that was completely new to me and thought I&#8217;d share the experience. Since this is a children&#8217;s game after all, we needed to make sure that text inputs filter out &#8220;no-no&#8221; words. Luckily, there&#8217;s only one text input in the entire game (*high-five!). Instead of clearing the field when a bad word is detected, I chose to just disable the &#8220;go&#8221; button. This makes it less frustrating for children with names like &#8220;Dickson&#8221;.</p>
<p style="text-align: center;"><a style="text-decoration: none;" href="http://www.aworldofwonders.tv/games/globequest.php" target="_blank" onclick="urchinTracker('/outgoing/www.aworldofwonders.tv/games/globequest.php?referer=');"><img class="aligncenter size-full wp-image-125" title="Globequest Player: Dickson" src="http://labs.alducente.com/wp-content/uploads/2009/10/Untitled-5.jpg" alt="Globequest Player: Dickson" width="400" height="102" /></a></p>
<p>Now, how am I suppose to detect inappropriate words? Should I just type out every word I could think of?&#8230;.Interwebz to the rescue!!! <a href="http://www.noswearing.com/list.php" target="_blank" onclick="urchinTracker('/outgoing/www.noswearing.com/list.php?referer=');">Check out the list</a>. Now the only thing I needed to do was copy the entire list and write a quick script to format it the way I want, instant digital earmuffs.</p>
<p>So in the end, I would have to say that this project was probably one of the biggest I had the opportunity to code on my own (yes, I&#8217;m a big boy now). I had a chance to take my time, lay out an architecture, and execute smoothly and with ease. While there were some speed bumps along the way, mostly flash &#8220;gotchas&#8221;, there was definitely a lot to learn from this project.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2009/10/12/globequest/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Demo: Playing with text.</title>
		<link>http://labs.alducente.com/2009/09/29/demo-playing-with-text/</link>
		<comments>http://labs.alducente.com/2009/09/29/demo-playing-with-text/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 03:28:34 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=95</guid>
		<description><![CDATA[I had a bit of a blast from the past earlier today while going through some old folders containing previous work and experiments. I came across a quick little demo I threw together in my early attempts of using TweenLite and the BitmapData class. Check it out below: And I&#8217;m not quite sure why I [...]]]></description>
			<content:encoded><![CDATA[<p>I had a bit of a blast from the past earlier today while going through some old folders containing previous work and experiments. I came across a quick little demo I threw together in my early attempts of using TweenLite and the BitmapData class. Check it out below:</p>
<p>
<object width="500" height="200">
<param name="movie" value="http://labs.alducente.com/wp-content/uploads/2009/09/dotText.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="500" height="200" src="http://labs.alducente.com/wp-content/uploads/2009/09/dotText.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>And I&#8217;m not quite sure why I did it, but I added a rollover effect on the dots as well&#8230;go ahead, put your mouse over those dots, you know you want to!</p>
<p>Looking back at this, and some <a href="http://labs.alducente.com/page/2/" target="_self">recent BitmapData work</a>, I&#8217;m getting a bit excited and starting to crave some more experimental work, I&#8217;ve already got a few ideas in mind! Superfluous rollover effects and all! <img src='http://labs.alducente.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>-Carlo</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2009/09/29/demo-playing-with-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interacting with the webcam</title>
		<link>http://labs.alducente.com/2009/08/25/70/</link>
		<comments>http://labs.alducente.com/2009/08/25/70/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 20:50:34 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Augmented Reality]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[Camera]]></category>
		<category><![CDATA[Marker Tracking]]></category>
		<category><![CDATA[Motion Detection]]></category>
		<category><![CDATA[Webcam]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=70</guid>
		<description><![CDATA[Last month, we decided to do some show-and-tell sessions at Zinc Roe where everyone had a chance to show some really cool stuff. My contribution was a little presentation on different ways to use the webcam to interact with flash applications. I had a blast reading up on some interesting webcam detection tutorials and articles, [...]]]></description>
			<content:encoded><![CDATA[<p>Last month, we decided to do some show-and-tell sessions at Zinc Roe where everyone had a chance to show some really cool stuff. My contribution was a little presentation on different ways to use the webcam to interact with flash applications. I had a blast reading up on some interesting webcam detection tutorials and articles, as well as putting some examples together myself.</p>
<p>Here are the topics I covered:</p>
<ul>
<li><strong>Camera.activityLevel</strong> &#8211; A brief explanation on using the Camera object&#8217;s activityLevel property</li>
<li><strong>Bitmap.getPixel()</strong> &#8211; Using the BitmapData class to check for motion</li>
<li><strong>Augmented Reality &amp; Marker Tracking</strong> &#8211; What it is and how it can be used in different applications.</li>
<li><strong>Moving MovieClips with your hand (or other limbs) using the webcam</strong> &#8211; An example of how you can use the motion detection stuff to move a MovieClip around the screen using only your hands and a webcam.</li>
</ul>
<p>So check out <a href="http://blog.zincroe.com/2009/07/motion-activity-tracking-in-flash/" target="_blank" onclick="urchinTracker('/outgoing/blog.zincroe.com/2009/07/motion-activity-tracking-in-flash/?referer=');">my post over at the Metal Fish Eggs blog</a> and let me know what you think!</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2009/08/25/70/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Superscripts, Subscripts, and Dynamic Textfields</title>
		<link>http://labs.alducente.com/2008/12/22/superscripts-subscripts-and-dynamic-textfields/</link>
		<comments>http://labs.alducente.com/2008/12/22/superscripts-subscripts-and-dynamic-textfields/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 21:03:14 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=62</guid>
		<description><![CDATA[Up until recently, I firmly believed that there was no easy way to make dynamic text have superscripted or subscripted characters. That is until I cracked open another developer&#8217;s flash files and noticed something that I&#8217;ve never seen before. He/she has embedded superscript fonts in the library, and used this font anytime the code encounters [...]]]></description>
			<content:encoded><![CDATA[<p>Up until recently, I firmly believed that there was no easy way to make dynamic text have superscripted or subscripted characters. That is until I cracked open another developer&#8217;s flash files and noticed something that I&#8217;ve never seen before. He/she has embedded superscript fonts in the library, and used this font anytime the code encounters a &lt;sup&gt;&lt;/sup&gt;  tag in the htmlText that was being loaded through XML. So I did a bit of google-ing and found a few helpful links, it seems that it&#8217;s the best (and easiest) way to deal with this problem. Check it out:</p>
<p><a href="http://www.psyked.co.uk/adobe/flash/superscript-and-subscript-with-actionscript.htm" target="_blank" onclick="urchinTracker('/outgoing/www.psyked.co.uk/adobe/flash/superscript-and-subscript-with-actionscript.htm?referer=');">http://www.psyked.co.uk/adobe/flash/superscript-and-subscript-with-actionscript.htm</a></p>
<p><a href="http://blog.ggshow.com/index.php/reference/2007/04/19/how_to_use_subscript_aamp_superscript_in" target="_blank" onclick="urchinTracker('/outgoing/blog.ggshow.com/index.php/reference/2007/04/19/how_to_use_subscript_aamp_superscript_in?referer=');">http://blog.ggshow.com/index.php/reference/2007/04/19/how_to_use_subscript_aamp_superscript_in</a></p>
<p>Pretty neat, eh?</p>
<p>-Carlo</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2008/12/22/superscripts-subscripts-and-dynamic-textfields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash forms and how to make them less annoying to make</title>
		<link>http://labs.alducente.com/2008/11/21/flash-forms-and-how-to-make-them-less-annoying-to-make/</link>
		<comments>http://labs.alducente.com/2008/11/21/flash-forms-and-how-to-make-them-less-annoying-to-make/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 20:26:27 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Forms]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=52</guid>
		<description><![CDATA[I&#8217;ve never been a big fan of creating forms in flash, like many others I would rather build an html form and let the backend guys deal with all the validating. But sometime it&#8217;s just unavoidable, specially when your entire site is in flash, popping open an html form is kinda dinky and not very [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve never been a big fan of creating forms in flash, like many others I would rather build an html form and let the backend guys deal with all the validating. But sometime it&#8217;s just unavoidable, specially when your entire site is in flash, popping open an html form is kinda dinky and not very good for consistency.</p>
<p>Here&#8217;s a couple things that I found made my life easier when creating forms in flash.</p>
<p><strong>Email Validation<br />
</strong>Here&#8217;s a good function that I snatched from a <a href="http://www.senocular.com/" target="_blank" onclick="urchinTracker('/outgoing/www.senocular.com/?referer=');">senocular</a> forum thread. Using AS3 regular expressions, it returns true if an email is valid and false if it&#8217;s not:</p>
<pre>function isValidEmail(email:String):Boolean {
	var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
	return emailExpression.test(email);
}</pre>
<p>All you have to do is pass the email in the parameter like so:</p>
<pre>trace(isValidEmail("carlo@alducente.com")) //traces "true"
trace(isValidEmail("woot!")) //traces "false"</pre>
<p><strong>Checking For Empty Fields<br />
</strong>This isn&#8217;t a big issue but found that it&#8217;s good to keep reminding myself that if text in a field is ==&#8221;" or == null, it doesn&#8217;t necessarily mean that it&#8217;s not empty.</p>
<p>Previously, in order to check for empty fields, i would always just check if the string is empty or equal to null, like so:</p>
<pre>if([string] == "" || [string] == null){
	//[string] is empty, throw a big fat bolded error.
}</pre>
<p>I did this for quite a while until i realized that people can still put in spaces only and it will bypass my validation because technically, the string is not empty. It&#8217;s got one (or more) spaces in it only. So here&#8217;s a quick function that I hacked together:</p>
<pre>function isNotEmpty(info:String):Boolean{
	var noSpaces:Array = info.split(" ");
	var a:uint;
	for (a = 0; a &lt; noSpaces.length;a++ ){
		if (noSpaces[a] != ""){
			return true;
		}
	}
	return false;
}</pre>
<p>Using the split() method of a string, i seperate the string into an array wherever there is a space. So if I call the function on &#8220;Carlo is blogging&#8221;, i get an array back that looks like this: ["Carlo", "is", "blogging"]. I can then loop through the array and check if there are any empty (&#8220;&#8221;) values in the array. If the Array is full of empty values, then the string is empty (return false), but if it finds at least one real value, return true.</p>
<p><strong>And the best for last: TABBING!! AAAHHHHH!!!!<br />
</strong>I&#8217;m probably the worst at remembering the tabbing order of my forms in flash. Just when you think you&#8217;re done with a form, the QA guy hits the &#8220;TAB&#8221; button and BLAM! You&#8217;re selection goes from the &#8220;First Name&#8221; field to some random movieclip and puts you to shame with a thick ugly yellow border around that movieclip.</p>
<p>There are two ways you can specify the tabbing order. You can do it by selecting the object you want to add tabbing on to, and going to Window&gt;Other Panels&gt;Accessibility. A window will popup with a &#8220;Tab index&#8221; field. There you can put in a number depending on the order of the tabbing. So if you want to make a text field the first one in the tabbing order, you just put 1 in that field.</p>
<p>You can also specify tabbing order through code, in AS3 objects have a &#8220;tabIndex&#8221; property, you can do the same thing above and give it a numerical value.</p>
<p>The one &#8220;gotcha&#8221; I always encounter is having random movieclips be part of the tabbing, highlighting it with a yellow border. The simplest solution to this is disabling the tabbing for that  movieclip by using the &#8220;tabEnabled&#8221; property.</p>
<pre>
myMovieClip.tabEnabled = false; //keeps it out of the tab order.
</pre>
<p>Any buttons on stage will automatically get added to the tabbing order, even if it&#8217;s originally a movieclip and you set its &#8220;buttonMode&#8221; property to true, that&#8217;s how I usually get that yellow border.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2008/11/21/flash-forms-and-how-to-make-them-less-annoying-to-make/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Color Sampler</title>
		<link>http://labs.alducente.com/2008/10/28/color-sampler/</link>
		<comments>http://labs.alducente.com/2008/10/28/color-sampler/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 20:47:42 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=39</guid>
		<description><![CDATA[Once again, it&#8217;s time to dust off the ol&#8217; blog. Sorry i&#8217;ve been busy with a couple little projects that I&#8217;ve been experimenting with, some work related&#8230;some not. It&#8217;s been a crazy few weeks and I&#8217;ve had some time to actually start experimenting with things like BitmapData, papervision, and the flex SDK. In a recent [...]]]></description>
			<content:encoded><![CDATA[<p>Once again, it&#8217;s time to dust off the ol&#8217; blog. Sorry i&#8217;ve been busy with a couple little projects that I&#8217;ve been experimenting with, some work related&#8230;some not. It&#8217;s been a crazy few weeks and I&#8217;ve had some time to actually start experimenting with things like BitmapData, papervision, and the flex SDK. In a recent R&amp;D session I came across this wicked <a href="http://www.somerandomdude.net/blog/flash/actionscript-3-color-sampler-class-download/" target="_blank" onclick="urchinTracker('/outgoing/www.somerandomdude.net/blog/flash/actionscript-3-color-sampler-class-download/?referer=');">ColorSampler</a> class written by P.J. Onori (a.k.a. <a href="http://www.somerandomdude.net" target="_blank" onclick="urchinTracker('/outgoing/www.somerandomdude.net?referer=');">somerandomdude</a>).</p>
<p>Using this class, you can grab the average color of any bitmap you specify. Pretty neat, eh?</p>
<p>-Car</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2008/10/28/color-sampler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Array Randomness</title>
		<link>http://labs.alducente.com/2008/07/29/array-randomness/</link>
		<comments>http://labs.alducente.com/2008/07/29/array-randomness/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 15:13:08 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=30</guid>
		<description><![CDATA[One of the simple things that I use (and get asked about) a lot is a way to get random values from an array, here a couple of ways of doing it. The simplest way of getting random values from an array is by creating a random index number and using it to access the [...]]]></description>
			<content:encoded><![CDATA[<p>One of the simple things that I use (and get asked about) a lot is a way to get random values from an array, here a couple of ways of doing it.</p>
<p>The simplest way of getting random values from an array is by creating a random index number and using it to access the array:</p>
<pre>//Array you want to pull values from
var myArray:Array = ["hello", "world", 11, 8, 86, {prop: "value"}];

//Trace a random value from the array
trace(getRandomValue(myArray));

function getRandomValue(array:Array):*{
	//Generate a random number to use as an index for the array
	var index:Number = Math.floor( Math.random() * array.length );
	//Return the value associated with the random index
	return array[index];
}</pre>
<p>If you try tracing out the value more than once, you&#8217;ll notice that sometimes you get the same value two or more times in a row. What if we just want to pull a unique random value from the array? We can do that by removing the selected value from the array so next time we ask for a random value, the previous values that were chosen will not be available again:</p>
<pre>var myArray:Array = ["hello", "world", 11, 8, 86, {prop: "value"}];

trace("Original Array: "+myArray);
trace(getRandomValue(myArray));
trace("Original Array: "+myArray);

function getRandomValue(array:Array):*{
	//Generate a random number to use as an index for the array
	var index:Number = Math.floor( Math.random() * array.length );
	//Remove the selected value from the array using the splice method, and return it
	return array.splice(index, 1)[0];
}</pre>
<p>If you run the code above, you&#8217;ll notice that the value selected by our getRandomValue() function edits the array and removes the value so next time we ask for another random value, it won&#8217;t be there for the function to select.</p>
<p>This is all good, but what happens if we want to get a unique random value without editing the original array? This is where the slice() method comes in to help, it returns a duplicate of the array you&#8217;re slicing:</p>
<pre>var myArray:Array = ["hello", "world", 11, 8, 86, {prop: "value"}];

//Create a copy of the original array and assign it to a new variable
var arrayCopy:Array = myArray.slice();

trace(getRandomValue(arrayCopy));
trace("Original Array: "+myArray);
trace("Duplicate Array: "+arrayCopy);

function getRandomValue(array:Array):*{
	//Generate a random number to use as an index for the array
	var index:Number = Math.floor( Math.random() * array.length );
	//Remove the selected value from the array using the splice method, and return it
	return array.splice(index, 1)[0];
}</pre>
<p>In our code above, we create a duplicate of our original array and use it to get unique random values. This prevents us from editing the original.</p>
<p>Pretty simple, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2008/07/29/array-randomness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
