<?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>Anselm Bradford &#187; Tips</title>
	<atom:link href="http://blog.anselmbradford.com/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.anselmbradford.com</link>
	<description>wrangling the Internet's wildest</description>
	<lastBuildDate>Sun, 18 Jul 2010 08:55:52 +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>Auckland Adobe CS5 Roadshow</title>
		<link>http://blog.anselmbradford.com/2010/04/28/auckland-adobe-cs5-roadshow/</link>
		<comments>http://blog.anselmbradford.com/2010/04/28/auckland-adobe-cs5-roadshow/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 12:09:59 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=990</guid>
		<description><![CDATA[Under the slogan of design without boundaries, work faster, and streamline critical processes, the CS5 Roadshow kicked off at Skycity Convention Centre in Auckland today. The hosts for the day were Michael &#8220;Stod&#8221; Stoddart, Mike McHugh, and Paul Burnett. The event covered a broad-range of tips, tricks, and new features of CS5. Questions could be [...]]]></description>
			<content:encoded><![CDATA[<p>Under the slogan of design without boundaries, work faster, and streamline critical processes, the <a href="http://www.adobe.com/nz/special/cs5roadshow/" onclick="pageTracker._trackPageview('/outgoing/www.adobe.com/nz/special/cs5roadshow/?referer=');">CS5 Roadshow</a> kicked off at Skycity Convention Centre in Auckland today. The hosts for the day were <a href="http://twitter.com/stod" onclick="pageTracker._trackPageview('/outgoing/twitter.com/stod?referer=');">Michael &#8220;Stod&#8221; Stoddart</a>, <a href="http://twitter.com/cs_tv" onclick="pageTracker._trackPageview('/outgoing/twitter.com/cs_tv?referer=');">Mike McHugh</a>, and <a href="http://twitter.com/pburnett" onclick="pageTracker._trackPageview('/outgoing/twitter.com/pburnett?referer=');">Paul Burnett</a>. The event covered a broad-range of tips, tricks, and new features of CS5. Questions could be asked in real-time by sending twitter questions to <a href="http://twitter.com/thequestionroom" onclick="pageTracker._trackPageview('/outgoing/twitter.com/thequestionroom?referer=');">The Question Room&#8221;</a>. </p>
<p>Some highlights:</p>
<p><strong>Production Premium</strong></p>
<ul>
<li>Utilizing 64 bit processing, Adobe Premiere and After Effects have greatly increased performance compared to previous versions.</li>
<li>The <a href="http://tv.adobe.com/watch/after-effects-cs5-feature-tour/rotoscope-with-rotobrush/" onclick="pageTracker._trackPageview('/outgoing/tv.adobe.com/watch/after-effects-cs5-feature-tour/rotoscope-with-rotobrush/?referer=');">rotobrush</a> feature in After Effects looks like a great time saver when rotoscoping video elements (cutting them out from the background).</li>
</ul>
<p><strong>InDesign</strong> (<a href="http://tv.adobe.com/watch/indesign-cs5-feature-tour/indesign-cs5-overview/" onclick="pageTracker._trackPageview('/outgoing/tv.adobe.com/watch/indesign-cs5-feature-tour/indesign-cs5-overview/?referer=');">feature tour</a>)</p>
<ul>
<li>Much smoother workflow when moving an object inside of its frame. There is now a &#8220;donut&#8221; area that when clicked allows the internal object to be moved. Also an &#8220;autosize&#8221; checkbox has been added to allow an object to resize to its frame when the frame is resized.</li>
<li>A caption text field can be created that will pull metadata out of an image when it is near to it. Great concept!</li>
<li>There is a new tool called the &#8220;Gap tool&#8221; that allows the gutter (gap) between elements to be easily resized and moved.</li>
<li>InDesign CS5 can produce simple interactive presentations that can be exported as a SWF or FLA.</li>
</ul>
<p><strong>Illustrator</strong> (<a href="http://tv.adobe.com/watch/illustrator-cs5-feature-tour/illustrator-cs5-feature-tour/" onclick="pageTracker._trackPageview('/outgoing/tv.adobe.com/watch/illustrator-cs5-feature-tour/illustrator-cs5-feature-tour/?referer=');">feature tour</a>)</p>
<ul>
<li>There are three new tools: the Perspective Grid tool, the Perspective Selection tool, and the Width tool. The first two provide guides for creating artwork along a 3-dimensional perspective, while the last tool—the Width tool—always the manipulation of the width of a stroke along its length.</li>
<li>There are two new drawing modes: draw behind and draw inside. These, as might be expected, streamline drawing behind and inside shapes respectively.</li>
<li>The dashed line feature has been to improved to ensure a part of the dash appears on corner points. This eliminates the ugly problem, for example, of having the points on a star disappear when using a dashed stroke.</li>
<li>Joining two paths has been improved, allowing paths to join by their nearest points.</li>
</ul>
<p><strong>Photoshop</strong> (<a href="http://tv.adobe.com/watch/photoshop-cs5-feature-tour/photoshop-cs5-overview/" onclick="pageTracker._trackPageview('/outgoing/tv.adobe.com/watch/photoshop-cs5-feature-tour/photoshop-cs5-overview/?referer=');">feature tour</a>)</p>
<ul>
<li>The much hyped Content Area Fill is present in many forms throughout the fill and brush tools in Photoshop CS5.</li>
<li>There is a new sharpening and noise reduction engine that can be utilized in the RAW photo dialog box.</li>
<li>There are new HDR features, such as a new HDR Toning menu under Adjustments.</li>
<li>Settings in the effects menu now have a &#8220;make default&#8221; button, allowing the setting of user-defined defaults.</li>
<li>The old extract filter for extracting hair has returned in the form of the Refine Edge option of a selection. This is a great time-saver for cutting out hair from a background.</li>
<li>The new Puppet Warp feature allows for the creation of a mesh that overlays a image that then can be distorted along a set of points.</li>
<li>Color mixing brush, which allows colors to be blended together (at first glance it appears similar to the Smudge tool).</li>
</ul>
<p>Of particular interest in this release is the heavy integration of the Flash platform among the Adobe products. Brand new in CS5, Adobe Catalyst is integrated with InDesign and Illustrator, each of which can be used to create Catalyst layouts. Catalyst allows the creation of simple interfaces and interactions without the use of any code.</p>
<p>Not all products were shown that I&#8217;m aware of (although I missed about an hour of the event during midday) such as Flash Builder and Sound Booth. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2010/04/28/auckland-adobe-cs5-roadshow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>This isn&#8217;t right&#8230; MovieClip nested inside Button throwing null object reference error in Flash CS4</title>
		<link>http://blog.anselmbradford.com/2009/09/10/this-isnt-right-movieclip-nested-inside-button-throwing-null-object-reference-error-in-flash-cs4/</link>
		<comments>http://blog.anselmbradford.com/2009/09/10/this-isnt-right-movieclip-nested-inside-button-throwing-null-object-reference-error-in-flash-cs4/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 12:02:21 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=933</guid>
		<description><![CDATA[A great thing about teaching is that your students approach problems in ways you haven&#8217;t done before and run into problems that you never knew existed. This is one such problem in Flash CS4 and a curious one at that. THE PROBLEM: A Button symbol is placed on the Stage on a frame other than [...]]]></description>
			<content:encoded><![CDATA[<p>A great thing about teaching is that your students approach problems in ways you haven&#8217;t done before and run into problems that you never knew existed. This is one such problem in Flash CS4 and a curious one at that.</p>
<p><strong>THE PROBLEM:</strong> A Button symbol is placed on the Stage on a frame other than the first frame and given an instance name in the Properties panel. In the Actions panel, ActionScript is added that references the instance name of the button on the same frame that the button instance first appears on. The movie is tested and the following error occurs:<br />
<code><br />
TypeError: Error #1009: Cannot access a property or method of a null object reference.<br />
at MovieClipInsideButton_fla::MainTimeline/frame2()<br />
</code></p>
<p>Normally this error means that a particular instance has not been given an instance name in the Properties panel on the frame where the ActionScript appears. However, nothing looks amiss in the ActionScript or on the Stage. Adding a trace statement, such as <code>trace(myButton);</code> reveals <code>null</code> in the output window, meaning the trace statement has run before the instance name has been set to the button instance on the Stage. Hmm&#8230; very perplexing, since you may have other buttons and movieclips that work fine when referenced from ActionScript.</p>
<p><strong>THE SOLUTION:</strong> From what I found, one scenario will produce this error. If a MovieClip symbol (instance) appears inside a Button symbol and the button appears on any frame other than the first frame, and the frame where the ActionScript references it is the same frame it first appears on—then this behavior will result.</p>
<p><img class="aligncenter size-full wp-image-935" title="MC_inside_button" src="http://blog.anselmbradford.com/wp-content/uploads/2009/09/MC_inside_button.png" alt="MC_inside_button" width="569" height="267" /></p>
<p>There are a few workarounds:</p>
<ol>
<li><strong>Retrieve the instance from the display list of its parent.</strong> Instead of referencing the Button instance on the stage directly, use <code>getChildByName(.)</code> to retrieve a reference to the instance, this can even be set to instance name at the beginning of your timeline code, like so:

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// myButton is the name of the instance as set in the Properties panel.</span>
<span style="color: #808080; font-style: italic;">// Retrieved child is cast as a SimpleButton, since this is the </span>
<span style="color: #808080; font-style: italic;">// class of the Button symbol</span>
myButton = SimpleButton<span style="color: #66cc66;">&#40;</span>getChildByName<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myButton&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

</li>
<li><strong>Do not nest a MovieClip inside a Button symbol.</strong> A Button nested inside a Button, a MovieClip nested inside a MovieClip, and a Button nested inside a MovieClip work fine.</li>
<li><strong>Place the first occurance of the Button instance on any frame before the frame where ActionScript first references it.</strong> This behavior appears to indicate Flash is taking too long to parse over the MovieClip inside a Button and runs the ActionScript on the timeline prematurely. Having the instance appear on a frame prior to the frame the ActionScript appears on ensures the instance is completely present in memory before it is referenced.</li>
<li><strong>Place the instance referencing code inside an enter frame event handler function.</strong> To ensure the entire frame has been parsed before any ActionScript code is run, enclose the offending code inside the event handler function of the enter frame event, and only make it run once, like so:

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">addEventListener<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span> , ensureRendered <span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ensureRendered<span style="color: #66cc66;">&#40;</span> evt:Event <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	removeEventListener<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span> , ensureRendered <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">// All instance referencing code appears below this point</span>
	<span style="color: #808080; font-style: italic;">// In this case, instance is named &quot;myButton&quot; on the Stage</span>
	myButton.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">200</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

</li>
</ol>
<p>This behavior doesn&#8217;t seem right to me and even seems it could be a bug. If anyone has an explanation for this behavior, I would love to hear it. You may download an example FLA here: <a href='/wp-content/uploads/2009/09/movieclipinsidebutton.zip'>Download Source</a></p>
<p><strong>UPDATE September 20, 2009:</strong> I added a new workaround, which is probably the most succinct and reliable one yet to use. See <em>Retrieve the instance from the display list of its parent</em> in the list of workarounds.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/09/10/this-isnt-right-movieclip-nested-inside-button-throwing-null-object-reference-error-in-flash-cs4/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Creating a date countdown timer in ActionScript 3 / Flash</title>
		<link>http://blog.anselmbradford.com/2009/08/03/creating-a-date-countdown-timer-in-actionscript-3-flash/</link>
		<comments>http://blog.anselmbradford.com/2009/08/03/creating-a-date-countdown-timer-in-actionscript-3-flash/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 15:23:41 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=873</guid>
		<description><![CDATA[Creating a countdown timer in ActionScript is quite easy. The essentials of it are: Specify a target date to countdown to using the Date class. Create a Timer instance to check the countdown time each second or so. At each tick of the timer calculate the number of milliseconds between now and the target date. [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a countdown timer in ActionScript is quite easy. The essentials of it are:</p>
<ol>
<li>Specify a target date to countdown to using the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Date.html" onclick="pageTracker._trackPageview('/outgoing/livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Date.html?referer=');">Date</a> class.</li>
<li>Create a <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/Timer.html" onclick="pageTracker._trackPageview('/outgoing/livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/Timer.html?referer=');">Timer</a> instance to check the countdown time each second or so.</li>
<li>At each tick of the timer calculate the number of milliseconds between now and the target date.</li>
<li>Determine how many days, hours, minutes, seconds, etc. that number of milliseconds is equal to.</li>
<li>Update the graphics to reflect the amount of time left.</li>
</ol>
<p>The following is an example of a countdown timer, with a link to the source code below. This utilizes a reusable class file for the countdown timer. All code specific to this particular implementation can be found in com/anselmbradford/Main.as.<br />

<object width="200" height="45">
<param name="movie" value="/wp-content/uploads/2009/08/counter.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="200" height="45" src="/wp-content/uploads/2009/08/counter.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p><a href='/wp-content/uploads/2009/08/counter.zip'>Download Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/08/03/creating-a-date-countdown-timer-in-actionscript-3-flash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Object-Oriented JavaScript Tip: Implementing the Singleton Pattern</title>
		<link>http://blog.anselmbradford.com/2009/04/21/object-oriented-javascript-tip-the-quintessential-singleton/</link>
		<comments>http://blog.anselmbradford.com/2009/04/21/object-oriented-javascript-tip-the-quintessential-singleton/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 06:45:24 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=784</guid>
		<description><![CDATA[The Singleton design pattern is a development approach that ensures only a single instance of a particular class is available in a system. Imagine building the game of chess, you would only want there to be one instance of the board floating around—say an instance of a class called ChessBoard. The Singleton pattern ensures that [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Singleton_pattern" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Singleton_pattern?referer=');">Singleton design pattern</a> is a development approach that ensures only a single instance of a particular class is available in a system. Imagine building the game of chess, you would only want there to be one instance of the board floating around—say an instance of a class called <code>ChessBoard</code>. The Singleton pattern ensures that there will only ever be one <code>ChessBoard</code> object available in your game. </p>
<p>Often the implementation of a Singleton looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Singleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Singleton.<span style="color: #660066;">getInstance</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Singleton.<span style="color: #660066;">instance</span> <span style="color: #339933;">==</span> undefined<span style="color: #009900;">&#41;</span> Singleton.<span style="color: #660066;">instance</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Singleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> Singleton.<span style="color: #660066;">instance</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>However, this is a port to JavaScript from other languages and it doesn&#8217;t offer a very robust implementation of the Singleton. For example, this design relies on calling <code>Singleton.getInstance()</code> to retrieve the single instance. However, nothing prevents calling&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> instance1 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Singleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> instance2 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Singleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> instance1 <span style="color: #339933;">==</span> instance2 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs false because these are two object instances</span></pre></div></div>

<p>&#8230;to create two instances, defeating the pattern. A better approach is to encapsulate the Singleton constructor function in a variable and return a reference to the function rather than the instance, and then provide access to the instance via a <code>getInstance</code> method as above.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Singleton <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">function</span> Singleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	Singleton.<span style="color: #660066;">getInstance</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> instance<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this case, the code shown earlier does not break the pattern:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> instance1 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Singleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> instance2 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Singleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> instance1 <span style="color: #339933;">==</span> instance2 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs true because these refer to the same constructor function</span></pre></div></div>

<p>However, this just prevents circumvention of the pattern, the same object instance has not yet been retrieved. To do this the static <code>getInstance()</code> method is called on the constructor reference variable.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> instance1 <span style="color: #339933;">=</span> Singleton.<span style="color: #660066;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> instance2 <span style="color: #339933;">=</span> Singleton.<span style="color: #660066;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> instance1 <span style="color: #339933;">==</span> instance2 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs true because these refer to the same object instance</span></pre></div></div>

<p>Additionally, a <a href="/2009/04/05/object-oriented-javascript-tip-overriding-tostring-for-readable-object-imprints/">toString method</a>, as well as <a href="/2009/04/09/object-oriented-javascript-tip-creating-static-methods-instance-methods/">static and instance methods</a> (though both are functionally identically in this case since there&#8217;s only one instance available) can be built into the Singleton definition, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Singleton <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">function</span> Singleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> instance <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	Singleton.<span style="color: #660066;">getInstance</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> instance<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">toString</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;[object Singleton]&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">instanceMethod</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;instance method called!&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
	<span style="color: #009900;">&#125;</span>
&nbsp;
	Singleton.<span style="color: #660066;">staticMethod</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;static method called!&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> Singleton<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Try these out:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Singleton.<span style="color: #660066;">staticMethod</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Singleton.<span style="color: #660066;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">instanceMethod</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Since JavaScript is a prototype-based language (not actually having classes), additional functionality can be added through the Singleton&#8217;s prototype, as in:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Singleton.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">custFunct</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;A custom method&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// add instance method</span>
Singleton.<span style="color: #660066;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">custFunct</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// call new instance method</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/04/21/object-oriented-javascript-tip-the-quintessential-singleton/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Object-Oriented JavaScript Tip: Creating static methods, instance methods</title>
		<link>http://blog.anselmbradford.com/2009/04/09/object-oriented-javascript-tip-creating-static-methods-instance-methods/</link>
		<comments>http://blog.anselmbradford.com/2009/04/09/object-oriented-javascript-tip-creating-static-methods-instance-methods/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 10:52:21 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=777</guid>
		<description><![CDATA[Custom JavaScript objects can have instance methods (function that are associated with a particular JavaScript object), but like other Object-Oriented languages, they can also have static methods, that is functions that are associated with the JavaScript class that created an object, as opposed to the object itself. This is useful in cases where a function [...]]]></description>
			<content:encoded><![CDATA[<p>Custom JavaScript objects can have instance methods (function that are associated with a particular JavaScript object), but like other Object-Oriented languages, they can also have <em>static</em> methods, that is functions that are associated with the JavaScript class that created an object, as opposed to the object itself. This is useful in cases where a function (a.k.a. a method) will not be different in different object instances. Let&#8217;s look at an example&#8230; </p>
<p>Suppose you created a class to handle simple arithmetic calculations:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Calculator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To begin with, an instance method could be added to this class in one of two ways, either inside the constructor or through the class prototype. In this example, one method called <code>multiply</code> will be created, which returns the product of two values multiplied together. First, implemented in the constructor it looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Calculator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">multiply</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>val1 <span style="color: #339933;">,</span> val2<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>val1<span style="color: #339933;">*</span>val2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Via the class prototype, which is a more readable solution in my opinion, it would look like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Calculator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Calculator.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">multiply</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>val1 <span style="color: #339933;">,</span> val2<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>val1<span style="color: #339933;">*</span>val2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Use of this method would then occur through instances of the <code>Calculator</code> class, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> calc <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Calculator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> calc.<span style="color: #660066;">multiply</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//pop-up alert with product of 4 times 3</span></pre></div></div>

<p>However, it shouldn&#8217;t really be necessary to create an object to use the <code>multiply</code> method, since the method isn&#8217;t dependent on the state of the object for its execution. The method can be moved to the class to clean up this code a bit. First the class definition is created, which looks almost identical to the instance method declaration above, with the exception of the <code>prototype</code> keyword being removed:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Calculator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Calculator.<span style="color: #660066;">multiply</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>val1 <span style="color: #339933;">,</span> val2<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>val1<span style="color: #339933;">*</span>val2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now the <code>multiply</code> method can be called through the class itself, instead of an instance of the class, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> Calculator.<span style="color: #660066;">multiply</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//pop-up alert with product of 4 times 3</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/04/09/object-oriented-javascript-tip-creating-static-methods-instance-methods/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Object-Oriented JavaScript Tip: Overriding toString() for readable object imprints</title>
		<link>http://blog.anselmbradford.com/2009/04/05/object-oriented-javascript-tip-overriding-tostring-for-readable-object-imprints/</link>
		<comments>http://blog.anselmbradford.com/2009/04/05/object-oriented-javascript-tip-overriding-tostring-for-readable-object-imprints/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 03:58:16 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=771</guid>
		<description><![CDATA[JavaScript has a core Object class that contains a toString() method that is called whenever a request is made to convert an object to a string (like related ECMAScript-based ActionScript). This is often done during debugging to check that a variable actually contains a reference to a certain object. Most likely alert(myObj) or console.log(myObj) would [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript has a core <code>Object</code> class that contains a <code>toString()</code> method that is called whenever a request is made to convert an object to a string (like related ECMAScript-based ActionScript). This is often done during debugging to check that a variable actually contains a reference to a certain object. </p>
<p>Most likely <code>alert(myObj)</code> or <code>console.log(myObj)</code> would be used, for example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myObj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>myObj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// popup displays [object Object]</span></pre></div></div>

<p>The problem is if you create a custom object. In this case it would be ideal to adjust the string representation to reflect the fact that the custom object is different from the core object. By default there is no difference, as the following example demonstrates:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// custom Foo class</span>
<span style="color: #003366; font-weight: bold;">function</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// new Foo object instance</span>
<span style="color: #003366; font-weight: bold;">var</span> f <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// popup displays [object Object]</span></pre></div></div>

<p>To make this more readable, add a <code>toString()</code> method to the prototype of the object:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// toString override added to prototype of Foo class</span>
Foo.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">toString</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;[object Foo]&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> f <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// popup displays [object Foo]</span></pre></div></div>

<p>In this case, because of the presence of the <code>toString()</code> method, which overrides the default, a custom string can be displayed for the object that is more applicable to what it is. Additionally, information about the properties of the object could be included in this method as well, as in:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">message</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Hello World!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
Foo.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">toString</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;[object Foo &lt;&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">message</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&gt;]&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> f <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// popup displays [object Foo &lt;Hello World!&gt;]</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/04/05/object-oriented-javascript-tip-overriding-tostring-for-readable-object-imprints/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Common Flash Compiler Errors: #1046</title>
		<link>http://blog.anselmbradford.com/2009/03/25/common-flash-compiler-errors-1046/</link>
		<comments>http://blog.anselmbradford.com/2009/03/25/common-flash-compiler-errors-1046/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 08:39:26 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=755</guid>
		<description><![CDATA[This error shows the following in the Compiler Errors window: 1046: Type was not found or was not a compile-time constant: [Class name]. Quick Answer and Solution Where I have &#8220;[Class name]&#8221; above you will have any number of names listed, for example it may say Event, Sprite, TextField, etc. What this means is you [...]]]></description>
			<content:encoded><![CDATA[<p>This error shows the following in the Compiler Errors window:</p>
<p><code><br />
1046: Type was not found or was not a compile-time constant: [Class name].<br />
</code></p>
<h3>Quick Answer and Solution</h3>
<p>Where I have &#8220;[Class name]&#8221; above you will have any number of names listed, for example it may say <code>Event</code>, <code>Sprite</code>, <code>TextField</code>, etc. What this means is you are using a piece of code that utilizes a class (typically seen as files with a &#8220;.as&#8221; extension) that you have not &#8220;imported&#8221; so that your code knows where to find it. To fix this problem perform the following:</p>
<ol>
<li>Open a web browser and navigate to Google.</li>
<li>Enter the search &#8220;[class name] actionscript 3 site:livedocs.adobe.com&#8221; (replacing [class name] with whatever the class name is in the error message, such as TextField, MouseEvent, URLLoader, etc.). For example, &#8220;Event actionscript 3 site:livedocs.adobe.com&#8221;</li>
<li>Look for a search result that lists the class in a format of a series of words with dots between them, probably will be the top result. Examples include:
<ul>
<li>flash.events.Event</li>
<li>flash.display.Sprite</li>
<li>fl.transitions.Tween</li>
<li>flash.geom.Rectangle</li>
</ul>
<p>This is the path to the class, which you can use to import the class into your code.</li>
<li>Without clicking on the search result, copy the class name as it appears in the previous step.</li>
<li>Return to Flash and double-click the error message.</li>
<li>Scroll to the top of the code area. Type &#8220;import&#8221; and paste the path to the class. For example,<br />
<code>import flash.events.Event;</code></li>
</ol>
<p>If you are using code on the Timeline, this can be placed at the top of the Actions panel. If you have written a class file that is referencing another class, this code appears between the <code>package {</code> curly brace, and class declaration, <code>public class MyClass</code>.</p>
<p>For example,</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// class import statements appear here</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h3>Technical Overview</h3>
<p>A class file is an external text file that contains variables and functions (known as properties and methods in the object-oriented programming context), essentially this means class files are self-contained blocks of code that contain code related to a particular task. To access these variables and functions within your own block of code the class file needs to be imported. If your code contains any references to a class file that has either: (a) not been imported, or (b) is not within the same folder as your .fla or .as files, then a #1046 error will be thrown. For example, suppose you have the following class file declared for a button:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyButton <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">CLICK</span> , _clicked <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _clicked<span style="color: #66cc66;">&#40;</span> evt:MouseEvent <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// button was clicked!</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Testing this code would produce the following error:<br />
<code><br />
1046: Type was not found or was not a compile-time constant: MouseEvent.<br />
</code></p>
<p>With the source listed as&#8230;<br />
<code><br />
private function _clicked( evt:MouseEvent ) : void<br />
</code></p>
<p>This is because the class <code>MouseEvent</code> is referenced in the code, but is not imported at the top of the class file. The fix is simple and looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #808080; font-style: italic;">// import the MouseEvent class</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyButton <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">CLICK</span> , _clicked <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _clicked<span style="color: #66cc66;">&#40;</span> evt:MouseEvent <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// button was clicked!</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Typically if you are a beginning ActionScripter, you will run into this error when referencing classes created by Adobe. However, as you become more advanced in your scripting abilities you may place your own custom class files in &#8220;packages&#8221; that would then need to be imported using the same above process. In case you are wondering what the stuff is before the actual class name, such as &#8220;flash.display&#8221; and &#8220;flash.events,&#8221; this is the &#8220;package&#8221; that class resides in, which is essentially the folders the class file resides in on disk. For example, suppose I created a class called &#8220;MyButton&#8221; and placed it in the package &#8220;com.anselmbradford.&#8221; This class would appear in a text file called &#8220;MyButton.as&#8221; that would be in a folder called &#8220;anselmbradford&#8221; that would itself be in a folder called &#8220;com.&#8221; The class file would look like:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">anselmbradford</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyButton <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>To import this class file into another class file I would place the &#8220;com&#8221; folder (containing the class file two levels in) in the same directory as my .fla or .as file that I wanted to import this class into. I would then import it using the syntax shown previously. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #808080; font-style: italic;">// class is imported</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">anselmbradford</span>.<span style="color: #006600;">MyButton</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// class is referenced in code, so must be imported</span>
			<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">button</span>:MyButton = <span style="color: #000000; font-weight: bold;">new</span> MyButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Note: Whole sets of class files that are within the same package can be imported using the &#8220;*&#8221; wildcard operator. For example, <code>flash.events.Event</code>, and <code>flash.events.MouseEvent</code>, both reside in the <code>flash.events</code> package. Instead of having two lines to import both of these classes, you can have <code>import flash.events.*;</code>, which will import all the necessary classes from the <code>flash.events</code> package.</p>
<p><strong>UPDATE October 4, 2009:</strong>This error will also occur if you have a symbol on your stage that has an instance name that is the same as a class name associated with the symbol. Check the Library panel, under the Linkages column, does any of your symbols have a name next to &#8220;Export:&#8221; that is the same as the instance name in the Properties panel of one of those symbols on the stage?</p>
<p><img src="http://blog.anselmbradford.com/wp-content/uploads/2009/03/type_error.png" alt="type_error" title="type_error" width="267" height="216" class="alignnone size-full wp-image-970" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/03/25/common-flash-compiler-errors-1046/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Common Flash Compiler Errors: #1042</title>
		<link>http://blog.anselmbradford.com/2009/03/19/common-flash-compiler-errors-1042/</link>
		<comments>http://blog.anselmbradford.com/2009/03/19/common-flash-compiler-errors-1042/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 01:26:47 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=729</guid>
		<description><![CDATA[This error shows the following in the Compiler Errors window: 1042: The this keyword can not be used in static methods. It can only be used in instance methods, function closures, and global code. Quick Answer and Solution Most likely you are you using the keyword &#8220;this&#8221; inside a class file, but it is not [...]]]></description>
			<content:encoded><![CDATA[<p>This error shows the following in the Compiler Errors window:</p>
<p><code><br />
1042: The this keyword can not be used in static methods. It can only be used in instance methods, function closures, and global code.<br />
</code></p>
<h3>Quick Answer and Solution</h3>
<p>Most likely you are you using the keyword &#8220;this&#8221; inside a class file, but it is not inside the curly braces of a function. By double-clicking on the error it will take you to the offending line of code. Check carefully to make sure where you have placed the keyword &#8220;this&#8221; is actually between the opening &#8220;{&#8221; and closing &#8220;}&#8221; braces of a function declaration. If it looks correct, but is accompanied by error #1126 (<a href="/2009/03/13/common-flash-compiler-errors-1126/">described here</a>), then fix that error first. Also, if the &#8220;this&#8221; keyword appears in a function that has the &#8220;static&#8221; keyword in its declaration, error #1042 will also be thrown.</p>
<p>The following are three scenarios where a class file will throw this error:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #808080; font-style: italic;">// &quot;this&quot; keyword used outside a function</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// function does not have a body because of misplaced semicolon,</span>
		<span style="color: #808080; font-style: italic;">// so error #1126 is thrown</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">hide</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>;
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// the &quot;this&quot; keyword is actually not in the body of a function</span>
			<span style="color: #808080; font-style: italic;">// because of the above #1126 error</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// function is a &quot;static method,&quot; meaning it runs inside the class,</span>
		<span style="color: #808080; font-style: italic;">// not the object created from the class</span>
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">hide</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// the &quot;this&quot; keyword is inside a static method</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The corrected form of the above examples would be:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">hide</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// the reference to &quot;this&quot; is inside a non-static function</span>
			<span style="color: #808080; font-style: italic;">// (called an instance method)</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h3>Technical Overview</h3>
<p>There are two types of methods (functions) that can appear in a class file, static methods and instance methods. Static methods refer to methods that are run via the class itself, while instance methods refer to methods run via an instance of the class. Consider the following class file:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">static</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> staticMethod<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;static method called!&quot;</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> instanceMethod<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;instance method called!&quot;</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>To call the first method, a new &#8220;<code>Main</code>&#8221; object does not need to be created, as the static method can be called on the class itself, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">Main.<span style="color: #006600;">staticMethod</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Conversely, to access the other method, an (object) instance of the <code>Main</code> class needs to be created and then the method can be called through that object, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> main:Main = <span style="color: #000000; font-weight: bold;">new</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
main.<span style="color: #006600;">instanceMethod</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Use of the &#8220;this&#8221; keyword refers to the object instance of the class that the code is currently dealing with (in the above case if <code>this</code> appeared in the body of the <code>instanceMethod()</code> method it would be referring to the object placed in the <code>main</code> variable). Since no object instance has to be created to use static methods, the &#8220;this&#8221; keyword can not be used within those methods because there is no object in existence to refer to. Additionally, all code outside of a function declaration runs <span style="text-decoration: underline;">before</span> an object instance is created (before the constructor function runs), so any references to &#8220;this&#8221; do not have an object to refer to in that context either.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/03/19/common-flash-compiler-errors-1042/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>2 invaluable Drupal development tips: list all available variables and backtrace a page</title>
		<link>http://blog.anselmbradford.com/2009/03/14/2-invaluable-drupal-development-tips-list-all-available-variables-and-backtrace-a-page/</link>
		<comments>http://blog.anselmbradford.com/2009/03/14/2-invaluable-drupal-development-tips-list-all-available-variables-and-backtrace-a-page/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 03:59:49 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=702</guid>
		<description><![CDATA[The Drupal Devel module includes some invaluable functions that make working with Drupal much much easier. A short list of these functions can be found at this post. One of these is the dpm() command (which I would guess stands for &#8220;Drupal Print Message,&#8221; or at least that&#8217;s how I remember it). Given an array [...]]]></description>
			<content:encoded><![CDATA[<p>The Drupal <a href="http://drupal.org/project/devel" onclick="pageTracker._trackPageview('/outgoing/drupal.org/project/devel?referer=');">Devel</a> module includes some invaluable functions that make working with Drupal much much easier. A short list of these functions can be found <a href="http://www.thingy-ma-jig.co.uk/blog/02-10-2007/hugely-useful-hugely-undocumented" onclick="pageTracker._trackPageview('/outgoing/www.thingy-ma-jig.co.uk/blog/02-10-2007/hugely-useful-hugely-undocumented?referer=');">at this post</a>. One of these is the <code>dpm()</code> command (which I would guess stands for &#8220;Drupal Print Message,&#8221; or at least that&#8217;s how I remember it). Given an array or object, this function will output a div structure at the top of your page that you can use to visually walk through the contents of either of these sets of data. Combine this with existing PHP debugging and instrospection commands and you have a very useful and powerful development tool at your disposal. For example, place this at the top of your Drupal theme&#8217;s <code>page.tpl.php</code> template:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?php
	 dpm<span style="color: #66cc66;">&#40;</span> get_defined_vars<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
?<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>Now when you navigate to your page you will have a clickable bar at the top that will list all variables available to the page when it loads, which you can access via the code in your theme page template if you want. </p>
<p><img src="http://blog.anselmbradford.com/wp-content/uploads/2009/03/dpm_get_defined_vars.png" alt="dpm_get_defined_vars" title="dpm_get_defined_vars" width="353" height="348" class="aligncenter size-full wp-image-703" /></p>
<p>Or maybe you would like to know what path your page took through Drupal&#8217;s architecture to its final incarnation, use <code>dpm()</code> with PHP&#8217;s <code>debug_backtrace()</code> function. This will output an array of each function your page contents went through before they were output to the browser, plus it shows the location of these functions. Try this in place of the code snippet above:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?php
	 dpm<span style="color: #66cc66;">&#40;</span> debug_backtrace<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
?<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p><img src="http://blog.anselmbradford.com/wp-content/uploads/2009/03/dpm_debug_backtrace.png" alt="dpm_debug_backtrace" title="dpm_debug_backtrace" width="531" height="374" class="aligncenter size-full wp-image-704" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/03/14/2-invaluable-drupal-development-tips-list-all-available-variables-and-backtrace-a-page/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Common Flash Compiler Errors: #1126</title>
		<link>http://blog.anselmbradford.com/2009/03/13/common-flash-compiler-errors-1126/</link>
		<comments>http://blog.anselmbradford.com/2009/03/13/common-flash-compiler-errors-1126/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 22:12:00 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=686</guid>
		<description><![CDATA[This error shows the following in the Compiler Errors window: 1126: Function does not have a body. Quick Answer and Solution By double-clicking on the error it will take you to the offending line of code. This error commonly happens when the end of line designator &#8220;;&#8221; is placed at the end of a function [...]]]></description>
			<content:encoded><![CDATA[<p>This error shows the following in the Compiler Errors window:</p>
<p><code><br />
1126: Function does not have a body.<br />
</code></p>
<h3>Quick Answer and Solution</h3>
<p>By double-clicking on the error it will take you to the offending line of code. This error commonly happens when the end of line designator &#8220;<code>;</code>&#8221; is placed at the end of a function name declaration, as in:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>;
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/*function body*/</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Notice the presence of the semicolon at the end of line 1. To fix the error the semicolon is removed:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/*function body*/</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<h3>Technical Overview</h3>
<p>A function is a block of code that will only run when it is &#8220;called,&#8221; meaning the above example would be run by writing the function name elsewhere, like so: <code>init();</code>. When a particular function is called, the code that appears between the curly braces (&#8220;{}&#8221;) is run. This is referred to as the function &#8220;body.&#8221; When you test a movie in Flash the code is read line by line by the compiler and eventually turned into a SWF. However, what you see as a single line of code and what the compiler sees as a single line of code are two different things. The compiler ignores extra white space and carriage returns. For example, to the compiler the following function declaration:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/*function body*/</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>&#8230;is the same as:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">/*function body*/</span><span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Because of this, it depends on the semicolon and closing curly brace (&#8220;}&#8221;) to denote that a line of code has ended. The closing curly brace is used for every piece of code that creates a block of code (functions, for example), while the semicolon is used for everything else. If a semicolon were to appear before the opening curly brace (&#8220;{&#8220;) in the above line of code, the compiler would hit the semicolon and throw an error that the function did not have a &#8220;body&#8221; because it had reached the end of the line of code without encountering an opening and closing curly brace. </p>
<p><strong>Note:</strong> The one exception to this rule is the constructor function found in class files, which can oddly enough contain a semicolon after the function name declaration and the compiler will not complain, for example the following will not throw an error:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">/*constructor function body*/</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>However, while the compiler will not complain, the constructor function actually ends at the semicolon, so what&#8217;s written between the curly braces (the &#8220;constructor function body&#8221;) will not be run when a new object of this class is instantiated (well, actually it will run, but it will be in the scope of the class, not the object, so it will run prior to the creation of the object). Constructor functions are different in one other aspect as well, they do not specify a return type (no &#8220;<code>:void</code>&#8221; after the parentheses, for example).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/03/13/common-flash-compiler-errors-1126/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
