<?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>Studio Barliesque</title>
	<atom:link href="http://studio.barliesque.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://studio.barliesque.com/blog</link>
	<description>David Barlia - Flash Developer / Designer / Animator</description>
	<lastBuildDate>Fri, 30 Oct 2009 18:43:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Textured Vectors</title>
		<link>http://studio.barliesque.com/blog/2009/01/textured-vectors/</link>
		<comments>http://studio.barliesque.com/blog/2009/01/textured-vectors/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 01:47:31 +0000</pubDate>
		<dc:creator>barliesque</dc:creator>
				<category><![CDATA[Animation]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Effect]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Lighting]]></category>
		<category><![CDATA[Texture]]></category>
		<category><![CDATA[Vectors]]></category>

		<guid isPermaLink="false">http://studio.barliesque.com/blog/?p=139</guid>
		<description><![CDATA[Just a little experiment for an upcoming animation project.  The usual flat cartoony vectors just wouldn't be right, so I was playing with layering textures with gradients designed to simulate 3D.  I'm pretty excited about the results...]]></description>
			<content:encoded><![CDATA[<p>Just a little experiment for an upcoming animation project.  The usual flat cartoony vectors just wouldn&#8217;t be right, so I was playing with layering bitmap fills with gradients designed to simulate 3D.  I&#8217;m pretty excited about the results&#8230;</p>
<p><script type="text/javascript" src="http://studio.barliesque.com/blog/wp-content/plugins/pb-embedflash/js/swfobject.js"></script><span class="embedflash" id="swfid9be01eeb2a51570ebc781e6dfa01ee75"><small>(Please open the article to see the flash file or player.)</small></span><script type="text/javascript">
				var flashvars = {}; var params = {}; var attributes = {};params.allowfullscreen = "true"; params.allowscriptaccess = "always";
				swfobject.embedSWF("http://studio.barliesque.com/blog/media/materials.swf","swfid9be01eeb2a51570ebc781e6dfa01ee75","500","400","9.0.0","http://studio.barliesque.com/blog/wp-content/plugins/pb-embedflash/swf/expressInstall.swf",flashvars,params,attributes);
		</script></p>
<p>This was also a chance to get to grips with the new Motion Editor in Flash CS4.  I&#8217;ve made that and a CS3 version available for download if you&#8217;d like to have a look.</p>
<p><a href="http://studio.barliesque.com/blog/download/textured_vectors_cs4.zip"><strong>Download the .fla (CS4)</strong></a><strong><br />
 </strong> <a href="http://studio.barliesque.com/blog/download/textured_vectors_cs3.zip"><strong>Download the .fla (CS3)</strong></a></p>
<p>Have a look at <a title="www.imageafter.com" href="http://www.imageafter.com" target="_blank">www.imageafter.com</a> if you&#8217;re looking for more texture images.</p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://studio.barliesque.com/blog/2009/01/textured-vectors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make an AS3 Flash Component with Custom UI Controls</title>
		<link>http://studio.barliesque.com/blog/2008/12/as3-component-custom-ui/</link>
		<comments>http://studio.barliesque.com/blog/2008/12/as3-component-custom-ui/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 12:30:41 +0000</pubDate>
		<dc:creator>barliesque</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[control panel]]></category>
		<category><![CDATA[custom component]]></category>
		<category><![CDATA[custom ui]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash CS3]]></category>
		<category><![CDATA[jsfl]]></category>
		<category><![CDATA[work-around]]></category>

		<guid isPermaLink="false">http://studio.barliesque.com/blog/?p=57</guid>
		<description><![CDATA[I'd nearly given up the whole idea, having searched all over the internet only to find dozens of others asking the same questions I'd had, but no one was delivering the answers.  Or not all the answers, at any rate... In this article, I'll give you a tour of the code for a simple component and its control panel, with notes on how to make your own components.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d nearly given up the whole idea, having searched all over the internet only to find dozens of others asking the same questions I&#8217;d had, but no one was delivering the answers.  Or not all the answers, at any rate.</p>
<p>As seemingly exhaustive as Adobe&#8217;s <a href="http://www.adobe.com/devnet/flash/articles/creating_as3_components.html" target="_blank">gigantic article</a> by Jeff Kamerer is, many answers were not to be found there.  I wanted to make an SWC-based component that did not rely on the UI Component framework &#8212; after all, not every component is a UI gadget!  I wanted to write a simple class to draw something to the stage, with a few options I could control with my own control panel and see updated with a live preview right on the stage.</p>
<p>Along the way to a solution, I encountered a host of problems getting the control panel to communicate with the authoring tool, and for the authoring tool to communicate properly with the component and the control panel&#8230; and then even with all of those problems cleared up, there was still the problem of parameter settings being retained in the finished compiled product.  It seems quite clear that several aspects of component creation do not work as they should&#8211;at least not when you add a custom control panel into the mix.  However, in spite of all the problems, there is a reasonable workaround to make this possible.</p>
<p>Eventually, after a lot of googling about, and a whole lot of trial and error, I managed to piece together this jigsaw puzzle, and can now present to you a method for creating your very own components with custom control panels, all in Actionscript 3, which works for both Flash CS3 and CS4.  In this article, I&#8217;ll give you a tour of the code for a simple component and its control panel, with notes on how to make your own components.</p>
<p><a href="http://studio.barliesque.com/blog/download/make_a_component.zip"><strong><span style="color: #ff0000;">CLICK HERE</span></strong></a><strong> to download the complete source files.</strong><strong></strong></p>
<p><br class="spacer_" /></p>
<h1>THE COMPONENT</h1>
<h3>Defining Parameters</h3>
<p>First, let&#8217;s take a look at the source code for the component.  Open up &#8220;MyComponent.as&#8221;  &#8230;In order to inform Flash what the parameters for this component will be, we have to include [Inspectable] metadata tags in the class code.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"> <span style="color: #000000;">&#91;</span>Inspectable <span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span> = <span style="color: #990000;">&quot;color&quot;</span>, variable = <span style="color: #990000;">&quot;color&quot;</span>, <span style="color: #004993;">type</span> = <span style="color: #990000;">&quot;Color&quot;</span>, defaultValue = <span style="color: #990000;">&quot;FF0000&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
 <span style="color: #000000;">&#91;</span>Inspectable <span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span> = <span style="color: #990000;">&quot;radius&quot;</span>, variable = <span style="color: #990000;">&quot;radius&quot;</span>, <span style="color: #004993;">type</span> = <span style="color: #990000;">&quot;Number&quot;</span>, defaultValue = <span style="color: #990000;">&quot;10&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span></pre></div></div>

<p>I&#8217;ve placed them right at the top of the class, for easy reference.  Both parameters&#8211;radius and color&#8211;are going to call getter/setters which you&#8217;ll find near the end of the file.  There are a few important things to notice here:</p>
<ul>
<li>The name and variable for each parameter MUST be the same</li>
<li>All of the parameters MUST be in alphabetical order</li>
<li>The default values must be set BOTH in the meta-data and the code</li>
</ul>
<p>Of course these are hardly official requirements for writing a component, and I&#8217;m sure there are plenty of components out there that were not written following these rules.  However, in order to create this component with a custom user interface in the Component Inspector and with live preview&#8230; all three of these rules must be observed.</p>
<p>Note also that the default value for color is represented as a hex string without the leading &#8220;#&#8221; or &#8220;0x&#8221;</p>
<p><br class="spacer_" /></p>
<h3>The setSize() Method</h3>
<p>Moving on, the setSize() method is where we handle resizing of the component.  The Flash authoring tool will automatically call this function for live preview, so it must be defined as public, and with parameters for width and height.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setSize<span style="color: #000000;">&#40;</span>w<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, h<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_width = w;
	_height = h;
	<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_background.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	_background.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>_color, <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
	_background.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRoundRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span>, _width, _height, _radius, _radius<span style="color: #000000;">&#41;</span>;
	_background.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; 
&nbsp;
	_tf.<span style="color: #004993;">text</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>_width<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; x &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">Math</span>.<span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>_height<span style="color: #000000;">&#41;</span>;
	_tf.<span style="color: #004993;">x</span> = <span style="color: #000000;">&#40;</span>_width <span style="color: #000000; font-weight: bold;">-</span> _tf.<span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">0.5</span>;
	_tf.<span style="color: #004993;">y</span> = <span style="color: #000000;">&#40;</span>_height <span style="color: #000000; font-weight: bold;">-</span> _tf.<span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">0.5</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Some component source examples I&#8217;ve come across have defined a draw() method as protected, with a drawNow() method to provide public access.  I have found no requirement for this, except perhaps when working with the UIComponent framework.</p>
<p><br class="spacer_" /></p>
<h3>Parameter get/set functions</h3>
<p>Next, the getter/setter functions for our parameters, color and radius.  We need to use getter/setter rather than public properties so that whenever these values change, we can redraw the component.  This will keep the component updated both for live preview and at runtime.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> radius<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span> <span style="color: #0033ff; font-weight: bold;">return</span> _radius; <span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> radius<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_radius = <span style="color: #004993;">value</span>;
	<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">color</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> <span style="color: #000000;">&#123;</span> <span style="color: #0033ff; font-weight: bold;">return</span> _color; <span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">color</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_color = <span style="color: #004993;">value</span>;
	<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><br class="spacer_" /></p>
<h3>Override width and height</h3>
<p>Finally, we must override the getter/setter functions for width and height.  If we don&#8217;t, then when an actionscript call is used to change the dimensions of our component, it would merely be stretched or squashed.  What we want is to redraw the component with the new size.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">width</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span> <span style="color: #0033ff; font-weight: bold;">return</span> _width; <span style="color: #000000;">&#125;</span>
override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">width</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_width = <span style="color: #004993;">value</span>;
	<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">height</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span> <span style="color: #0033ff; font-weight: bold;">return</span> _height; <span style="color: #000000;">&#125;</span>
override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">height</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_height = <span style="color: #004993;">value</span>;
	<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><br class="spacer_" /></p>
<h3>Compile and Test</h3>
<p>Let&#8217;s compile the component and try it out without any custom control panels, just for starters.  Open up &#8220;Make a Component.fla&#8221;  You&#8217;ll find just one library item, a MovieClip called &#8220;MyComponent.&#8221;  It&#8217;s not quite ready to be compiled as it is.  Double-click the item to open it up on the stage.  You&#8217;ll find just one object, called &#8220;avatar&#8221; which the component code will use for default dimensions and as a simple means of setting font format properties as well as embedding the font.  All right let&#8217;s compile&#8230;</p>
<ol>
<li>In the Library, right click &#8220;MyComponent&#8221; and click on &#8220;Properties&#8221;</li>
<li>Tick the box: &#8220;Export for ActionScript&#8221;  Since the class box will have automatically set itself to &#8220;MyComponent&#8221; it will use our component code.</li>
<li>Click OK, and again, right click &#8220;MyComponent&#8221; in the Library and click on &#8220;Component Definition&#8230;&#8221;</li>
<li>As redundant as it is, type &#8220;MyComponent&#8221; into the Class box here also, and then click OK.</li>
<li>Again, right click &#8220;MyComponent&#8221; in the Library and click on &#8220;Component Definition&#8230;&#8221;</li>
<p><strong>NOTE:</strong> <em>The parameters part of this dialog will now show our parameters, radius and color.  Frankly, this dialog was built backwards:  it ought to have filled in the Class from the Properties dialogue, and from that the Parameters.  But that&#8217;s not how it works.  What&#8217;s more, don&#8217;t bother trying to rearrange your parameters using the buttons provided&#8211;those changes will be lost.  You see, as soon as you click OK in this dialog, Flash reads in the Class file, searching for meta-data and rebuilds the parameters table&#8230;!</em></p>
<li>Tick the box: &#8220;Display in Components Panel&#8221; and click OK.</li>
<li>Now right click &#8220;MyComponent&#8221; one more time and click on &#8220;Export SWC File&#8230;&#8221;</li>
<li>Make a new folder in: &#8220;C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Components&#8221; called &#8220;My Components&#8221; or &#8220;Test Components&#8221; or whatever you like.</li>
<li>Export the SWC file to this foler.</li>
<li>Open up the Components panel (ctrl-F7 / <img src="/blog/media/command.gif" alt="" width="11" height="11" />-F7)</li>
<li>Click the panel options button (the tiny black triangle in the upper right corner of the panel) and click on &#8220;Reload&#8221;</li>
<p><strong>NOTE:</strong> <em>Whenever you re-compile your SWC file, you must reload the Components panel for Flash to load in the updated version.</em></p>
<li>You should see the name of the folder you created your component in, so open that and you&#8217;ll find your new component.</li>
<li>Make a new Flash document where we&#8217;ll give the component a try out.</li>
<li>Drag the MyComponent from the Library panel onto the stage.  You should see something like this:</li>
<p style="text-align: center;"><img class="aligncenter" src="/blog/media/onstage.jpg" alt="The Component on Stage" /></p>
<p>Tthe avatar has been replaced.  Our component code has been run, right on the stage.</p>
<li>With the component selected, click on the Parameters tab of the Properties panel.</li>
<li>Try changing the parameter values.  Immediately as you change the values, the component updates itself.</li>
<li>Save this file as &#8220;Test Component.fla&#8221; and we&#8217;ll come back to it later.</li>
</ol>
<h1>CUSTOM CONTROL PANEL</h1>
<p>Something to keep in mind is that our custom control panel will not communicate directly with the component instance.  Rather, the control panel adjusts parameter settings in the authoring tool, and the authoring tool in turn modifies the component instance.  The component instance receives information via the setSize() method and property setters, and has no means of its own to communicate with either the authoring tool or the control panel. Keeping our parameters in alphabetical order, rather than trying to arrange them in some logical order, allows us to avoid a minefield of problems.</p>
<p><br class="spacer_" /></p>
<h3>Reading Parameter Values</h3>
<p>Let&#8217;s have a look at the source code for our control panel.  Open up &#8220;ControlPanel.as&#8221;  Once again, right near the top of the file are references to our parameters:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> const PARAMETER_COLOR<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;fl.getDocumentDOM().selection[0].parameters[0].value&quot;</span>;
<span style="color: #0033ff; font-weight: bold;">private</span> const PARAMETER_RADIUS<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;fl.getDocumentDOM().selection[0].parameters[1].value&quot;</span>;</pre></div></div>

<p>These instructions refer to parts of the Flash authoring tool&#8217;s user interface using the JSFL language&#8211;specifically, the parameters panel of the selected object.  <em>(See below under </em><strong><em>Further Reading </em></strong><em>for more details about JSFL.)</em> Notice that the numbering of the parameters follows the alphabetical order we&#8217;ve maintained.  Although it&#8217;s not required to set these constants, it makes the rest of the code considerably more readable.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ControlPanel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #004993;">color</span>.<span style="color: #004993;">text</span> = MMExecute<span style="color: #000000;">&#40;</span>PARAMETER_COLOR<span style="color: #000000;">&#41;</span>;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">color</span>.<span style="color: #004993;">text</span>.<span style="color: #004993;">substr</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #990000;">&quot;#&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">color</span>.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;#&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> dec2hex<span style="color: #000000;">&#40;</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">color</span>.<span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">color</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">CHANGE</span>, setColorFromText, <span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
	colorPicker.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>ColorPickerEvent.<span style="color: #004993;">CHANGE</span>, setColor, <span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	radius.<span style="color: #004993;">text</span> = MMExecute<span style="color: #000000;">&#40;</span>PARAMETER_RADIUS<span style="color: #000000;">&#41;</span>;
	radius.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">CHANGE</span>, setRadiusFromText, <span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
	radiusSlider.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>SliderEvent.<span style="color: #004993;">CHANGE</span>, setRadius, <span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, setControls, <span style="color: #0033ff; font-weight: bold;">false</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900;">//......................</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> setControls<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	setColorFromText<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	setRadiusFromText<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, setControls<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>In the class constructor function, we read the current control panel values and apply them to our controls.  Using the <code>MMExecute()</code> function (which is made available by importing the package: <code>adobe.utils.MMExecute</code>) allows us to execute our JSFL code defined in those two constants above.</p>
<p>The slider and the color picker components&#8217; default parameter values will be applied right after our control panel is instantiated.  Hence, the code to set those controls had to be called from an ENTER_FRAME event listener, so that it would occur <em>after</em> those components had been initialized.</p>
<p><br class="spacer_" /></p>
<h3>Setting Parameter Values</h3>
<p>Whenever parameters are changed, either with the handy slider &amp; color picker, or with the text fields, setting the parameters in the authoring tool requires another simple call to <code>MMExecute():</code></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">MMExecute<span style="color: #000000;">&#40;</span>PARAMETER_RADIUS <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;=&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">value</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #009900;">// Which, assuming value is 20, is equivalent to...</span>
&nbsp;
MMExecute<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;fl.getDocumentDOM().selection[0].parameters[1].value = 20&quot;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>That&#8217;s really there is to it.  The remainder of the ControlPanel.as code works like any other Flash form, updating text and components to work together, and using l to <code>MMExecute()</code> to update the authoring tool.  The authoring tool in turn sets variables in our component instance to update the live preview.  Now let&#8217;s add this control panel to our component&#8230;</p>
<p><br class="spacer_" /></p>
<h3>Compile the Component with Custom UI</h3>
<ol>
<li>Compile the control panel (Shift-F12) creating &#8220;Component Control Panel.swf&#8221;</li>
<li>Now, re-open &#8220;Make a Component.fla&#8221; and right-click MyComponent in the Library panel, then click &#8220;Component Definition&#8230;&#8221;</li>
<li>Across from &#8220;Custom UI:&#8221; click on the Set button.</li>
<li>Select &#8220;Custom UI in external .swf file&#8221;
<ul>
<li>Select &#8220;Display in Component Inspector panel&#8221;</li>
<li>Assign the Custom UI .swf file by clicking on &#8220;Browse&#8230;&#8221; and selecting &#8221;Component Control Panel.swf&#8221; which we just created.</li>
<li>Click OK</li>
</ul>
</li>
<li>Click OK</li>
<li>We&#8217;re ready to re-compile the component.  Right-click MyComponent and click on &#8220;Export SWC File&#8230;&#8221; and overwrite the older SWC file we created</li>
<li>Update the Component panel by clicking the panel options button (the tiny black triangle in the upper right corner of the panel) and click on &#8220;Reload&#8221;</li>
<li>Re-open your test file: &#8220;Test Component.fla&#8221;</li>
<li>Click and drag the updated component from the Coponents panel, into the Library panel.  You should see the dialog: &#8220;One or more library items already exist in the document.&#8221;  Select &#8220;Replace existing items&#8221; to update your test file.</li>
<li>Now when you click on a component instance on the stage, the Parameters panel will no longer allow parameters to be set there, but will give you a button to launch the Component Inspector, which is where our control panel will appear. </li>
<p><strong>NOTE:</strong> <em>By choosing &#8220;Display in Property Inspector&#8221; in step 4, you can get your control panel to appear in the Parameters tab.  However, in this example case, the color picker demands more space than is available there.</em></p>
<li>Try making a few variations of the component on stage and compile your test movie.</li>
</ol>
<h1>CONCLUSION</h1>
<p>Thanks for reading!  I hope you&#8217;ve found this tutorial helpful.  Check out the file &#8220;Use the Component.fla&#8221; and its base class &#8220;UseComponent.as&#8221; for various tests which helped me to refine this method and write this tutorial.  There is also an illustration of the one issue, described below, that I have as yet been unable to resolve.  If you should come up with a solution, please be sure to post about it here!</p>
<p><br class="spacer_" /></p>
<h3>Known Issue:</h3>
<p>If I rotate the component on the stage in the authoring tool, its width and height are incorrectly reported as an unrotated bounding box, which will inevitably be larger than the correct dimensions, as shown below:</p>
<p><img class="aligncenter size-full wp-image-110" title="error-authoring" src="http://studio.barliesque.com/blog/wp-content/uploads/2008/12/error-authoring.jpg" alt="error-authoring" width="331" height="305" /></p>
<p>The selected component shows its correct dimensions as 83 x 17, while the authoring tool shows the incorrect dimensions 70.2 x 70.2.  At runtime, the component is initialized with those incorrect dimensions:</p>
<p><img class="aligncenter size-full wp-image-111" title="error-runtime" src="http://studio.barliesque.com/blog/wp-content/uploads/2008/12/error-runtime.jpg" alt="error-runtime" width="313" height="130" /></p>
<p><b>[UPDATE]</b>&nbsp;&nbsp;<i>A solution to this problem is presented by Juan Carlos in a comment that follows this post.</i></p>
<p><br class="spacer_" /></p>
<h3>Further Reading:</h3>
<p>Read about the [Inspectable] meta-data tag:<br />
 <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=metadata_3.html#159728" target="_blank"> http://livedocs.adobe.com/flex/3/html/help&#8230;</a><br />
 <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00002498.html" target="_blank"> http://livedocs.adobe.com/flash/9.0/main/&#8230;</a><br />
 It seems this information does pertain to AS3 as compiled by Flash CS3+, but I have never found documentation except as it pertains either to Flex or to AS2.</p>
<p>To find out more about JSFL and what you can do with <code>MMExecute()</code>, take a look at this excellent video by Lee Brimelow about creating panels to extend the Flash IDE:<br />
 <a href="http://gotoandlearn.com/play?id=66" target="_blank"> http://gotoandlearn.com/play?id=66</a></p>
<p>This reference to extending Flash provides full details of JSFL support in Flash:<br />
 <a href="http://livedocs.adobe.com/flash/9.0/main/flash_cs3_extending.pdf" target="_blank">http://livedocs.adobe.com/flash/9.0/main/flash_cs3_extending.pdf</a></p>
<p>&#8230;and a tutorial on creating FLA-based components:<br />
<a href="http://www.flashbrighton.org/wordpress/?p=31" target="_blank">http://www.flashbrighton.org/wordpress/?p=31</a></p>
]]></content:encoded>
			<wfw:commentRss>http://studio.barliesque.com/blog/2008/12/as3-component-custom-ui/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Flash sniffer bug solved</title>
		<link>http://studio.barliesque.com/blog/2008/12/flash-sniffer-bug-solved/</link>
		<comments>http://studio.barliesque.com/blog/2008/12/flash-sniffer-bug-solved/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 16:00:00 +0000</pubDate>
		<dc:creator>barliesque</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[browser sniffer]]></category>
		<category><![CDATA[brwsniff.js]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[flash player]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jsbrwsniff]]></category>
		<category><![CDATA[mozilla]]></category>

		<guid isPermaLink="false">http://studio.barliesque.com/blog/?p=45</guid>
		<description><![CDATA[Ever since Flash Player 10 arrived on the scene, Flash websites here and there have begun having a problem recognizing what version is really installed...]]></description>
			<content:encoded><![CDATA[<p>Ever since Flash Player 10 arrived on the scene, Flash websites here and there have begun having a problem:  They&#8217;ll insist that you need a newer version of Flash Player, in spite of the fact that you&#8217;ve got version 10 happily installed.  If you&#8217;re running Internet Explorer, you won&#8217;t have any problem, but if you&#8217;re running Firefox, Safari, Netscape, or Google&#8217;s new Chrome browser, then there&#8217;s trouble.</p>
<p>The problem lies in a small javascript file:  <a href="http://jsbrwsniff.sourceforge.net/index.html" target="_blank&quot;">brwsniff.js</a>, a handy dandy browser sniffer that checks for the installed Flash Player version number.  The bit of code written for non-IE browsers wasn&#8217;t expecting a player with a version number of more than one digit; so, seeing only the one&#8217;s place digit, if you&#8217;ve got Flash Player 10 installed, the script comes up with a version number of ZERO! <img src='http://studio.barliesque.com/blog/wp-includes/images/smilies/07.png' alt=':arg:' class='wp-smiley' /> </p>
<p>Unfortunately, the author of this otherwise delightful script has not updated the file since before Flash Player 10 was released.  Having made the minor repair necessary, I&#8217;m making my updated version available for download <a href="http://studio.barliesque.com/blog/download/brwsniff.zip"><strong><span style="color: #ff0000;">HERE</span></strong></a>.</p>
<p><strong>Please note: </strong><em> If for some reason you needed this script to detect the browser software in use, I&#8217;m afraid you&#8217;re still out of luck.  The script seems to see everything as either IE or Firefox.</em></p>
<p><em><strong>[UPDATE]<br />
<span style="font-weight: normal;"><span style="font-style: normal;">Got a message from Pau Garcia i Quiles, author of jsbrwsniff.  He&#8217;ll publish a bugfix soon&#8212;until he does, download the version posted here.  I&#8217;ll announce when an official bug fix becomes available.  New features he&#8217;s planning to add in the coming months:</span></span></strong></em></p>
<p><em><strong><span style="font-weight: normal;"><span style="font-style: normal;"></p>
<ul>
<li>Encapsulation to avoid namespace clashing</li>
<li>Java version detection</li>
<li>Adobe PDF detection</li>
</ul>
<p></span></span></strong></em></p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://studio.barliesque.com/blog/2008/12/flash-sniffer-bug-solved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Developer in the Bowler Hat</title>
		<link>http://studio.barliesque.com/blog/2008/12/flash-developer-in-the-bowler-hat/</link>
		<comments>http://studio.barliesque.com/blog/2008/12/flash-developer-in-the-bowler-hat/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 01:43:14 +0000</pubDate>
		<dc:creator>barliesque</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[MORFsite]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Magritte]]></category>
		<category><![CDATA[surrealism]]></category>

		<guid isPermaLink="false">http://studio.barliesque.com/blog/?p=37</guid>
		<description><![CDATA[My new portfolio site is finally ready for public viewing.  The design of the site is an homage to one of my favorite artists, the Belgian surrealist René Magritte.  Even if you've never heard the name, you've probably seen his most famous image...]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://studio.barliesque.com" target="_blank"><img title="Flash Developer in the Bowler Hat" src="http://studio.barliesque.com/blog/media/500x364.jpg" alt="Screenshot of my new portfolio website: http://studio.barliesque.com" width="500" height="364" /></a></p>
<p>My new <a href="http://studio.barliesque.com" target="_blank">portfolio site</a> is finally ready for public viewing.  The design of the site is an homage to one of my favorite artists, the Belgian surrealist <a href="http://en.wikipedia.org/wiki/Magritte,_Ren%C3%A9" target="_blank">René Magritte</a>.  Even if you&#8217;ve never heard the name, you&#8217;ve probably seen his most famous image somewhere:  A man in a bowler hat, with the sea behind him&#8230; and a green apple floating mysteriously right in front of his face.  Monsieur Magritte is responsible for numerous iconic images like this one, and in my design of this site (as with the background image for this blog) I&#8217;ve created various sorts of references to his style, some spoofs of his most famous paintings&#8230; with the addition of animation!</p>
<p>Another point of interest is that this site is the first project I&#8217;ve completed using my new Actionscript 3 framework:  MORFsite.  Although there&#8217;s still a fair bit more functionality yet to be added to it before it&#8217;s complete, MORFsite already covers these features&#8230;</p>
<ul>
<li>handles overall site architecture and navigation events</li>
<li>manages media and data resources</li>
<li>maintains the visual layout of the site</li>
</ul>
<p>I still need to integrate SWFaddress and tie up some loose ends.  When I do, my plan is to release MORFsite as an open source project.</p>
<p>Anyway, enough babble!  Go visit my new portfolio site:   <a href="http://studio.barliesque.com">http://studio.barliesque.com</a></p>
<p><strong>[UPDATE]</strong> The site was just awarded a <a title="PickA Awards - Adobe Flash Design Awards" href="http://www.pickaward.com/" target="_blank">PickA</a> Gold Award!  (21 January 2009)</p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://studio.barliesque.com/blog/2008/12/flash-developer-in-the-bowler-hat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting into Papervision3D</title>
		<link>http://studio.barliesque.com/blog/2008/10/getting-into-papervision3d/</link>
		<comments>http://studio.barliesque.com/blog/2008/10/getting-into-papervision3d/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 21:06:56 +0000</pubDate>
		<dc:creator>barliesque</dc:creator>
				<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://studio.barliesque.com/blog/?p=27</guid>
		<description><![CDATA[<script type="text/javascript" src="http://studio.barliesque.com/blog/wp-includes/js/jquery/jquery.js"></script><script type="text/javascript" src="http://studio.barliesque.com/blog/wp-content/plugins/pb-embedflash/js/sbadapter/shadowbox-jquery.js"></script><script type="text/javascript" src="http://studio.barliesque.com/blog/wp-content/plugins/pb-embedflash/js/shadowbox.js"></script><script type="text/javascript"><!--
window.onload = function() {var options ={assetURL:'',loadingImage:'http://studio.barliesque.com/blog/wp-content/plugins/pb-embedflash/css/images/loading.gif',flvPlayer:'http://studio.barliesque.com/blog/wp-content/plugins/pb-embedflash/swf/mediaplayer.swf',animate:true,animSequence:'wh',overlayColor:'#000',overlayOpacity:0.85,overlayBgImage:'http://studio.barliesque.com/blog/wp-content/plugins/pb-embedflash/css/images/overlay-85.png',listenOverlay:true,autoplayMovies:true,showMovieControls:true,resizeDuration:0.35,fadeDuration:0.35,displayNav:true,continuous:false,displayCounter:true,counterType:'default',viewportPadding:20,handleLgImages:'resize',initialHeight:160,initialWidth:320,enableKeys:true,keysClose:['c', 'q', 27],keysPrev:['p', 37],keysNext:['n', 39],handleUnsupported:'',text: {cancel:'Cancel',loading: 'loading',close:'<span class="shortcut">C</span>lose',next:'<span class="shortcut">N</span>ext',prev:'<span class="shortcut">P</span>revious',errors:{single: 'You must install the <a href="{0}">{1}</a> browser plugin to view this content.',shared: 'You must install both the <a href="{0}">{1}</a> and <a href="{2}">{3}</a> browser plugins to view this content.',either: 'You must install either the <a href="{0}">{1}</a> or the <a href="{2}">{3}</a> browser plugin to view this content.'}}};Shadowbox.init(options);}
--></script><p>I&#8217;m having fun right now getting into Papervision3D.  I took some time deciding on whether to go ahead with ver.2  Lack of documentation and examples was starting to make me think it&#8217;d be best to go with an older version.  As it turns out, there are plenty of resources out there, it&#8217;s just a matter of locating them!  Here are links to the&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m having fun right now getting into Papervision3D.  I took some time deciding on whether to go ahead with ver.2  Lack of documentation and examples was starting to make me think it&#8217;d be best to go with an older version.  As it turns out, there are plenty of resources out there, it&#8217;s just a matter of locating them!  Here are links to the most helpful sites I&#8217;ve found so far, with  useful examples, tutorials and documentation&#8230;</p>
<p><a href="http://www.pv3d.org" target="_blank">http://www.pv3d.org</a><br />
 <a href="http://papervision2.com" target="_blank">http://papervision2.com</a><br />
 <a href="http://www.dehash.com/?page_id=202" target="_blank"> http://www.dehash.com/?page_id=202</a><br />
 <a href="http://www.flashbookmarks.com/PV3D-Beta2-DOC" target="_blank"> http://www.flashbookmarks.com/PV3D-Beta2-DOC</a><br />
<a href="http://blog.zupko.info/?cat=8" target="_blank"> http://blog.zupko.info/?cat=8</a><br />
<a href="http://www.madvertices.com" target="_blank">http://www.madvertices.com</a>
</p>
<p>&#8230;and here&#8217;s a little 3D experiment I&#8217;ve been tinkering with as I learn how to use this exciting library:</p>
<p><small>(Please open the article to see the flash file or player.)</small></p>
<p>I&#8217;ll post some source code eventually for PV3D experiments soon&#8230;   <img src='http://studio.barliesque.com/blog/wp-includes/images/smilies/21b.png' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://studio.barliesque.com/blog/2008/10/getting-into-papervision3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The trouble with getBounds()</title>
		<link>http://studio.barliesque.com/blog/2008/10/the-trouble-with-getbounds/</link>
		<comments>http://studio.barliesque.com/blog/2008/10/the-trouble-with-getbounds/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 00:00:00 +0000</pubDate>
		<dc:creator>barliesque</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[getBounds]]></category>
		<category><![CDATA[masks]]></category>

		<guid isPermaLink="false">http://studio.barliesque.com/blog/?p=6</guid>
		<description><![CDATA[Keeping tabs on the exact position and dimensions of an object on the stage gets tricky when masks are involved.  None of Actionscript's native commands provide reliable results.  Here's an alternate solution...]]></description>
			<content:encoded><![CDATA[<p>What do you do when you want to know the exact details of an objects whereabouts on stage?  Within Actionscript&#8217;s command set, there are a few options, such as the object&#8217;s own <em>.x .y .width .height</em> properties.  However, your best bet is to call the <em>getBounds()</em> function.  That&#8217;ll tell you the extents of what&#8217;s being drawn to the screen.  That is, unless you happen to be using a mask inside the movie clip.</p>
<p>A tiny object being masked by a huge shape will cause <em>getBounds()</em> to return the extents of&#8230; the mask, not the visible object.  It gets even better if your object happens to move beyond the masked area&#8211;thus making it totally invisible.  Now <em>getBounds()</em> exapands to include the area of the giant mask plus that of the tiny object, which is no longer being drawn to the screen at all.</p>
<p>In fact, there appears to be no built-in method for reliably determining the actual screen area a MovieClip is occupying.  Do we call this a bug, or was it really meant to work this way???  <img src='http://studio.barliesque.com/blog/wp-includes/images/smilies/16.png' alt=':S' class='wp-smiley' /> </p>
<p>I decided to try writing a handy dandy function to remedy this problem, and in so doing discovered another serious limitation involving masks.  When you create an arrangement of layers in the Flash IDE with, let&#8217;s say three or four objects being masked by one mask, you&#8217;ve done something that apparently is only possible with the Flash IDE, and not with AS3.  If you have a look at the <em>.mask</em> property of each of those masked objects, they&#8217;ll all be set to NULL.  There&#8217;s no sign of any masking going on, as far as ActionScript is concerned.  Suppose you manually set the <em>.mask</em> property of one of those three or four masked objects?  The result is that all the other objects will be unmasked.  Using the <em>.mask</em> property strictly pairs one mask to one display object.  So now you&#8217;ve got to find a way of duplicating your mask, so each object has its own mask&#8230;!   <img src='http://studio.barliesque.com/blog/wp-includes/images/smilies/46.png' alt=':grit:' class='wp-smiley' /> </p>
<p>Well, nonetheless I wrote my own routine: <em>getVisibility()</em> which reliably tracks down whatever is actually visible, and nothing more.  It&#8217;s reliable, that is, as long as you manually set your masks in code&#8211;one mask for each object.  If a better solution exists, I&#8217;d like to know about it.  For now, here&#8217;s a little demo of my function versus AS3&#8217;s native functions&#8230;</p>
<p><script type="text/javascript" src="http://studio.barliesque.com/blog/wp-content/plugins/pb-embedflash/js/swfobject.js"></script><span class="embedflash" id="swfide6d881dd90b38197c0f8d4ffbf206450"><small>(Please open the article to see the flash file or player.)</small></span><script type="text/javascript">
				var flashvars = {}; var params = {}; var attributes = {};params.allowfullscreen = "true"; params.allowscriptaccess = "always";
				swfobject.embedSWF("http://studio.barliesque.com/blog/media/Visibility.swf","swfide6d881dd90b38197c0f8d4ffbf206450","500","600","9.0.0","http://studio.barliesque.com/blog/wp-content/plugins/pb-embedflash/swf/expressInstall.swf",flashvars,params,attributes);
		</script></p>
<p>There&#8217;s only one error I can detect in the result of <em>getVisibility()</em> &#8230;When objects are rotated, their visibility is based upon a rotated bounding box, rather than the precise shape of the object.  Still, this gets us considerably closer to a solution.</p>
<p>The .fla can be downloaded <a title="Visibility.fla" href="http://studio.barliesque.com/blog/media/Visibility.fla"><strong>HERE</strong></a>.  Here&#8217;s the code for my <em>getVisibility()</em> function&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> getVisibility<span style="color: #000000;">&#40;</span>obj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> vis<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>obj.<span style="color: #004993;">parent</span> == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>obj <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		vis = getChildVisibility<span style="color: #000000;">&#40;</span>obj, obj.<span style="color: #004993;">parent</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
		vis = obj.<span style="color: #004993;">getBounds</span><span style="color: #000000;">&#40;</span>obj.<span style="color: #004993;">parent</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900;">// Is the DisplayObject masked?</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>obj.<span style="color: #004993;">mask</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		vis = vis.<span style="color: #004993;">intersection</span><span style="color: #000000;">&#40;</span>obj.<span style="color: #004993;">mask</span>.<span style="color: #004993;">getBounds</span><span style="color: #000000;">&#40;</span>obj.<span style="color: #004993;">parent</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900;">// Is the DisplayObject partly or completely off-stage?</span>
	vis = vis.<span style="color: #004993;">intersection</span><span style="color: #000000;">&#40;</span>obj.<span style="color: #004993;">stage</span>.<span style="color: #004993;">getBounds</span><span style="color: #000000;">&#40;</span>obj.<span style="color: #004993;">parent</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">return</span> vis;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> getChildVisibility<span style="color: #000000;">&#40;</span>obj<span style="color: #000000; font-weight: bold;">:*</span>, <span style="color: #004993;">target</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> vis<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">child</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> childRect<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">1</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span>= obj.<span style="color: #004993;">numChildren</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">child</span> = obj.<span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span>.<span style="color: #004993;">visible</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span> <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					childRect = getChildVisibility<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span>, <span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
					childRect = <span style="color: #004993;">child</span>.<span style="color: #004993;">getBounds</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span>.<span style="color: #004993;">mask</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					childRect = childRect.<span style="color: #004993;">intersection</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span>.<span style="color: #004993;">mask</span>.<span style="color: #004993;">getBounds</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
				vis = vis.<span style="color: #004993;">union</span><span style="color: #000000;">&#40;</span>childRect<span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> vis;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://studio.barliesque.com/blog/2008/10/the-trouble-with-getbounds/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>My first post to my first blog</title>
		<link>http://studio.barliesque.com/blog/2008/10/my-first-post-to-my-first-blog/</link>
		<comments>http://studio.barliesque.com/blog/2008/10/my-first-post-to-my-first-blog/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 23:17:13 +0000</pubDate>
		<dc:creator>barliesque</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[david barlia]]></category>
		<category><![CDATA[flash animator]]></category>
		<category><![CDATA[flash developer]]></category>

		<guid isPermaLink="false">http://studio.barliesque.com/blog/?p=16</guid>
		<description><![CDATA[<p>Thanks for stopping by!</p>
<p>All these years of designing and developing and I&#8217;ve never had a blog to call my own.  The shame of it!  Well, through the magic of WordPress I&#8217;ve finally rectified this. Thanks also go to <a href="http://thebuckmaker.com/category/aeros/" target="_blank">TheBuckmaker</a> for the Aeros theme, to which I&#8217;ve added my own Magritte-inspired background image and a few minor modifications.</p>
<p>I&#8217;ll be posting&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Thanks for stopping by!</p>
<p>All these years of designing and developing and I&#8217;ve never had a blog to call my own.  The shame of it!  Well, through the magic of WordPress I&#8217;ve finally rectified this. Thanks also go to <a href="http://thebuckmaker.com/category/aeros/" target="_blank">TheBuckmaker</a> for the Aeros theme, to which I&#8217;ve added my own Magritte-inspired background image and a few minor modifications.</p>
<p>I&#8217;ll be posting about my travails with Adobe Flash and ActionScript3 in particular, but who knows what else may find its way onto this blog?</p>
<p>Sometime soon, I plan to release a proper announcement of my AS3 framework, MORFsite.  At present, I&#8217;m using it to complete a new website for myself&#8211;finally an up-to-date portfolio!  I&#8217;ll post about MORFsite soon, which I plan to release as an OpenSource project.  But not until it&#8217;s had a chance to mature with a couple of real live projects.</p>
<p>Well&#8230; on with the blog!</p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://studio.barliesque.com/blog/2008/10/my-first-post-to-my-first-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
