<?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>benwatts.ca &#187; actionscript</title>
	<atom:link href="http://www.benwatts.ca/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.benwatts.ca</link>
	<description>The crazy ramblings of designer/web developer Ben Watts.</description>
	<lastBuildDate>Sat, 02 Jan 2010 22:31:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Creating Instances from the Library with Strings</title>
		<link>http://www.benwatts.ca/2009/12/20/creating-instances-from-the-library-with-strings/</link>
		<comments>http://www.benwatts.ca/2009/12/20/creating-instances-from-the-library-with-strings/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 18:52:25 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[actionscript3]]></category>

		<guid isPermaLink="false">http://www.benwatts.ca/?p=531</guid>
		<description><![CDATA[Problem: while working on an AS3 document you uncover an unusual situation in which you have a string class name that corresponds to something in the library. How does one do it? I&#8217;ve come across this a number of times and found myself dropboxing this snippet so I would always have it with me &#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Problem: while working on an AS3 document you uncover an unusual situation in which you have a string class name that corresponds to something in the library. How does one do it? </p>
<p>I&#8217;ve come across this a number of times and found myself dropboxing this snippet so I would always have it with me &#8230;</p>
<div class="codecolorer-container actionscript3 " style="overflow:auto;white-space:nowrap;width:540px"><div class="actionscript3 codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">import</span> <span class="kw6">flash.utils</span>.<span class="sy0">*</span>;<br />
<br />
<span class="coMULTI">/** <br />
&nbsp;* Takes a string classname, returns an instance of that class, if it exists. <br />
&nbsp;*/</span><br />
<span class="kw1">private</span> <span class="kw3">function</span> newInstanceFromString<span class="br0">&#40;</span>className<span class="sy0">:</span><span class="kw5">String</span><span class="br0">&#41;</span><span class="sy0">:*</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">try</span><span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> classRef<span class="sy0">:</span><span class="kw5">Class</span> = <span class="kw7">getDefinitionByName</span><span class="br0">&#40;</span>className<span class="br0">&#41;</span> <span class="kw1">as</span> <span class="kw5">Class</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">new</span> classRef<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">catch</span><span class="br0">&#40;</span> e<span class="sy0">:</span><span class="kw5">ReferenceError</span> <span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw7">trace</span><span class="br0">&#40;</span><span class="st0">'Error: there was a problem creating an instance of the &quot;'</span><span class="sy0">+</span>className<span class="sy0">+</span><span class="st0">'&quot; class. Check your library and linkage to ensure it<span class="es0">\'</span>s there.'</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw7">trace</span><span class="br0">&#40;</span>e<span class="sy0">+</span><span class="st0">&quot;<span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span>; <br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
<p>See the AS3 livedocs for more information about <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#getDefinitionByName()">getDefinitionByName</a>, the super helpful method that makes it all work. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.benwatts.ca/2009/12/20/creating-instances-from-the-library-with-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tinting a Display Object</title>
		<link>http://www.benwatts.ca/2008/06/17/tinting-a-display-object/</link>
		<comments>http://www.benwatts.ca/2008/06/17/tinting-a-display-object/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 17:29:35 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[colour]]></category>
		<category><![CDATA[tinting]]></category>

		<guid isPermaLink="false">http://seaturtle.rainiscold.ca/?p=56</guid>
		<description><![CDATA[Tinting a display object in AS3 is remarkably easy: // EXAMPLE 1: tint a display object import fl.motion.Color; // [..] var tint:Color = new Color&#40;&#41;; tint.setTint&#40; 0x0099ff, 1 &#41;; myobject.transform.colorTransform = tint; You&#8217;ve got two options for resetting the colour, store the original colour or create a new Color object. The following example resets the [...]]]></description>
			<content:encoded><![CDATA[<p>Tinting a display object in AS3 is remarkably easy:</p>
<div class="codecolorer-container actionscript3 " style="overflow:auto;white-space:nowrap;width:540px"><div class="actionscript3 codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">// EXAMPLE 1: tint a display object</span><br />
<span class="kw1">import</span> fl.motion.Color;<br />
<span class="co1">// [..]</span><br />
<span class="kw2">var</span> tint<span class="sy0">:</span>Color = <span class="kw1">new</span> Color<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
tint.setTint<span class="br0">&#40;</span> 0x0099ff, <span class="nu0">1</span> <span class="br0">&#41;</span>;<br />
myobject.<span class="kw7">transform</span>.<span class="kw7">colorTransform</span> = tint;</div></div>
<p>You&#8217;ve got two options for resetting the colour, store the original colour or create a new Color object. The following example resets the colour of a display object when it is hovered over.</p>
<div class="codecolorer-container actionscript3 " style="overflow:auto;white-space:nowrap;width:540px"><div class="actionscript3 codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">// EXAMPLE 2: reset with a new Color Object</span><br />
<span class="kw1">import</span> fl.motion.Color;<br />
<span class="kw1">import</span> <span class="kw6">flash.events</span>.<span class="kw5">MouseEvent</span>; <br />
<span class="co1">// [..]</span><br />
<br />
<span class="co1">// call the hover() function when we hover over the display object:</span><br />
myobject.<span class="kw7">addEventListener</span><span class="br0">&#40;</span><span class="kw5">MouseEvent</span>.<span class="kw8">ROLL_OVER</span>, hover<span class="br0">&#41;</span>; <br />
<br />
<span class="kw1">private</span> <span class="kw3">function</span> hover<span class="br0">&#40;</span>e<span class="sy0">:</span><span class="kw5">MouseEvent</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; e.<span class="kw7">currentTarget</span>.<span class="kw7">transform</span>.<span class="kw7">colorTransform</span> = <span class="kw1">new</span> Color<span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">// removes tint</span><br />
<span class="br0">&#125;</span></div></div>
<p>Alternatively, you can store the original &#8220;colour&#8221; of the untinted in a variable <strong>before </strong>you tint it. The following trivial example demonstrates this, but you wouldn&#8217;t see any visible change on the stage (FYI).</p>
<div class="codecolorer-container actionscript3 " style="overflow:auto;white-space:nowrap;width:540px"><div class="actionscript3 codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">// EXAMPLE 3: reset the tint by storing the original value</span><br />
<span class="kw1">import</span> fl.motion.Color;<br />
<span class="co1">// [..]</span><br />
<span class="kw2">var</span> tint<span class="sy0">:</span>Color = <span class="kw1">new</span> Color<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
tint.setTint<span class="br0">&#40;</span> 0x0099ff, <span class="nu0">1</span> <span class="br0">&#41;</span>;<br />
<br />
<span class="kw2">var</span> originalColour<span class="sy0">:</span>Color = myobject.<span class="kw7">transform</span>.<span class="kw7">colorTransform</span>; <span class="co1">// store the original colour.</span><br />
<br />
myobject.<span class="kw7">transform</span>.<span class="kw7">colorTransform</span> = tint; <span class="co1">// tint the object blue</span><br />
myobject.<span class="kw7">transform</span>.colourTransform = originalColour; <span class="co1">// tint the object back to its original colour</span></div></div>
<p><!--http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/motion/Color.html#tintColor--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benwatts.ca/2008/06/17/tinting-a-display-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Mouse Cursor</title>
		<link>http://www.benwatts.ca/2008/05/26/as3-mouse-cursor/</link>
		<comments>http://www.benwatts.ca/2008/05/26/as3-mouse-cursor/#comments</comments>
		<pubDate>Mon, 26 May 2008 16:22:24 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[interaction]]></category>

		<guid isPermaLink="false">http://seaturtle.rainiscold.ca/?p=52</guid>
		<description><![CDATA[Movieclips with mouse handlers that make them behave as buttons no longer automatically use the lovable hand cursor. Hence the need for these two properties to be set to true on your DisplayList object! buttonMode = true; useHandCursor = true;]]></description>
			<content:encoded><![CDATA[<p>Movieclips with mouse handlers that make them behave as buttons no longer automatically use the lovable hand cursor. Hence the need for these two properties to be set to true on your DisplayList object!</p>
<pre lang="actionscript3">buttonMode = true;
useHandCursor = true;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.benwatts.ca/2008/05/26/as3-mouse-cursor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing Everything from a Display Container</title>
		<link>http://www.benwatts.ca/2008/05/25/removing-everything-from-a-display-container/</link>
		<comments>http://www.benwatts.ca/2008/05/25/removing-everything-from-a-display-container/#comments</comments>
		<pubDate>Mon, 26 May 2008 00:28:24 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[displaylist]]></category>

		<guid isPermaLink="false">http://seaturtle.rainiscold.ca/?p=48</guid>
		<description><![CDATA[I ran into this problem and couldn&#8217;t figure out what was going on because I fail miserably: // doesn't work because as this code executes numChildren is decreasing; // it ends up not removing everything for&#40;var i:Number=0; i &#38;lt; numChildren; i++&#41;&#123; &#160; removeChildAt&#40;i&#41;; &#125; The solution: while&#40; numChildren &#62; 0 &#41;&#123; &#160; removeChildAt&#40;0&#41;; &#125; This [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into this problem and couldn&#8217;t figure out what was going on <strong><em>because I fail miserably</em></strong>:</p>
<div class="codecolorer-container actionscript3 " style="overflow:auto;white-space:nowrap;width:540px"><div class="actionscript3 codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">// doesn't work because as this code executes numChildren is decreasing;</span><br />
<span class="co1">// it ends up not removing everything</span><br />
<span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i<span class="sy0">:</span><span class="kw5">Number</span>=<span class="nu0">0</span>; i <span class="sy0">&amp;</span>lt; <span class="kw7">numChildren</span>; i<span class="sy0">++</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; <span class="kw7">removeChildAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div></div>
<p>The solution:</p>
<div class="codecolorer-container actionscript3 " style="overflow:auto;white-space:nowrap;width:540px"><div class="actionscript3 codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">while</span><span class="br0">&#40;</span> <span class="kw7">numChildren</span> <span class="sy0">&gt;</span> <span class="nu0">0</span> <span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; <span class="kw7">removeChildAt</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div></div>
<p>This expression is useful for deleting things from the bottom of the displayList up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benwatts.ca/2008/05/25/removing-everything-from-a-display-container/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add Filters to Display Objects</title>
		<link>http://www.benwatts.ca/2008/05/19/add-filters-to-display-objects/</link>
		<comments>http://www.benwatts.ca/2008/05/19/add-filters-to-display-objects/#comments</comments>
		<pubDate>Mon, 19 May 2008 15:03:59 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[fx]]></category>

		<guid isPermaLink="false">http://seaturtle.rainiscold.ca/?p=46</guid>
		<description><![CDATA[Flash&#8217;s built-in filters (eg. blur/drop shadow) can be applied to display objects and bitmaps, though frankly it feels much more straightforward when you&#8217;re applying them to a display object instead of a bitmap. But I haven&#8217;t done anything with bitmaps yet &#8230; so &#8230; All the filters are part of the flash.filters.* class. // must [...]]]></description>
			<content:encoded><![CDATA[<p>Flash&#8217;s built-in filters (eg. blur/drop shadow) can be applied to display objects and bitmaps, though frankly it feels much more straightforward when you&#8217;re applying them to a display object instead of a bitmap. But I haven&#8217;t done anything with bitmaps yet &#8230; so &#8230;</p>
<p>All the filters are part of the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/filters/package-detail.html">flash.filters.* class</a>.</p>
<div class="codecolorer-container actionscript3 " style="overflow:auto;white-space:nowrap;width:540px"><div class="actionscript3 codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">// must import above the class definition</span><br />
<span class="kw1">import</span> <span class="kw6">flash.filters</span>.<span class="kw5">DropShadowFilter</span>;<br />
<span class="co1">// -- [..]</span><br />
<br />
<span class="kw2">var</span> myClip<span class="sy0">:</span><span class="kw5">MovieClip</span> = <span class="kw1">new</span> <span class="kw5">MovieClip</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> shadowFilter<span class="sy0">:</span><span class="kw5">DropShadowFilter</span> = <span class="kw1">new</span> <span class="kw5">DropShadowFilter</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">// takes a lot of arguments ...</span><br />
myClip.<span class="kw7">filters</span> = <span class="br0">&#91;</span>shadowFilter<span class="br0">&#93;</span>; <span class="co1">// filters is an instance variable from the DisplayObject class -- 'tis an Array</span><br />
<br />
<span class="co1">// if this was a bitmap (as opposed to a DisplayObject) we'd need to do applyFilter() or something</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benwatts.ca/2008/05/19/add-filters-to-display-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sifting Through the Display List to Delete Things</title>
		<link>http://www.benwatts.ca/2008/05/19/sifting-through-the-display-list-to-delete-things/</link>
		<comments>http://www.benwatts.ca/2008/05/19/sifting-through-the-display-list-to-delete-things/#comments</comments>
		<pubDate>Mon, 19 May 2008 14:31:51 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[displaylist]]></category>

		<guid isPermaLink="false">http://seaturtle.rainiscold.ca/?p=44</guid>
		<description><![CDATA[Hah, it&#8217;s a pretty specific case &#8230; but this checks the last item of the display list and removes it if it partially matches (indexOf) the name on the display list item. This requires that the display list item to be given a name. var myClip:MovieClip = new MovieClip&#40;&#41;; myClip.name = &#34;thenameofit&#34;; if&#40; getChildAt&#40;numChildren-1&#41;.name.indexOf&#40;&#34;thenameofit&#34;&#41; &#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Hah, it&#8217;s a pretty specific case &#8230; but this checks the last item of the display list and removes it if it partially matches (indexOf) the name on the display list item. This requires that the display list item to be given a name.</p>
<div class="codecolorer-container actionscript3 " style="overflow:auto;white-space:nowrap;width:540px"><div class="actionscript3 codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">var</span> myClip<span class="sy0">:</span><span class="kw5">MovieClip</span> = <span class="kw1">new</span> <span class="kw5">MovieClip</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
myClip.<span class="kw7">name</span> = <span class="st0">&quot;thenameofit&quot;</span>;<br />
<br />
<span class="kw1">if</span><span class="br0">&#40;</span> <span class="kw7">getChildAt</span><span class="br0">&#40;</span>numChildren<span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#41;</span>.<span class="kw7">name</span>.<span class="kw7">indexOf</span><span class="br0">&#40;</span><span class="st0">&quot;thenameofit&quot;</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> <span class="sy0">-</span><span class="nu0">1</span> <span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw7">removeChildAt</span><span class="br0">&#40;</span>numChildren<span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#41;</span><br />
<span class="br0">&#125;</span></div></div>
<p>Yeah. Heh. So I&#8217;m keeping this code around, why? It could be used in the program I&#8217;m writing now, but it&#8217;s not nearly flexible enough as this, which loops through the display list and removes any child with containing a partially match of &#8220;deleteme&#8221;. Much more flexible, but also more intensive in a complex movie?</p>
<div class="codecolorer-container actionscript3 " style="overflow:auto;white-space:nowrap;width:540px"><div class="actionscript3 codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">for</span><span class="br0">&#40;</span> <span class="kw2">var</span> i<span class="sy0">:</span><span class="kw5">int</span>=<span class="nu0">0</span>; i <span class="sy0">&lt;</span> <span class="kw1">this</span>.<span class="kw7">numChildren</span>; i<span class="sy0">++</span> <span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span> <span class="kw7">getChildAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="kw7">name</span>.<span class="kw7">indexOf</span><span class="br0">&#40;</span><span class="st0">'deleteme'</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> <span class="sy0">-</span><span class="nu0">1</span> <span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw7">removeChildAt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benwatts.ca/2008/05/19/sifting-through-the-display-list-to-delete-things/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
