<?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://benwatts.ca/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://benwatts.ca</link>
	<description>Designer and Frontend Developer in Ottawa, Canada</description>
	<lastBuildDate>Fri, 22 Jul 2011 19:00:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating Instances from the Library with Strings</title>
		<link>http://benwatts.ca/2009/creating-instances-from-the-library-with-strings/</link>
		<comments>http://benwatts.ca/2009/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 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.*;</span><br />
<br />
<span style="color: #3f5fbf;">/** <br />
&nbsp;* Takes a string classname, returns an instance of that class, if it exists. <br />
&nbsp;*/</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> newInstanceFromString<span style="color: #000000;">&#40;</span>className<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:*</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">try</span><span style="color: #000000;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> classRef<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span> = <span style="color: #004993;">getDefinitionByName</span><span style="color: #000000;">&#40;</span>className<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> classRef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">catch</span><span style="color: #000000;">&#40;</span> e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ReferenceError</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'Error: there was a problem creating an instance of the &quot;'</span><span style="color: #000066; font-weight: bold;">+</span>className<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'&quot; class. Check your library and linkage to ensure it<span style="">\'</span>s there.'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#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://benwatts.ca/2009/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://benwatts.ca/2008/tinting-a-display-object/</link>
		<comments>http://benwatts.ca/2008/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 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// EXAMPLE 1: tint a display object</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>motion<span style="color: #000066; font-weight: bold;">.</span>Color<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #009900; font-style: italic;">// [..]</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> tint<span style="color: #000066; font-weight: bold;">:</span>Color = <span style="color: #0033ff; font-weight: bold;">new</span> Color<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
tint<span style="color: #000066; font-weight: bold;">.</span>setTint<span style="color: #000000;">&#40;</span> 0x0099ff<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myobject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">transform</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">colorTransform</span> = tint<span style="color: #000066; font-weight: bold;">;</span></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 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// EXAMPLE 2: reset with a new Color Object</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>motion<span style="color: #000066; font-weight: bold;">.</span>Color<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<span style="color: #009900; font-style: italic;">// [..]</span><br />
<br />
<span style="color: #009900; font-style: italic;">// call the hover() function when we hover over the display object:</span><br />
myobject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ROLL_OVER</span><span style="color: #000066; font-weight: bold;">,</span> hover<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> hover<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">currentTarget</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">transform</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">colorTransform</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Color<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// removes tint</span><br />
<span style="color: #000000;">&#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 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// EXAMPLE 3: reset the tint by storing the original value</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>motion<span style="color: #000066; font-weight: bold;">.</span>Color<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #009900; font-style: italic;">// [..]</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> tint<span style="color: #000066; font-weight: bold;">:</span>Color = <span style="color: #0033ff; font-weight: bold;">new</span> Color<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
tint<span style="color: #000066; font-weight: bold;">.</span>setTint<span style="color: #000000;">&#40;</span> 0x0099ff<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> originalColour<span style="color: #000066; font-weight: bold;">:</span>Color = myobject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">transform</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">colorTransform</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// store the original colour.</span><br />
<br />
myobject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">transform</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">colorTransform</span> = tint<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// tint the object blue</span><br />
myobject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">transform</span><span style="color: #000066; font-weight: bold;">.</span>colourTransform = originalColour<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// 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://benwatts.ca/2008/tinting-a-display-object/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3 Mouse Cursor</title>
		<link>http://benwatts.ca/2008/as3-mouse-cursor/</link>
		<comments>http://benwatts.ca/2008/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://benwatts.ca/2008/as3-mouse-cursor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing Everything from a Display Container</title>
		<link>http://benwatts.ca/2008/removing-everything-from-a-display-container/</link>
		<comments>http://benwatts.ca/2008/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 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// doesn't work because as this code executes numChildren is decreasing;</span><br />
<span style="color: #009900; font-style: italic;">// it ends up not removing everything</span><br />
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">numChildren</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #004993;">removeChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>The solution:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">numChildren</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #004993;">removeChildAt</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#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://benwatts.ca/2008/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://benwatts.ca/2008/add-filters-to-display-objects/</link>
		<comments>http://benwatts.ca/2008/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 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// must import above the class definition</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.filters</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DropShadowFilter</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #009900; font-style: italic;">// -- [..]</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> myClip<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">MovieClip</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> shadowFilter<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DropShadowFilter</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">DropShadowFilter</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// takes a lot of arguments ...</span><br />
myClip<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">filters</span> = <span style="color: #000000;">&#91;</span>shadowFilter<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// filters is an instance variable from the DisplayObject class -- 'tis an Array</span><br />
<br />
<span style="color: #009900; font-style: italic;">// 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://benwatts.ca/2008/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://benwatts.ca/2008/sifting-through-the-display-list-to-delete-things/</link>
		<comments>http://benwatts.ca/2008/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 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> myClip<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">MovieClip</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
myClip<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> = <span style="color: #990000;">&quot;thenameofit&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>numChildren<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;thenameofit&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">removeChildAt</span><span style="color: #000000;">&#40;</span>numChildren<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#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 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">numChildren</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'deleteme'</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">removeChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://benwatts.ca/2008/sifting-through-the-display-list-to-delete-things/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

