<?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>nightdrops.com &#187; quickreference</title>
	<atom:link href="http://www.nightdrops.com/tag/quickreference/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nightdrops.com</link>
	<description>like the color blue</description>
	<lastBuildDate>Thu, 01 Jul 2010 13:19:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Quickreference: flipping DisplayObjects</title>
		<link>http://www.nightdrops.com/2010/quickreference-flipping-displayobjects/</link>
		<comments>http://www.nightdrops.com/2010/quickreference-flipping-displayobjects/#comments</comments>
		<pubDate>Wed, 19 May 2010 10:00:04 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[quickreference]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/?p=387</guid>
		<description><![CDATA[This one flips DisplayObjects on a vertical or horizontal axe. public static function flipHorizontal(obj:DisplayObject):void { &#160; &#160; var m:Matrix = obj.transform.matrix; &#160; &#160; m.transformPoint(new Point(obj.width * .5, obj.height * .5)); &#160; &#160; m.tx = (m.a &#62; 0)?obj.width + obj.x:obj.x - obj.width;&#160; &#160; &#160; &#160; &#160; &#160; &#160; m.a = -1 * m.a; &#160; &#160; obj.transform.matrix [...]]]></description>
			<content:encoded><![CDATA[<p>This one flips DisplayObjects on a vertical or horizontal axe.<br />
</p><p></p><div class='code' style='overflow: auto; white-space:nowrap;'>public static function flipHorizontal(obj:DisplayObject):void {<br />
&nbsp; &nbsp; var m:Matrix = obj.transform.matrix;<br />
&nbsp; &nbsp; m.transformPoint(new Point(obj.width * .5, obj.height * .5));<br />
&nbsp; &nbsp; m.tx = (m.a &gt; 0)?obj.width + obj.x:obj.x - obj.width;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; m.a = -1 * m.a;<br />
&nbsp; &nbsp; obj.transform.matrix = m;<br />
}<br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
public static function flipVertical(obj:DisplayObject):void {<br />
&nbsp; &nbsp; var m:Matrix = obj.transform.matrix;<br />
&nbsp; &nbsp; m.transformPoint(new Point(obj.width * .5, obj.height * .5));<br />
&nbsp; &nbsp; m.ty = (m.d &gt; 0)?obj.y + obj.height:obj.y - obj.height;<br />
&nbsp; &nbsp; m.d = -1 * m.d;<br />
&nbsp; &nbsp; obj.transform.matrix = m;<br />
}</div><p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2010/quickreference-flipping-displayobjects/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Basic random functions</title>
		<link>http://www.nightdrops.com/2009/basic-random-functions/</link>
		<comments>http://www.nightdrops.com/2009/basic-random-functions/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 13:53:26 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[quickreference]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/?p=270</guid>
		<description><![CDATA[Here are some really basic (but useful) functions that returns random stuff&#8230; The really basic one, is built in the Flash api and it returns a Number between 0 and 1: var n:Number = Math.random&#40;&#41;; A number in  a range Sometime is more useful to have a random number in a different range, let&#8217;s say [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some really basic (but useful) functions that returns random stuff&#8230;</p>
<p>The really basic one, is built in the Flash api and it returns a <code class="codecolorer actionscript default"><span class="actionscript"><span style="color: #0066CC;">Number</span></span></code> between 0 and 1:</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: #000000; font-weight: bold;">var</span> n:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<h4>A number in  a range</h4>
<p>Sometime is more useful to have a random number in a different range, let&#8217;s say between 15 and 45, instead of 0 and 1.</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: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> randNumber<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">max</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1</span>, <span style="color: #0066CC;">min</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">max</span> - <span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">min</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<h4>Random int</h4>
<p>and what if we don&#8217;t need decimals? Round&#8217;em!</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: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> randInt<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">max</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1</span>, <span style="color: #0066CC;">min</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">max</span> - <span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<h4>Random boolean</h4>
<p>True or false? Flip a coin.</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: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> bool<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<h4>Random sign</h4>
<p>-1 or 1; Useful when you have to random select random rotation verse, for example, -1*45 or 1*45, rotates counterclockwise or clockwise.</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: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> sign<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>:-<span style="color: #cc66cc;">1</span>:<span style="color: #cc66cc;">1</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<h4>Random color</h4>
<p>Really useful when drawing debug shapes on screen..</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: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">color</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:uint <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> 0xFFFFFF;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<h4>Random point</h4>
<p>Inside an area. I like to use the flash.geom.Rectangle struct to describe an area, more than using 4 parameters (Flash api are quite inconsistent about this choice)</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: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> point<span style="color: #66cc66;">&#40;</span>area:Rectangle<span style="color: #66cc66;">&#41;</span>:Point <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>randInt<span style="color: #66cc66;">&#40;</span>area.<span style="color: #006600;">x</span>, area.<span style="color: #006600;">x</span> + area.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span>, randInt<span style="color: #66cc66;">&#40;</span>area.<span style="color: #006600;">y</span>, area.<span style="color: #006600;">y</span> + area.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2009/basic-random-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quickreference: display elements in a circle</title>
		<link>http://www.nightdrops.com/2009/quickreference-display-elements-in-a-circle/</link>
		<comments>http://www.nightdrops.com/2009/quickreference-display-elements-in-a-circle/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 13:00:54 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[quickreference]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/?p=227</guid>
		<description><![CDATA[How to display elements in a circle? A small function to do that is: GeSHi Error: GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2) Parameters are: items: the items to be displayed a a circle center: the center of the circle distance: the distance from the center initialAngle: the angle of [...]]]></description>
			<content:encoded><![CDATA[<p>How to display elements in a circle? A small function to do that is:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><br /><strong>GeSHi Error:</strong> GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)<br /></div>
<p>Parameters are:</p>
<ul>
<li>items: the items to be displayed a a circle</li>
<li>center: the center of the circle</li>
<li>distance: the distance from the center</li>
<li>initialAngle: the angle of the first item. Zero means that the item wil be aligned orizontally with the center, on his right.</li>
</ul>
<p>Here&#8217;s an example:</p>
<p><object style="width: 400px; height: 300px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/wp-content/uploads/2009/07/CircleSortingExample.swf" /><embed style="width: 400px; height: 300px;" type="application/x-shockwave-flash" width="400" height="300" src="/wp-content/uploads/2009/07/CircleSortingExample.swf"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2009/quickreference-display-elements-in-a-circle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tweening global volume in flash</title>
		<link>http://www.nightdrops.com/2009/tweening-global-volume-in-flash/</link>
		<comments>http://www.nightdrops.com/2009/tweening-global-volume-in-flash/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 14:22:12 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[quickreference]]></category>
		<category><![CDATA[TweenLite]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/?p=217</guid>
		<description><![CDATA[Just a quick reminder on how to shut up the master volume on a flash project. I like a smooth tween to the silence, so I&#8217;m using the TweenLite libraries. GeSHi Error: GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2) The trick here is to tween the volume property of a [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick reminder on how to shut up the master volume on a flash project. I like a smooth tween to the silence, so I&#8217;m using the TweenLite libraries.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><br /><strong>GeSHi Error:</strong> GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)<br /></div>
<p>The trick here is to tween the volume property of a throw-away SoundTransform object, and on each step of the Tween apply that object as the SoundMixer.soundTransform Object, with an helper function. Note that I&#8217;m not going to write the function inside the TweenLite&#8217;s partameter list, as it is gross and dirty.</p>
<p>Tweening the volume back to 1 is so easy that I&#8217;m not writing it, to not offend anyone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2009/tweening-global-volume-in-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick reference: Drawing a scaled object in Actionscript</title>
		<link>http://www.nightdrops.com/2009/quick-reference-drawing-a-scaled-object-in-actionscript/</link>
		<comments>http://www.nightdrops.com/2009/quick-reference-drawing-a-scaled-object-in-actionscript/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 09:43:52 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[quickreference]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/?p=167</guid>
		<description><![CDATA[Just as a quick reference, since I usually forgot each time how to do it. Assume to have a DisplayObject obj, you want to draw in a Bitmap a scaled snapshot of that object. Just like when you are drawing thumbs. GeSHi Error: GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)]]></description>
			<content:encoded><![CDATA[<p>Just as a quick reference, since I usually forgot each time how to do it.</p>
<p>Assume to have a DisplayObject obj, you want to draw in a Bitmap a scaled snapshot of that object.</p>
<p>Just like when you are drawing thumbs.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><br /><strong>GeSHi Error:</strong> GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)<br /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2009/quick-reference-drawing-a-scaled-object-in-actionscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fading out and detaching</title>
		<link>http://www.nightdrops.com/2009/fading-out-and-detaching/</link>
		<comments>http://www.nightdrops.com/2009/fading-out-and-detaching/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 10:27:31 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[quickreference]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[TweenLite]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/blog/?p=10</guid>
		<description><![CDATA[One class i really do like is TweenLite. I don&#8217;t really like the default tweening engine for a couple of reasons, but mainly because i have to save the tween object in a reference in my class, or the garbage collector could eat it (stopping the tweens in a unpredictable status). TweenLite don&#8217;t require this [...]]]></description>
			<content:encoded><![CDATA[<p>One class i really do like is <a href="http://blog.greensock.com/tweenliteas3/">TweenLite</a>. I don&#8217;t really like the default tweening engine for a couple of reasons, but mainly because i have to save the tween object in  a reference in my class, or the garbage collector could eat it (stopping the tweens in a unpredictable status).<br />
TweenLite don&#8217;t require this (it exposes static functions, and keep internal references to the tweens) and permits me to specify functions to be called, not only handlers (which i know, may sound a little ActionScript 2.0, but in fact permits to call any funcion, and so avoiding one-line handlers).</p>
<p>One small example, (to be used inside a DisplayObjectContainer) is fading out a child, and detaching after. In one clear line<span style="font-family:monospace;">:</span></p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><br /><strong>GeSHi Error:</strong> GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)<br /></div>
<p>Let&#8217;s bring this a step further: we can easily apply this technique to all child of a given container:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><br /><strong>GeSHi Error:</strong> GeSHi could not find the language actionscript3 (using path /nfs/c03/h01/mnt/85630/domains/nightdrops.com/html/wp-content/plugins/snipplr/geshi/geshi/) (code 2)<br /></div>
<p>So now all the time removeChild is called from outside, the child gently fade away, and then quietly removes himself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2009/fading-out-and-detaching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
