<?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>Scripting Action</title>
	<atom:link href="http://www.scriptingaction.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.scriptingaction.com</link>
	<description>by Itai Asseo</description>
	<lastBuildDate>Sun, 05 Sep 2010 15:50:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Drawing in cocos2D</title>
		<link>http://www.scriptingaction.com/?p=240</link>
		<comments>http://www.scriptingaction.com/?p=240#comments</comments>
		<pubDate>Sun, 05 Sep 2010 15:50:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scriptingaction.com/?p=240</guid>
		<description><![CDATA[ok &#8212; so, last time I was really excited about cocos2D for it&#8217;s flash-like features. Because I use the flash graphics API extensively, I was looking for something similar in the iPhone API. unfortunately, it&#8217;s not as straight forward, but Cocos2D once again came to the rescue. 
there are 2 ways generally to draw in [...]]]></description>
			<content:encoded><![CDATA[<p>ok &#8212; so, last time I was really excited about cocos2D for it&#8217;s flash-like features. Because I use the flash graphics API extensively, I was looking for something similar in the iPhone API. unfortunately, it&#8217;s not as straight forward, but Cocos2D once again came to the rescue. </p>
<p>there are 2 ways generally to draw in Cocos2d.  One is taking advantage of the &#8216;draw&#8217; function that every instance of CCNode, CCSprite and CCLayer inherit. it&#8217;s taking advantage of the openGL engine, but for most cases the result is a bit rough looking&#8230; you can draw lines, basic shapes and fills.  It&#8217;s really fast and it saves you a lot of the hassle of getting the graphic context and all that.  here&#8217;s how you draw a simple line &#8212;  &#8220;draw&#8221; is overriding a function that gets called every single frame &#8212; you you are essentially redrawing all the time.</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#41;</span> draw<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CGSize <span style="color: #0066CC;">size</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#91;</span>CCDirector sharedDirector<span style="color: #66cc66;">&#93;</span> winSize<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; glColor4f<span style="color: #66cc66;">&#40;</span>1.0, 0.0, 0.0, 1.0<span style="color: #66cc66;">&#41;</span>; &nbsp;<br />
&nbsp; &nbsp; glLineWidth<span style="color: #66cc66;">&#40;</span>2.0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; glEnable<span style="color: #66cc66;">&#40;</span>GL_LINE_SMOOTH<span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; ccDrawLine<span style="color: #66cc66;">&#40;</span>startPoint, endPoint<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>The other way of drawing in Cocos2D is using whats called Render Texture. The general idea is that you take an image and burn it&#8217;s texture in a certain position. it&#8217;s really straight forward and it lets you control the type of brush/shape with the image you&#8217;re using. The basic implementation is something like this:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:200px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>implementation RenderTextureTest<br />
-<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> init<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span>self = <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">super</span> init<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; CGSize s = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#91;</span>CCDirector sharedDirector<span style="color: #66cc66;">&#93;</span> winSize<span style="color: #66cc66;">&#93;</span>; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; CCLabel<span style="color: #66cc66;">*</span> label = <span style="color: #66cc66;">&#91;</span>CCLabel labelWithString:<span style="color: #66cc66;">@</span><span style="color: #ff0000;">&quot;Render Texture Test&quot;</span> fontName:<span style="color: #66cc66;">@</span><span style="color: #ff0000;">&quot;Arial&quot;</span> fontSize:32<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>self addChild:label z:0<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>label setPosition: ccp<span style="color: #66cc66;">&#40;</span>s.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span>2, s.<span style="color: #006600;">height</span>-50<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create a render texture, this is what we're going to draw into</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">target</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#91;</span>CCRenderTexture renderTextureWithWidth:s.<span style="color: #0066CC;">width</span> <span style="color: #0066CC;">height</span>:s.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#93;</span> retain<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">target</span> setPosition:ccp<span style="color: #66cc66;">&#40;</span>s.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span>2, s.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// note that the render texture is a cocosnode, and contains a sprite of it's texture for convience,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// so we can just parent it to the scene like any other cocos node</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>self addChild:<span style="color: #0066CC;">target</span> z:1<span style="color: #66cc66;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create a brush image to draw into the texture with</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; brush = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#91;</span>CCSprite spriteWithFile:<span style="color: #66cc66;">@</span><span style="color: #ff0000;">&quot;brush.png&quot;</span><span style="color: #66cc66;">&#93;</span> retain<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>brush setBlendFunc: <span style="color: #66cc66;">&#40;</span>ccBlendFunc<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> GL_ONE, GL_ONE_MINUS_SRC_ALPHA <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span>; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>brush setOpacity:100<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; self.<span style="color: #006600;">isTouchEnabled</span> = YES;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Save Image menu</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>CCMenuItemFont setFontSize:16<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; CCMenuItem <span style="color: #66cc66;">*</span>item = <span style="color: #66cc66;">&#91;</span>CCMenuItemFont itemFromString:<span style="color: #66cc66;">@</span><span style="color: #ff0000;">&quot;Save Image&quot;</span> <span style="color: #0066CC;">target</span>:self selector:<span style="color: #66cc66;">@</span>selector<span style="color: #66cc66;">&#40;</span>saveImage:<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; CCMenu <span style="color: #66cc66;">*</span><span style="color: #0066CC;">menu</span> = <span style="color: #66cc66;">&#91;</span>CCMenu menuWithItems:item, nil<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>self addChild:<span style="color: #0066CC;">menu</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">menu</span> setPosition:ccp<span style="color: #66cc66;">&#40;</span>s.<span style="color: #006600;">width</span>-80, s.<span style="color: #006600;">height</span>-80<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> self;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
-<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#41;</span>ccTouchesMoved:<span style="color: #66cc66;">&#40;</span>NSSet <span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>touches withEvent:<span style="color: #66cc66;">&#40;</span>UIEvent <span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>event<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; UITouch <span style="color: #66cc66;">*</span>touch = <span style="color: #66cc66;">&#91;</span>touches anyObject<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; CGPoint <span style="color: #0066CC;">start</span> = <span style="color: #66cc66;">&#91;</span>touch locationInView: <span style="color: #66cc66;">&#91;</span>touch view<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">start</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#91;</span>CCDirector sharedDirector<span style="color: #66cc66;">&#93;</span> convertToGL: <span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// begin drawing to the render texture</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">target</span> begin<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//move the brush to position</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#91;</span>brush setPosition:ccp<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">start</span>.<span style="color: #006600;">x</span>, <span style="color: #0066CC;">start</span>.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// draw the texture</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#91;</span>brush visit<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// finish drawing and return context back to the screen</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">target</span> <span style="color: #0066CC;">end</span><span style="color: #66cc66;">&#93;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>When I was playing around with these methods my first instinct was to create a bunch of sprites and draw on the at the same time to get a cool effect with rotation/scale etc.  That proved to be a very bad idea with RenderTexture.  Sprites are extremely expensive, memory-wise, and especially when they&#8217;re big.  Very quickly I brought the FPS down to 12 (from 60).  What I had to do is create more complex math and keep the sprite count at 1 which works really well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptingaction.com/?feed=rss2&amp;p=240</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocos2D is Flash for the iPhone</title>
		<link>http://www.scriptingaction.com/?p=236</link>
		<comments>http://www.scriptingaction.com/?p=236#comments</comments>
		<pubDate>Mon, 16 Aug 2010 03:23:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scriptingaction.com/?p=236</guid>
		<description><![CDATA[This is really the one line advice I needed. I&#8217;ve dabbled with iPhone apps for a couple of months now, but building temperature converters, table views and sliders bored me to death! So it wasn&#8217;t until I went out for some hummus with my friend that he suggested I download the Cocos2D framework. 2 days [...]]]></description>
			<content:encoded><![CDATA[<p>This is really the one line advice I needed. I&#8217;ve dabbled with iPhone apps for a couple of months now, but building temperature converters, table views and sliders bored me to death! So it wasn&#8217;t until I went out for some hummus with my friend that he suggested I download the <a href="http://www.cocos2d-iphone.org/">Cocos2D framework</a>. 2 days later I&#8217;m hooked. and basically, I just want to put down some things so I don&#8217;t forget &#8212; stuff that would help me translate AS3 to xCode. The stuff below is really all from the <a href="http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:lesson_2._your_first_game">first page of the beginner tutorials</a>, but it is so similar to how flash works (or at least, how I&#8217;m used to work with flash) that I wanted to point it out.</p>
<p>Here are some early findings:</p>
<p>how to create a sprite and add it to the display list:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CCSprite <span style="color: #66cc66;">*</span>mySprite;<br />
mySprite = <span style="color: #66cc66;">&#91;</span>CCSprite spriteWithFile: <span style="color: #66cc66;">@</span><span style="color: #ff0000;">&quot;image.png&quot;</span><span style="color: #66cc66;">&#93;</span>;<br />
mySprite.<span style="color: #0066CC;">position</span> = ccp<span style="color: #66cc66;">&#40;</span> 100, 100 <span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#91;</span>self addChild:mySprite<span style="color: #66cc66;">&#93;</span>;</div></div>
<p>how to add an enterFrame Event:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// schedule a repeating callback on every frame</span><br />
<span style="color: #66cc66;">&#91;</span>self schedule:<span style="color: #66cc66;">@</span>selector<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">nextFrame</span>:<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;</div></div>
<p>and how the enterFrame function looks like:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">- <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#41;</span> <span style="color: #0066CC;">nextFrame</span>:<span style="color: #66cc66;">&#40;</span>ccTime<span style="color: #66cc66;">&#41;</span>dt <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; mySprite.<span style="color: #0066CC;">position</span> = ccp<span style="color: #66cc66;">&#40;</span> mySprite.<span style="color: #0066CC;">position</span>.<span style="color: #006600;">x</span> + 100<span style="color: #66cc66;">*</span>dt, mySprite.<span style="color: #0066CC;">position</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>mySprite.<span style="color: #0066CC;">position</span>.<span style="color: #006600;">x</span> <span style="color: #66cc66;">&gt;</span> 480+32<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mySprite.<span style="color: #0066CC;">position</span> = ccp<span style="color: #66cc66;">&#40;</span> -32, mySprite.<span style="color: #0066CC;">position</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptingaction.com/?feed=rss2&amp;p=236</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AIR Apps running on Android</title>
		<link>http://www.scriptingaction.com/?p=232</link>
		<comments>http://www.scriptingaction.com/?p=232#comments</comments>
		<pubDate>Fri, 21 May 2010 00:47:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://www.scriptingaction.com/?p=232</guid>
		<description><![CDATA[We finally have a public Beta to play with and start experimenting with creating Flash Apps for the Android.  Get one for yourself here: http://labs.adobe.com/technologies/air2/android/.
Here is a small app I ported from flash.  The cool thing is that you don&#8217;t need to change any of your code, expect for accounting for the small [...]]]></description>
			<content:encoded><![CDATA[<p>We finally have a public Beta to play with and start experimenting with creating Flash Apps for the Android.  Get one for yourself here: <a href="http://labs.adobe.com/technologies/air2/android/">http://labs.adobe.com/technologies/air2/android/</a>.</p>
<p>Here is a small app I ported from flash.  The cool thing is that you don&#8217;t need to change any of your code, expect for accounting for the small screen.  Of course there are the new multitouch functions that you can take advantage of, but that&#8217;s like an added bonus.  Check it out. make some apps! </p>
<p><object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=11912145&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=11912145&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>
<p><a href="http://vimeo.com/11912145">Fun with Flash on Android</a> from <a href="http://vimeo.com/iasseo">Itai Asseo</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptingaction.com/?feed=rss2&amp;p=232</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Circular Slider</title>
		<link>http://www.scriptingaction.com/?p=218</link>
		<comments>http://www.scriptingaction.com/?p=218#comments</comments>
		<pubDate>Fri, 08 Jan 2010 21:55:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scriptingaction.com/?p=218</guid>
		<description><![CDATA[One of the challanges in the design of www.flurrious.com was getting those circular sliders in.  Of course you can fake it and create an animation of a slider and control the timeline from 0-100, but that&#8217;s lame and not so easy to modify (like change the radius, sweep angle etc.).  so, I set [...]]]></description>
			<content:encoded><![CDATA[<p>One of the challanges in the design of <a href="http://www.flurrious.com">www.flurrious.com</a> was getting those circular sliders in.  Of course you can fake it and create an animation of a slider and control the timeline from 0-100, but that&#8217;s lame and not so easy to modify (like change the radius, sweep angle etc.).  so, I set to create a circular slider.</p>
<p>I had the basic principles in place: create a circle, and create a beginSwipe andgle and an endSwipe angle. done:</p>
<p><a rel="shadowbox;width=600;height=600;" href="http://www.asseo.net/blog_files/flash/circ_slider_swipe.swf"><img src="http://www.asseo.net/labs/wp-content/uploads/2010/01/Picture-1.png" alt="" title="Picture 1" width="300" height="292" class="alignnone size-full wp-image-220" /></a></p>
<p>the code looks something like this:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package &nbsp;<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* @author iasseo<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CircularSlider <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _circ : Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _startAngle : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">90</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _angleRange : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">30</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _angleShape : Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _radius : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">250</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> topAngle : <span style="color: #0066CC;">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> bottmAngle : <span style="color: #0066CC;">Number</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CircularSlider<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calcAngles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drawCircle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initAngle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, onEF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> calcAngles<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; topAngle = _startAngle - _angleRange - <span style="color: #cc66cc;">90</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; topAngle = topAngle <span style="color: #66cc66;">/</span> 180 <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bottmAngle = _startAngle + _angleRange - <span style="color: #cc66cc;">90</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bottmAngle = bottmAngle <span style="color: #66cc66;">/</span> 180 <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initAngle<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>_angleShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> drawAngle<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>2, 0xff0000<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>2, 0x00ff00<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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>bottmAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>bottmAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>2, 0xff0000<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> drawCircle<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>1,0xffffff<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span>0, 0, _radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>_circ<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onEF<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleRange = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">/</span>2 - mouseX<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;calcAngles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;drawAngle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Next, I needed to place the scroll handlebar at the top of the sweep (top of green line in picture), and have it be draggable to the bottom of the sweep. To do that, I calculated the X,Y position of the top and bottom (which I already have in the code), and upon click, I created a rectangle that represented the bounding box for the drag operation. Then, I calculated the percentage point of the handle inside that bounding box to get the 0-1 result, and using the Y position, extracted what the X position would be:</p>
<p><a rel="shadowbox;width=600;height=600;" href="http://www.asseo.net/blog_files/flash/circ_slider_bounding_box.swf"><img src="http://www.asseo.net/labs/wp-content/uploads/2010/01/Picture-2-210x300.png" alt="" title="Picture 2" width="210" height="300" class="alignnone size-medium wp-image-224" /></a></p>
<p>The only problem is that now, when I remove the guides (the circle and angles), I am left with only the slider&#8230; and I need the arc so the slider has some visual representation. There are 2 solutions for that. Simple solution: mask the circle&#8230; easy to do. here&#8217;s the result:</p>
<p><a rel="shadowbox;width=600;height=600;" href="http://www.asseo.net/blog_files/flash/circ_slider_mask.swf"><img src="http://www.asseo.net/labs/wp-content/uploads/2010/01/Picture-3-261x300.png" alt="" title="Picture 3" width="261" height="300" class="alignnone size-medium wp-image-226" /></a></p>
<p>A solution that&#8217;s a bit more complex is to DRAW the arc.. that&#8217;s where I was happy to find this <a href="http://algorithmist.wordpress.com/2009/12/01/drawing-circular-segments-in-actionscript/" target="_blank">nice post by the algorythmist</a>.  So, using this code, you can then create a nice circular slider:</p>
<p><a rel="shadowbox;width=600;height=600;" href="http://www.asseo.net/blog_files/flash/circ_slider_arc.swf"><img src="http://www.asseo.net/labs/wp-content/uploads/2010/01/Picture-4.png" alt="" title="Picture 4" width="107" height="293" class="alignnone size-full wp-image-228" /></a></p>
<p>now all that&#8217;s left to do is output the percentage from the slider and you got yourself a nice circular slider!</p>
<p>here&#8217;s the final code:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:800px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package &nbsp;<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Rectangle</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* @author iasseo<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CircularSlider <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _circ : Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _startAngle : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">90</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _angleRange : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">30</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _angleShape : Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _radius : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">250</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> topAngle : <span style="color: #0066CC;">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> bottmAngle : <span style="color: #0066CC;">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _handle : Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _box : Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _handleHolder : Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _mask : Sprite;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CircularSlider<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calcAngles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drawCircle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initAngle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drawAngle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drawSegments<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createHandle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createHandle<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handleHolder = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handleHolder.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handleHolder.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>_handleHolder<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xcccccc<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span>0, 0, 10<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handleHolder.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>_handle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, onStartDrag<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onStartDrag<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : MouseEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; makeBox<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drawBox<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rect : Rectangle = _box.<span style="color: #006600;">getRect</span><span style="color: #66cc66;">&#40;</span>_box<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #0066CC;">startDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span>, rect<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, <span style="color: #0066CC;">onMouseMove</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, onStopDrag<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onMouseMove</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : MouseEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">updateAfterEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> rect : Rectangle = _box.<span style="color: #006600;">getRect</span><span style="color: #66cc66;">&#40;</span>_box<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> dist : <span style="color: #0066CC;">Number</span> = rect.<span style="color: #0066CC;">height</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> per : <span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span>_handle.<span style="color: #006600;">y</span> + dist<span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span>dist;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> a : <span style="color: #0066CC;">Number</span> = _startAngle - _angleRange;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> b : <span style="color: #0066CC;">Number</span> = _startAngle + _angleRange;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> r : <span style="color: #0066CC;">Number</span> = b-a;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> targetAngle :<span style="color: #0066CC;">Number</span> = a + r<span style="color: #66cc66;">*</span>per;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; targetAngle = targetAngle <span style="color: #66cc66;">/</span> 180 <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>targetAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius + <span style="color: #cc66cc;">2</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onStopDrag<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : MouseEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeBox<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #0066CC;">stopDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _handle.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, <span style="color: #0066CC;">onMouseMove</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, onStopDrag<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, <span style="color: #0066CC;">onMouseMove</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> removeBox<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeChild<span style="color: #66cc66;">&#40;</span>_box<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> drawBox<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>1,0xffffff, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</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>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>_radius, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>_radius, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>bottmAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>bottmAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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>bottmAngle<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> _radius, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> makeBox<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">mouseEnabled</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _box.<span style="color: #006600;">mouseChildren</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>_box<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> calcAngles<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; topAngle = _startAngle - _angleRange - <span style="color: #cc66cc;">90</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; topAngle = topAngle <span style="color: #66cc66;">/</span> 180 <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bottmAngle = _startAngle + _angleRange - <span style="color: #cc66cc;">90</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bottmAngle = bottmAngle <span style="color: #66cc66;">/</span> 180 <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> drawSegments<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>2, 0x0000ff<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// FROM THE ALGORYTHMIST -- http://algorithmist.wordpress.com/2009/12/01/drawing-circular-segments-in-actionscript/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// now that start and end angle are fixed, draw a set of quads no more than PI/4 in arc at once</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> angleDelta:<span style="color: #0066CC;">Number</span> = bottmAngle - topAngle;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> numSeg:<span style="color: #0066CC;">Number</span> &nbsp; &nbsp; = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">ceil</span><span style="color: #66cc66;">&#40;</span>angleDelta<span style="color: #66cc66;">*</span>4.0<span style="color: #66cc66;">/</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> arc:<span style="color: #0066CC;">Number</span> &nbsp; &nbsp; &nbsp; &nbsp;= angleDelta<span style="color: #66cc66;">/</span>numSeg;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// p is the vector from the origin of the wedge to (p0X,p0Y)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// q is the vector from the origin of the wedge to (p2X,p2Y)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// the vector p+q bisects the angle between p and q. &nbsp;The middle interpolation point is</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// 'radius' units along that bisector.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> pX:<span style="color: #0066CC;">Number</span> &nbsp; &nbsp;= _radius<span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> pY:<span style="color: #0066CC;">Number</span> &nbsp; &nbsp;= _radius<span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> p0X:<span style="color: #0066CC;">Number</span> &nbsp; = pX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> p0Y:<span style="color: #0066CC;">Number</span> &nbsp; = pY;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> qX:<span style="color: #0066CC;">Number</span> &nbsp; &nbsp;= <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> qY:<span style="color: #0066CC;">Number</span> &nbsp; &nbsp;= <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> angle:<span style="color: #0066CC;">Number</span> = topAngle;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// initial point at startAngle</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> startX:<span style="color: #0066CC;">Number</span> = _radius<span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> startY:<span style="color: #0066CC;">Number</span> = _radius<span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span> startX, startY <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> radInv:<span style="color: #0066CC;">Number</span> = 1.0<span style="color: #66cc66;">/</span>_radius;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// approximate each arc with a quad. Bezier</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> i:uint=<span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>numSeg; ++i <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle &nbsp; &nbsp; &nbsp; &nbsp; += arc;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; qX &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = _radius<span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; qY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = _radius<span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> p2X:<span style="color: #0066CC;">Number</span> = qX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> p2Y:<span style="color: #0066CC;">Number</span> = qY;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// unit vector in direction of bisector - alternative approach is two more trig. calcs to compute the coordinates.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// let's have some fun and do it a different way.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> dX:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span>pX+qX<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>radInv;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> dY:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span>pY+qY<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>radInv;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> d:<span style="color: #0066CC;">Number</span> &nbsp;= <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sqrt</span><span style="color: #66cc66;">&#40;</span>dX<span style="color: #66cc66;">*</span>dX + dY<span style="color: #66cc66;">*</span>dY<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dX <span style="color: #66cc66;">/</span>= d;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dY <span style="color: #66cc66;">/</span>= d;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// middle interpolation point is a distance of 'radius' units along direction of bisecting unit vector</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> p1X:<span style="color: #0066CC;">Number</span> = _radius<span style="color: #66cc66;">*</span>dX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> p1Y:<span style="color: #0066CC;">Number</span> = _radius<span style="color: #66cc66;">*</span>dY;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// compute control point so that quad. Bezier passes through (p0X,p0Y), (p1X,p1Y), and (p2X,p2Y) at t=0.5</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> cX:<span style="color: #0066CC;">Number</span> = 2.0<span style="color: #66cc66;">*</span>p1X - 0.5<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>p0X + p2X<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> cY:<span style="color: #0066CC;">Number</span> = 2.0<span style="color: #66cc66;">*</span>p1Y - 0.5<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>p0Y + p2Y<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// You can compute the control point directly with nothing but sin &amp; cos, but if memory serves it takes</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// four more trig comps. for a total of six per loop iteration.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">curveTo</span><span style="color: #66cc66;">&#40;</span>cX, cY, p2X, p2Y<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// end point is start point for next iteration</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p0X = p2X;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p0Y = p2Y;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pX &nbsp;= qX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pY &nbsp;= qY;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initAngle<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>_angleShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> drawAngle<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>2, 0xff0000<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>topAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>2, 0x00ff00<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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>bottmAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>bottmAngle<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>_radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>2, 0xff0000<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angleShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> drawCircle<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>1,0xffffff<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span>0, 0, _radius<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&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;">// TO MASK OUT THE CIRCLE, YOU CAN USE THIS:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/*_mask = new Sprite();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _mask.x = stage.stageWidth/2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _mask.y = stage.stageHeight/2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _mask.mouseEnabled = false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _mask.mouseChildren = false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild(_mask);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _mask.graphics.beginFill(0xff0000, 1);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _mask.graphics.drawRect(Math.cos(topAngle)*_radius, Math.sin(topAngle)*_radius, _radius-Math.cos(topAngle)*_radius + 1, _radius/2-Math.sin(topAngle)*_radius);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _circ.<span style="color: #006600;">mask</span> = _mask;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>_circ<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptingaction.com/?feed=rss2&amp;p=218</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Drawing Snowflakes: Part 1</title>
		<link>http://www.scriptingaction.com/?p=185</link>
		<comments>http://www.scriptingaction.com/?p=185#comments</comments>
		<pubDate>Thu, 07 Jan 2010 17:37:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scriptingaction.com/?p=185</guid>
		<description><![CDATA[So, like I said in my last post, I&#8217;m going to dedicate these few next posts to go over some of the techniques I used to create Flurrious.com.
The first thing I want to go over is the creation of the drawing application. The architecture of it is pretty simple, but crucial to making it work [...]]]></description>
			<content:encoded><![CDATA[<p>So, like I said in my last post, I&#8217;m going to dedicate these few next posts to go over some of the techniques I used to create <a href="http://www.flurrious.com" target="_blank">Flurrious.com</a>.</p>
<p>The first thing I want to go over is the creation of the drawing application. The architecture of it is pretty simple, but crucial to making it work well, and having it be extendable and modular. My first step was to create the canvas. since a snowflake has an <a href="http://www.its.caltech.edu/~atomic/snowcrystals/faqs/faqs.htm" target="_blank">ice crystal formation</a>, it has to have 6 sides.  So my first step is to draw 6 triangles that form a hexagon:</p>
<p><img class="alignnone size-full wp-image-186" title="flakestage" src="http://www.asseo.net/labs/wp-content/uploads/2010/01/flakestage.jpg" alt="" width="250" height="198" /></p>
<p>The code for this is pretty simple, looks like this:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:250px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package &nbsp;<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* @author iasseo<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SnowFlake <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> const SLICES : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">6</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> const RADIUS : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">300</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _sliceArray : <span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _angle : <span style="color: #0066CC;">Number</span>; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SnowFlake<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angle = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> <span style="color: #66cc66;">/</span> SLICES;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createFlakeStage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createFlakeStage<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> n : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;n <span style="color: #66cc66;">&lt;</span> SLICES; n++<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: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">slice</span> : Sprite = createSlice<span style="color: #66cc66;">&#40;</span>_angle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">rotation</span> = 360 <span style="color: #66cc66;">/</span> SLICES <span style="color: #66cc66;">*</span> n;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _sliceArray.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">slice</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">slice</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createSlice<span style="color: #66cc66;">&#40;</span>angle : <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> : Sprite<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">slice</span> : Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>1,0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0,.1<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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><span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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>-<span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>0,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">slice</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Now, even though this is my canvas which I&#8217;m using to capture the mouse events, I&#8217;m going to draw the actual shapes on a separate Sprite, so I can have better control. In order to do that, I&#8217;m going to place 6 empty Sprites in the center of the hexagon, each one rotated, just like the triangles I drew.  I&#8217;ll add a new function &#8211; createShapeHolders() &#8211; to the constructor (notice that I&#8217;m disabling all MouseEvents for these &#8217;shapes&#8217;, because I want to control them from the canvas I drew earlier). For each of the triangles (which are separate Sprites), I&#8217;m going to add a MouseEvent, which will trigger the drawing application. I&#8217;m going to add that to the &#8216;for loop&#8217; in the createFlakeStage() function, and I&#8217;m also adding 3 MouseEvent functions: beginShape, renderShape and endShape.</p>
<p>When I click on any of the triangles now, beginShape() will save the slice I clicked on as _slice (added as a private var to the class), and trigger a MOUSE_MOVE event. Then, as I move the mouse, the renderShape() function will draw on all 6 sides of the hexagon:</p>
<p><a rel="shadowbox;width=1000;height=600;" href="http://www.asseo.net/blog_files/flash/snowflake_stage1.swf" bgcolor:"#ffffff"'><img src="http://www.asseo.net/labs/wp-content/uploads/2010/01/flake_stage1.jpg" alt="" title="flake_stage1" width="250" height="211" class="alignnone size-full wp-image-198" /><BR>CLICK TO SEE THIS IN ACTION</a></p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:250px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package &nbsp;<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* @author iasseo<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SnowFlake <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> const SLICES : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">6</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> const RADIUS : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">300</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _sliceArray : <span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _angle : <span style="color: #0066CC;">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _shapeHolders : Vector.<span style="color: #66cc66;">&lt;</span>Sprite<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Sprite<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _slice : Sprite; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SnowFlake<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angle = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> <span style="color: #66cc66;">/</span> SLICES;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createFlakeStage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createShapeHolders<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createShapeHolders<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> n : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;n <span style="color: #66cc66;">&lt;</span> SLICES; n++<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: #000000; font-weight: bold;">var</span> shape : Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">mouseEnabled</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">mouseChildren</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _shapeHolders.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>shape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">rotation</span> = 360 <span style="color: #66cc66;">/</span> SLICES <span style="color: #66cc66;">*</span> n;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>shape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createFlakeStage<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> n : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;n <span style="color: #66cc66;">&lt;</span> SLICES; n++<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: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">slice</span> : Sprite = createSlice<span style="color: #66cc66;">&#40;</span>_angle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">rotation</span> = 360 <span style="color: #66cc66;">/</span> SLICES <span style="color: #66cc66;">*</span> n;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, beginShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">alpha</span> = <span style="color: #cc66cc;">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _sliceArray.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">slice</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">slice</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createSlice<span style="color: #66cc66;">&#40;</span>angle : <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> : Sprite<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">slice</span> : Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>1,0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0,.1<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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><span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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>-<span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>0,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">slice</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> beginShape<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : MouseEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _slice = <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span> as Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;i <span style="color: #66cc66;">&lt;</span> SLICES; 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; _shapeHolders<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>1,0xFFFFFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _shapeHolders<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>_slice.<span style="color: #006600;">mouseX</span>, _slice.<span style="color: #006600;">mouseY</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, renderShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, endShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> renderShape<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : MouseEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;i <span style="color: #66cc66;">&lt;</span> SLICES; 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; _shapeHolders<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>_slice.<span style="color: #006600;">mouseX</span>, _slice.<span style="color: #006600;">mouseY</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> endShape<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : MouseEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, renderShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, endShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Now the only problem is that it doesn&#8217;t look like a symmetrical drawing&#8230; it basically copies the shape you&#8217;re drawing and places it in a circle.  Now we need to add a reflection to the shape. So, to do that, we&#8217;ll have to add 2 Sprites to each of the &#8217;shapes&#8217; we created in the createShapeHolders() function.  One of those shapes we&#8217;ll flip horizontally (scaleX = -1) and then, each time we trigger beginShape and renderShape, we&#8217;ll use the FP10 copyFrom() function to create a reflection effect. All we have left to do now is to hide the canvases, and start drawing! here is the result:</p>
<p><a rel="shadowbox;width=1000;height=600;" href="http://www.asseo.net/blog_files/flash/snowflake_stage2.swf"><img src="http://www.asseo.net/labs/wp-content/uploads/2010/01/flake_drawing.jpg" alt="" title="flake_drawing" width="250" height="219" class="alignnone size-full wp-image-207" /><BR>CLICK HERE TO SEE IT IN ACTION &#8211; CLICK AND DRAG NEAR THE CENTER OF THE STAGE</a></p>
<p>and here is the final code:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:800px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package &nbsp;<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* @author iasseo<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SnowFlake <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> const SLICES : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">6</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> const RADIUS : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">300</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _sliceArray : <span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _angle : <span style="color: #0066CC;">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _shapeHolders : Vector.<span style="color: #66cc66;">&lt;</span>Sprite<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Sprite<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _slice : Sprite; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SnowFlake<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _angle = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> <span style="color: #66cc66;">/</span> SLICES;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createFlakeStage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createShapeHolders<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createShapeHolders<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> n : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;n <span style="color: #66cc66;">&lt;</span> SLICES; n++<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: #000000; font-weight: bold;">var</span> shape : Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">mouseEnabled</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">mouseChildren</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>1<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">scaleX</span> = -<span style="color: #cc66cc;">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _shapeHolders.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>shape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">rotation</span> = 360 <span style="color: #66cc66;">/</span> SLICES <span style="color: #66cc66;">*</span> n;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>shape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createFlakeStage<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> n : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;n <span style="color: #66cc66;">&lt;</span> SLICES; n++<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: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">slice</span> : Sprite = createSlice<span style="color: #66cc66;">&#40;</span>_angle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">rotation</span> = 360 <span style="color: #66cc66;">/</span> SLICES <span style="color: #66cc66;">*</span> n;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, beginShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">alpha</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _sliceArray.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">slice</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">slice</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createSlice<span style="color: #66cc66;">&#40;</span>angle : <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> : Sprite<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">slice</span> : Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>1,0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0,.1<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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><span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</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>-<span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS, <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #66cc66;">&#40;</span>angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>0,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_angle<span style="color: #66cc66;">&#41;</span>-<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span>RADIUS<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">slice</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">slice</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> beginShape<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : MouseEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _slice = <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span> as Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;i <span style="color: #66cc66;">&lt;</span> SLICES; 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: #000000; font-weight: bold;">var</span> side1 : Sprite = _shapeHolders<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>0<span style="color: #66cc66;">&#41;</span> as Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> side2 : Sprite = _shapeHolders<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>1<span style="color: #66cc66;">&#41;</span> as Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side1.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>1,0xFFFFFF<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side1.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>_slice.<span style="color: #006600;">mouseX</span>, _slice.<span style="color: #006600;">mouseY</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side2.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">copyFrom</span><span style="color: #66cc66;">&#40;</span>side1.<span style="color: #006600;">graphics</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, renderShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, endShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> renderShape<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : MouseEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;i <span style="color: #66cc66;">&lt;</span> SLICES; 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: #000000; font-weight: bold;">var</span> side1 : Sprite = _shapeHolders<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>0<span style="color: #66cc66;">&#41;</span> as Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> side2 : Sprite = _shapeHolders<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>1<span style="color: #66cc66;">&#41;</span> as Sprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side1.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>_slice.<span style="color: #006600;">mouseX</span>, _slice.<span style="color: #006600;">mouseY</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side2.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">copyFrom</span><span style="color: #66cc66;">&#40;</span>side1.<span style="color: #006600;">graphics</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> endShape<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span> : MouseEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, renderShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, endShape<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptingaction.com/?feed=rss2&amp;p=185</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flurrious.com</title>
		<link>http://www.scriptingaction.com/?p=181</link>
		<comments>http://www.scriptingaction.com/?p=181#comments</comments>
		<pubDate>Wed, 06 Jan 2010 16:40:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scriptingaction.com/?p=181</guid>
		<description><![CDATA[I haven&#8217;t posted anything is the past few weeks because I was busy working on Flurrious.com &#8212; Digitas&#8217; &#8216;09 holiday card.  It let&#8217;s you draw a snowflake and send it to a friend &#8212; and watch all of the other snowflakes other people make.  For each snowflake sent, Digitas donates $1 to UNICEF.
The site has [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t posted anything is the past few weeks because I was busy working on <a href="http://www.Flurrious.com" target="_blank">Flurrious.com</a> &#8212; Digitas&#8217; &#8216;09 holiday card.  It let&#8217;s you draw a snowflake and send it to a friend &#8212; and watch all of the other snowflakes other people make.  For each snowflake sent, Digitas donates $1 to UNICEF.</p>
<p>The site has done MUCH better than expected &#8212; over 23,000 snowflakes were made (in less than 2 weeks), and almost $7,000 donated to UNICEF. The site is pretty small at 200kb, but so far we&#8217;ve served over 600GB of data to users (most of it is probably the snowflakes that are being saved as PNGs on the server).</p>
<p><a href="http://www.flurrious.com" target="_blank"><img class="alignnone size-medium wp-image-182" title="flurrious" src="http://www.asseo.net/labs/wp-content/uploads/2010/01/flurrious-300x195.jpg" alt="flurrious" width="300" height="195" /></a></p>
<p>To create this application I had to do an extensive brush-up on my flash drawing API skills.  I&#8217;m using some of the new features from FP10 like IGraphicsPath and the 3D rotations (as well as Papervision3D). That graphics data is being saved in Vector arrays, and is stored on the database.  When you view a snowflake, that data is being passed back to flash, and then get&#8217;s drawn again with the same API.</p>
<p>In the next few posts I&#8217;ll talk about some of the techniques I used to create the application.  some of the highlights in my opinion are: saving and recreating vector data, creating smooth lines, and creating the circular slidres.  Creating the snowflake generative drawing I think was the least challenging thing in the site&#8230;</p>
<p>-itai</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptingaction.com/?feed=rss2&amp;p=181</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Looping videos in Papervision3D</title>
		<link>http://www.scriptingaction.com/?p=177</link>
		<comments>http://www.scriptingaction.com/?p=177#comments</comments>
		<pubDate>Mon, 16 Nov 2009 18:10:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[papervision3D]]></category>

		<guid isPermaLink="false">http://www.scriptingaction.com/?p=177</guid>
		<description><![CDATA[I was working on an Augmented Reality bit this weekend which involved a looping video. Normally this is a harmless operation which involves a simple onStreamStatus event, that by passing a &#8220;NetStream.Play.Stop&#8221; triggers a _netStream.seek(0); function.  But when I tried that in PV3d the video would not loop&#8230; it was pretty frustrating, but eventually [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on an Augmented Reality bit this weekend which involved a looping video. Normally this is a harmless operation which involves a simple onStreamStatus event, that by passing a &#8220;NetStream.Play.Stop&#8221; triggers a _netStream.seek(0); function.  But when I tried that in PV3d the video would not loop&#8230; it was pretty frustrating, but eventually I figured out that the VideoStreamMaterial class in the Papervision3D package stopped rendering upon a &#8220;NetStream.Play.Stop&#8221; event, but didn&#8217;t resume it on a &#8220;NetStream.Seek.Notify&#8221; event, which I had to manually add.<br />
<BR><BR><br />
this is how the function looks like after the change:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">private function onStreamStatus ( event:NetStatusEvent ):void<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch ( event.info.code )<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;NetStream.Play.Start&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animated = true;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;NetStream.Unpause.Notify&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animated = true;&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;NetStream.Seek.Notify&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animated = true;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;NetStream.Play.Failed&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animated = false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;NetStream.Play.Stop&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animated = false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;NetStream.Play.StreamNotFound&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animated = false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;NetStream.Pause.Notify&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animated = false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; }</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptingaction.com/?feed=rss2&amp;p=177</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bitmap division and animation with simple API</title>
		<link>http://www.scriptingaction.com/?p=168</link>
		<comments>http://www.scriptingaction.com/?p=168#comments</comments>
		<pubDate>Tue, 10 Nov 2009 19:42:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Effects]]></category>

		<guid isPermaLink="false">http://www.scriptingaction.com/?p=168</guid>
		<description><![CDATA[I&#8217;m continuing my efforts to create an easy-to-use effect library.  For now I&#8217;m concentrating on 2D matrix effects &#8212; the previous one was halfTone.  This one is a devision of an image (or any displayObjects for that matter) into smaller segments.
here&#8217;s what it looks like (click to watch animation):

here is the code involved [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m continuing my efforts to create an easy-to-use effect library.  For now I&#8217;m concentrating on 2D matrix effects &#8212; the previous one was halfTone.  This one is a devision of an image (or any displayObjects for that matter) into smaller segments.</p>
<p>here&#8217;s what it looks like (click to watch animation):<br />
<a rel="shadowbox;width=900;height=600;" href="http://www.asseo.net/blog_files/flash/devide.swf"><img src="http://www.asseo.net/labs/wp-content/uploads/2009/11/Picture-10-300x198.png" alt="Picture 10" title="Picture 10" width="300" height="198" class="alignnone size-medium wp-image-169" /></a></p>
<p>here is the code involved with using the effect:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">devide = <span style="color: #000000; font-weight: bold;">new</span> Devide<span style="color: #66cc66;">&#40;</span>_loadedBitmap, 12, 0x000000<span style="color: #66cc66;">&#41;</span>; <br />
addChild<span style="color: #66cc66;">&#40;</span>devide<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
devide.<span style="color: #006600;">swipeLeftToRight</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
seq = <span style="color: #000000; font-weight: bold;">new</span> TimelineLite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>onComplete:restartTween<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;<br />
seq.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span>TweenLite.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>devide, 1, <span style="color: #66cc66;">&#123;</span>swipeLeftToRight:1<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
seq.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>devide, 1, <span style="color: #66cc66;">&#123;</span>swipeRightToLeft:0<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
seq.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>devide, 1, <span style="color: #66cc66;">&#123;</span>swipeTopToBottom:1<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
seq.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>devide, 1, <span style="color: #66cc66;">&#123;</span>swipeBottomToTop:0<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>It is based on my previous work that I <a href="http://www.scriptingaction.com/?p=37">posted here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptingaction.com/?feed=rss2&amp;p=168</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Halftone effect with simple API</title>
		<link>http://www.scriptingaction.com/?p=153</link>
		<comments>http://www.scriptingaction.com/?p=153#comments</comments>
		<pubDate>Thu, 05 Nov 2009 16:18:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Effects]]></category>

		<guid isPermaLink="false">http://www.scriptingaction.com/?p=153</guid>
		<description><![CDATA[I started working on an effect library with an easy-to-use API which will be easily attached to any tweening engine.  I&#8217;m still working hard on the API and on how the whole thing is architectured, so I&#8217;m not going to include source code this time, but to give you a glimpse of how this [...]]]></description>
			<content:encoded><![CDATA[<p>I started working on an effect library with an easy-to-use API which will be easily attached to any tweening engine.  I&#8217;m still working hard on the API and on how the whole thing is architectured, so I&#8217;m not going to include source code this time, but to give you a glimpse of how this is going to look, here&#8217;s an example of the Halftone effect which is going to be part of the Matrix2D package (it will include stuff like pixelate and explode effects).</p>
<p>the following effect is achieved simply by typing the following:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">halfTone = <span style="color: #000000; font-weight: bold;">new</span> HalfTone<span style="color: #66cc66;">&#40;</span>_loadedBitmap, 16<span style="color: #66cc66;">&#41;</span>;<br />
addChild<span style="color: #66cc66;">&#40;</span>halfTone<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>but the fun part is animating the effect with a simple API.  I&#8217;m using the new <a href="http://blog.greensock.com/v11/" target="_blank">TweenLite v11</a>, but any tween engine or really any other way (like controlling the swipe with the position of the mouse).  here&#8217;s how I&#8217;m creating the different swipes in the example below:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">halfTone.<span style="color: #006600;">swipeLeftToRight</span> = <span style="color: #cc66cc;">0</span>;<br />
seq = <span style="color: #000000; font-weight: bold;">new</span> TimelineLite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>onComplete:restartTween<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;<br />
seq.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>halfTone, 1, <span style="color: #66cc66;">&#123;</span>swipeLeftToRight:1<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
seq.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>halfTone, 1, <span style="color: #66cc66;">&#123;</span>swipeRightToLeft:0<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
seq.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>halfTone, 1, <span style="color: #66cc66;">&#123;</span>swipeTopToBottom:1<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>,1<span style="color: #66cc66;">&#41;</span>;<br />
seq.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>halfTone, 1, <span style="color: #66cc66;">&#123;</span>swipeBottomToTop:0<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
seq.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>halfTone, 1, <span style="color: #66cc66;">&#123;</span>swipeTLtoBR:1<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>,1<span style="color: #66cc66;">&#41;</span>;<br />
seq.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>halfTone, 1, <span style="color: #66cc66;">&#123;</span>swipeTLtoBR:0<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p><a rel="shadowbox;width=900;height=600;" href="http://www.asseo.net/blog_files/flash/halftone_effect.swf"><img src="http://www.asseo.net/labs/wp-content/uploads/2009/11/Picture-4-300x199.png" alt="Picture 4" title="Picture 4" width="300" height="199" class="alignnone size-medium wp-image-156" /></a></p>
<p>Special thanks to Joe Ferrari for helping me through the diagonal array math (still working on the BottomLeft to TopRight swipe)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptingaction.com/?feed=rss2&amp;p=153</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Grid Positioning v2</title>
		<link>http://www.scriptingaction.com/?p=150</link>
		<comments>http://www.scriptingaction.com/?p=150#comments</comments>
		<pubDate>Sun, 01 Nov 2009 03:12:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scriptingaction.com/?p=150</guid>
		<description><![CDATA[after some thought of how to make this more practical, I decided to make another version.  
In this version the 2 boxes next to the selected box and the 2 above and below grow as well, and the response and alignment is much better.
here&#8217;s what it looks like now:

here is the source
]]></description>
			<content:encoded><![CDATA[<p>after some thought of how to make this more practical, I decided to make another version.  </p>
<p>In this version the 2 boxes next to the selected box and the 2 above and below grow as well, and the response and alignment is much better.</p>
<p>here&#8217;s what it looks like now:</p>
<p><a rel="shadowbox;width=400;height=400;" href="http://www.asseo.net/blog_files/flash/gridDynamics2.swf"><img src="http://www.asseo.net/labs/wp-content/uploads/2009/10/Picture-7-299x300.png" alt="Picture 7" title="Picture 7" width="299" height="300" class="alignnone size-medium wp-image-151" /></a></p>
<p>here is <a href="http://www.asseo.net/blog_files/source/grid_dynamics2.zip">the source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptingaction.com/?feed=rss2&amp;p=150</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
