<?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>Thu, 08 Mar 2012 23:59:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>EasyAGAL Updates.  Testing suite planned&#8230;</title>
		<link>http://studio.barliesque.com/blog/2012/02/easyagal-updates-testing-suite-planned/</link>
		<comments>http://studio.barliesque.com/blog/2012/02/easyagal-updates-testing-suite-planned/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 21:17:49 +0000</pubDate>
		<dc:creator>barliesque</dc:creator>
				<category><![CDATA[AGAL]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Molehill]]></category>
		<category><![CDATA[EasyAGAL]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[GPU]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Shaders]]></category>
		<category><![CDATA[Stage3D]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://studio.barliesque.com/blog/?p=203</guid>
		<description><![CDATA[I've just made the first update of the year to EasyAGAL, and wanted to let everyone know about that along with some of my plans for the library's future, including a new testing suite.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just made the first update of the year to <strong><a href="http://github.com/Barliesque/EasyAGAL" title="Download EasyAGAL from GitHub" target="_blank">EasyAGAL</a></strong>, and wanted to let everyone know about that along with some of my plans for the library&#8217;s future.</p>
<ul>
<li>Compiled library to a SWC</li>
<li>Added BlendHSL macros including: hue, saturation, luminosity and color blend functions</li>
<li>Added ColorSpace macros, featuring conversion between RGB &#038; HSL, desaturate, colorize, etc.</li>
<li>Added new functions to RegisterType:  isConst(),  isTemp() , isReadOnly()</li>
<li>Corrected an error in Component.as, register type was not passed on to component</li>
</ul>
<p>So, with the addition of those HSL color space macros, that finally completes the library of color blending functions.  Though, I do still need to add a little something to handle alpha blending&#8230; (Coming soon!)  Online documentation has also been updated:  <a href="http://barliesque.com/easy_agal/docs/" title="EasyAGAL Online Documentation" target="_blank">http://barliesque.com/easy_agal/docs/</a></p>
<p>I&#8217;ve also just begun work on a testing suite.  What that means is that you&#8217;ll be able to write a shader in the usual way, and then run it in a sort of test mode;  which means you&#8217;ll be able to do things like add trace statements to find out what values are in a given register to find out where a calculation is going wrong.  It&#8217;s a pretty big undertaking, but I think I&#8217;ve got it figured out.  I welcome any suggestions here about what sort of features you&#8217;d like the EasyAGAL test suite to include.</p>
<p>Happy coding,<br />
David<br />
 <img src='http://studio.barliesque.com/blog/wp-includes/images/smilies/35.png' alt=':cool:' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://studio.barliesque.com/blog/2012/02/easyagal-updates-testing-suite-planned/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>EasyAGAL &#8211; Macros and Aliases</title>
		<link>http://studio.barliesque.com/blog/2011/09/easyagal-macros-and-aliases/</link>
		<comments>http://studio.barliesque.com/blog/2011/09/easyagal-macros-and-aliases/#comments</comments>
		<pubDate>Sat, 24 Sep 2011 01:49:29 +0000</pubDate>
		<dc:creator>barliesque</dc:creator>
				<category><![CDATA[AGAL]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Molehill]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Alias]]></category>
		<category><![CDATA[EasyAGAL]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Macro]]></category>
		<category><![CDATA[Register]]></category>
		<category><![CDATA[Shaders]]></category>
		<category><![CDATA[Stage3D]]></category>

		<guid isPermaLink="false">http://studio.barliesque.com/blog/?p=171</guid>
		<description><![CDATA[In this article I'll show you how you can create and use a library of macro functions written with EasyAGAL. The more macros we have to work with, the more AGAL can begin to feel like a higher level language...]]></description>
			<content:encoded><![CDATA[<p>In this article I&#8217;ll show you how you can create and use a library of macro functions written with EasyAGAL. The more macros we have to work with, the more AGAL can begin to feel like a higher level language.</p>
<p>In case the term is unfamiliar to you, a macro is similar to a function in that it&#8217;s a bit of code that gets used and re-used repeatedly. The difference is that, where a function exists in one place in memory and is called by multiple points in an application, a macro is literally duplicated wherever it&#8217;s needed at compile-time. Presently, there is no way for AGAL to redirect program execution to call a function, or branch or loop &#8212; AGAL programs are executed in a straight shot, from top to bottom. So, in place of functions we must use macros.</p>
<p>Wherever you use a function from the Easy/EasierAGAL library, instructions are appended to whatever code is being assembled at the time. So you can write a set of handy static functions in their own class, to be called as needed. You can pass EasyAGAL registers as parameters, or any other data that may be useful to customize the macro. And you can organize your macros along with the rest of your ActionScript classes into logical packages so they&#8217;re nice and easy to find when you need them.</p>
<p><br/></p>
<h3>Interface types</h3>
<p>There is one important rule in writing macros with EasyAGAL: you may not use any register that is not passed to your macro as a parameter. This is a good rule to abide by because it means that the user of the macro retains control over how registers are used; it helps to keep your macros as reusable as possible. When you define function parameters, or alias variables, you have four data type options:</p>
<ul>
<li>
<p><code><strong>IRegister</strong></code><br />
Just as it sounds, this type specifies an AGAL register. The whole register, that is, so <code>CONST[0]</code> is an <code>IRegister</code>, but <code>CONST[0].xyz</code> is not. If the user of your macro tries to pass <code>VARYING[1].x</code> where an <code>IRegister</code> was specified, they&#8217;ll get a compile error.</p>
</li>
<li>
<p><code><strong>IComponent</strong></code><br />
Strictly a single component of a register. <code>CONST[0].x</code> is an <code>IComponent</code>, but <code>CONST[0].xyz</code> and <code>CONST[0]</code> are not.</p>
</li>
<li>
<p><code><strong>IField</strong></code><br />
This type specifies any AGAL register (except for texture samplers) &#8212; either the whole register, or a selection of components.</p>
</li>
<li>
<p><code><strong>ISampler</strong></code><br />
 This type specifies a texture <code>SAMPLER</code> register. Trying to pass <code>ATTRIBUTE[3]</code> to an <code>ISampler</code> parameter again results in a compile-time error. No component selections of sampler registers are supported by AGAL.</li>
</ul>
<p>So, for example, we can use ActionScript variables as aliases to AGAL registers, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">:</span>IRegister = ATTRIBUTE<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> projection<span style="color: #000066; font-weight: bold;">:</span>IRegister = CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
multiply4x4<span style="color: #000000;">&#40;</span>OUTPUT<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">,</span> projection<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p><br/></p>
<h3>A Simple Macro</h3>
<p>Here&#8217;s a really simple macro to set a register or component to zero:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setZero<span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">:</span>IField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// Subtract anything from itself and the result is always zero.</span>
	<span style="color: #004993;">subtract</span><span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> dest<span style="color: #000066; font-weight: bold;">,</span> dest<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I used <code>IField</code> for the parameter type because this allows the macro to be applied either to whole registers or individual components. Nothing is returned from the function, since its purpose is to append to the current shader code by calling the EasierAGAL command set. You might wonder, &#8220;Why bother to write a macro when there&#8217;s only one operation inside?&#8221; Simply because it&#8217;s clearer what the purpose of <code>setZero()</code> is compared to the subtraction statement.</p>
<p>Here&#8217;s another macro function to clamp a value to a range:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">static <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">clamp</span><span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">:</span>IField<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">source</span><span style="color: #000066; font-weight: bold;">:</span>IField<span style="color: #000066; font-weight: bold;">,</span> minValue<span style="color: #000066; font-weight: bold;">:</span>IField<span style="color: #000066; font-weight: bold;">,</span> maxValue<span style="color: #000066; font-weight: bold;">:</span>IField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">source</span><span style="color: #000066; font-weight: bold;">,</span> maxValue<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> dest<span style="color: #000066; font-weight: bold;">,</span> minValue<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I&#8217;ve placed these two functions in a class called <code>Utils</code>, so I can now use them in any Easy/EasierAGAL shader code, like so&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">Utils<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">clamp</span><span style="color: #000000;">&#40;</span>TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
Utils<span style="color: #000066; font-weight: bold;">.</span>zero<span style="color: #000000;">&#40;</span>TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>w<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>As if you didn&#8217;t already know how to call a static function! Anyway, you&#8217;ll find these and more in the package: <code>com.barliesque.shaders.macro</code></p>
<p><br/></p>
<h3>Other Parameter Types</h3>
<p>Obviously, when writing macros you can specify whatever parameter types you want, not just AGAL registers. Have a look at the parameter list of the following function, specifically the comparison parameter.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">static <span style="color: #0033ff; font-weight: bold;">public</span> const EQUAL<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;equal&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
static <span style="color: #0033ff; font-weight: bold;">public</span> const NOT_EQUAL<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;notEqual&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
static <span style="color: #0033ff; font-weight: bold;">public</span> const LESS_THAN<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;less&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
static <span style="color: #0033ff; font-weight: bold;">public</span> const GREATER_THAN<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;greater&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
static <span style="color: #0033ff; font-weight: bold;">public</span> const LESS_OR_EQUAL<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;lessOrEqual&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
static <span style="color: #0033ff; font-weight: bold;">public</span> const GREATER_OR_EQUAL<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;greaterOrEqual&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Return one of two results, based on a comparison of two values, componentwise
 * dest = (operandA compared with operandB) ? trueResult : falseResult
 * Contains 5 to 8 instructions.
 * @param       comparison      The type of comparison, e.g. Utils.NOT_EQUAL
 * @param       temp            A temporary register that will be utilized for this operation
 */</span>
static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setByComparison<span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">:</span>IField<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000066; font-weight: bold;">:</span>IField<span style="color: #000066; font-weight: bold;">,</span> comparison<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000066; font-weight: bold;">:</span>IField<span style="color: #000066; font-weight: bold;">,</span> 
                                        trueResult<span style="color: #000066; font-weight: bold;">:</span>IField<span style="color: #000066; font-weight: bold;">,</span> falseResult<span style="color: #000066; font-weight: bold;">:</span>IField<span style="color: #000066; font-weight: bold;">,</span> temp<span style="color: #000066; font-weight: bold;">:</span>IRegister<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// First make the requested comparison</span>
        <span style="color: #009900; font-style: italic;">// and set the temporary to the inverse</span>
        <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>comparison<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">case</span> LESS_OR_EQUAL<span style="color: #000066; font-weight: bold;">:</span>
                        setIf_GreaterEqual<span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        setIf_LessThan<span style="color: #000000;">&#40;</span>temp<span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">case</span> GREATER_OR_EQUAL<span style="color: #000066; font-weight: bold;">:</span>
                        setIf_GreaterEqual<span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        setIf_LessThan<span style="color: #000000;">&#40;</span>temp<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">case</span> EQUAL<span style="color: #000066; font-weight: bold;">:</span>
                        setIf_Equal<span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000066; font-weight: bold;">,</span> temp<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #009900; font-style: italic;">//  temp = 1 - dest</span>
                        setIf_GreaterEqual<span style="color: #000000;">&#40;</span>temp<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #004993;">subtract</span><span style="color: #000000;">&#40;</span>temp<span style="color: #000066; font-weight: bold;">,</span> temp<span style="color: #000066; font-weight: bold;">,</span> dest<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">case</span> NOT_EQUAL<span style="color: #000066; font-weight: bold;">:</span>
                        setIf_NotEqual<span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000066; font-weight: bold;">,</span> temp<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #009900; font-style: italic;">//  temp = 1 - dest</span>
                        setIf_GreaterEqual<span style="color: #000000;">&#40;</span>temp<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #004993;">subtract</span><span style="color: #000000;">&#40;</span>temp<span style="color: #000066; font-weight: bold;">,</span> temp<span style="color: #000066; font-weight: bold;">,</span> dest<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">case</span> LESS_THAN<span style="color: #000066; font-weight: bold;">:</span>
                        setIf_LessThan<span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        setIf_GreaterEqual<span style="color: #000000;">&#40;</span>temp<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">case</span> GREATER_THAN<span style="color: #000066; font-weight: bold;">:</span>
                        setIf_LessThan<span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        setIf_GreaterEqual<span style="color: #000000;">&#40;</span>temp<span style="color: #000066; font-weight: bold;">,</span> operandB<span style="color: #000066; font-weight: bold;">,</span> operandA<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">default</span><span style="color: #000066; font-weight: bold;">:</span>
                        <span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Unrecognized comparison type: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> comparison<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// Now apply result values to each...</span>
        multiply<span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> dest<span style="color: #000066; font-weight: bold;">,</span> trueResult<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        multiply<span style="color: #000000;">&#40;</span>temp<span style="color: #000066; font-weight: bold;">,</span> temp<span style="color: #000066; font-weight: bold;">,</span> falseResult<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// ...and combine results</span>
        <span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span>dest<span style="color: #000066; font-weight: bold;">,</span> dest<span style="color: #000066; font-weight: bold;">,</span> temp<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So, now I can perform a comparison and get a result value in a single line&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">&nbsp;
<span style="color: #009900; font-style: italic;">//</span>
<span style="color: #009900; font-style: italic;">// OUTPUT = (TEMP[1] &lt;= CONST[0]) ? CONST[2] : CONST[3]</span>
<span style="color: #009900; font-style: italic;">//</span>
Utils<span style="color: #000066; font-weight: bold;">.</span>setByComparison<span style="color: #000000;">&#40;</span>OUTPUT<span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> Utils<span style="color: #000066; font-weight: bold;">.</span>LESS_OR_EQUAL<span style="color: #000066; font-weight: bold;">,</span> CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p><br/></p>
<h3>Watch Your Operation Count</h3>
<p>Do be careful how you use macros, however. It&#8217;s easy to forget that a single macro might produce dozens of operations.  Remember: There is a limit of 256 operations per shader program! That&#8217;s a pretty tight space to work in, but with multiple shader programs chained together, we can do just about anything. You can keep a tab on your operations count by looking at the following properties in the EasyAGAL base class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Operations in the vertex program: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> vertexInstructions<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Operations in the shader program: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> fragmentInstructions<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>By the way, you can also access the generated opcode, with optional line numbering:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;VERTEX SHADER:&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>getVertexOpcode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;------------------&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;FRAGMENT SHADER&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>getFragmentOpcode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p><b><a href="https://github.com/Barliesque/EasyAGAL" title="Download EasyAGAL from GitHub" target="_blank">Download EasyAGAL from GitHub.</a></b></p>
]]></content:encoded>
			<wfw:commentRss>http://studio.barliesque.com/blog/2011/09/easyagal-macros-and-aliases/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Introducing EasyAGAL</title>
		<link>http://studio.barliesque.com/blog/2011/08/introducing-easyagal/</link>
		<comments>http://studio.barliesque.com/blog/2011/08/introducing-easyagal/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 19:56:28 +0000</pubDate>
		<dc:creator>barliesque</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Molehill]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[AGAL]]></category>
		<category><![CDATA[EasyAGAL]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Shaders]]></category>
		<category><![CDATA[Stage3D]]></category>

		<guid isPermaLink="false">http://studio.barliesque.com/blog/?p=162</guid>
		<description><![CDATA[I decided to write a small library that would assist in writing AGAL shaders, just as easily as writing ActionScript.  So, now I get:  Code completion and hinting, far more readable code, as well as some dynamic coding advantages...  <i>Download <b>EasyAGAL</b> from GitHub.</i>]]></description>
			<content:encoded><![CDATA[<p>Like most Flash developers out there, I&#8217;ve been getting excited about all the new possibilities Molehill is going to open up.  So I&#8217;ve begun refreshing my somewhat shaky knowledge of matrix mathematics, and learning the new AGAL language.  I could never understand why assembly code is always written in what looks more like shorthand than a fully expressed language, considering whatever the name of an operation is, it&#8217;ll be compiled down to a handful of bits understandable only to the CPU.  Mario Scabia is absolutely spot on likening it to the ancient hieroglyphics, in his <a href="http://iflash3d.com/shaders/my-name-is-agal-i-come-from-adobe-1/">introduction to AGAL</a>.</p>
<p>Learning how to work with matrices to achieve rendering effects is challenging enough without having to take on a new and strange programming language.  Given that there is no IDE especially for AGAL (at least for the time being!) I decided to write a small library that would assist me in writing AGAL programs, just as easily as writing ActionScript.  So, what does that mean?</p>
<ul>
<li>Code completion and hinting</li>
<li>Far more easily readable code</li>
<li>Dynamic coding advantages</li>
</ul>
<h3>Two Flavors:  Easy &#038; Easier</h3>
<p>Two base classes are provided for you to choose from:  <b>EasyAGAL.as</b> which uses the original AGAL opcodes for function names, and <b>EasierAGAL.as</b> which uses fully expressed function names.</p>
<p>Compare these corresponding samples:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">	<span style="color: #990000;">&quot;m44 vt1, va2, vc8 <span style="">\n</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span>
	<span style="color: #990000;">&quot;nrm vt1.xyz, vt1.xyz <span style="">\n</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span>
	<span style="color: #990000;">&quot;sub vt2, vc12, vt0 <span style="">\n</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span>
	<span style="color: #990000;">&quot;nrm vt2.xyz, vt2.xyz <span style="">\n</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span>
	<span style="color: #990000;">&quot;dp3 vt3, vt1, vt2 <span style="">\n</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span>
	<span style="color: #990000;">&quot;mov v2, vt3&quot;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">	<span style="color: #009900; font-style: italic;">// With EasyAGAL...</span>
&nbsp;
	m44<span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> ATTRIBUTE<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	nrm<span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>xyz<span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>xyz <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	sub<span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">12</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	nrm<span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>xyz<span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>xyz <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	dp3<span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	mov<span style="color: #000000;">&#40;</span> VARYING<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">	<span style="color: #009900; font-style: italic;">// or with EasierAGAL...</span>
&nbsp;
	multiply4x4<span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> ATTRIBUTE<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">normalize</span><span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>xyz<span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>xyz <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">subtract</span><span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">12</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">normalize</span><span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>xyz<span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>xyz <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	dotProduct3<span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	move<span style="color: #000000;">&#40;</span> VARYING<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>You&#8217;ll notice that the EasyAGAL code simplifies the use of registers a bit &#8212;  depending on whether you&#8217;re writing a vertex or a fragment shader, the appropriate register will automatically be used.  So, for example, you don&#8217;t need to worry about <em>vt1</em> versus <em>ft1</em>, only <em>TEMP[1]</em> which will be translated appropriately.  We can make the EasyAGAL code more readable still, by assigning registers to variables with descriptive names:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">	<span style="color: #6699cc; font-weight: bold;">var</span> normal<span style="color: #000066; font-weight: bold;">:</span>IRegister = ATTRIBUTE<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> normalMatrix<span style="color: #000066; font-weight: bold;">:</span>IRegister = CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> xformedNorm<span style="color: #000066; font-weight: bold;">:</span>IRegister = TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> intensity<span style="color: #000066; font-weight: bold;">:</span>IRegister = TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	multiply4x4<span style="color: #000000;">&#40;</span> xformedNorm<span style="color: #000066; font-weight: bold;">,</span> normal<span style="color: #000066; font-weight: bold;">,</span> normalMatrix <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">normalize</span><span style="color: #000000;">&#40;</span> xformedNorm<span style="color: #000066; font-weight: bold;">.</span>xyz<span style="color: #000066; font-weight: bold;">,</span> xformedNorm<span style="color: #000066; font-weight: bold;">.</span>xyz <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">subtract</span><span style="color: #000000;">&#40;</span> intensity<span style="color: #000066; font-weight: bold;">,</span> CONST<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">12</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">normalize</span><span style="color: #000000;">&#40;</span> intensity<span style="color: #000066; font-weight: bold;">.</span>xyz<span style="color: #000066; font-weight: bold;">,</span> intensity<span style="color: #000066; font-weight: bold;">.</span>xyz <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	dotProduct3<span style="color: #000000;">&#40;</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> intensity <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	move<span style="color: #000000;">&#40;</span> VARYING<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> TEMP<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<h3>Skeptical?</h3>
<p>Some may say &#8220;PixelBender3D does the same thing&#8230;&#8221; &#8230;which is actually quite inaccurate.  PixelBender3D is a high level language that is pre-compiled down to AGAL byte-code.  When writing AGAL from ActionScript (with or without the aid of this library) we have the oportunity to dynamically make some decisions about how the shader is written, e.g. whether to include vertex fogging, etc.  We can instantly rewrite the shader to include or exclude any number of options.  True, PixelBender3D was created as a friendlier alternative to AGAL, but at some cost to efficiency and outright hands-on control.</p>
<p>Others will say, &#8220;If you take the time to learn AGAL properly, you&#8217;ll be able to read it more easily and you won&#8217;t need any of this.&#8221;  I expect that for many the hurdle of making sense out of the hieroglyphics of AGAL when first meeting the language will prove too much of an obstacle to progress beyond basic tutorials.  This library provides training wheels to learning AGAL.  I have not reinvented the language, but merely made it much easier to read and write, leveraging the features of our IDE&#8217;s.  All methods of <em>EasyAGAL</em> and <em>EasierAGAL</em> maintain the same parameters, in the same order, as AGAL opcodes;  They are all documented with ASDoc tags providing help for every instruction and every register as you type.  The code-hints from EasierAGAL also include the original AGAL opcodes to help you learn them.</p>
<p><img src="http://studio.barliesque.com/images/easy-agal-code-hinting2.png" /></p>
<h3>Happy Trails</h3>
<p>AGAL is not easy, but hopefully this library will make it easier, and assist your learning experience.  Here are some excellent links to tutorials and introductions to AGAL and the Molehill API:</p>
<p><a href="http://iflash3d.com/shaders/my-name-is-agal-i-come-from-adobe-1/">My Name is AGAL, and I Come from Adobe</a> by Marco Scabia<br />
<a href="http://labs.jam3.ca/2011/03/molehill-getting-started/">Molehill &#8211; Getting Started</a> by Mikko Haapoja<br />
<a href="http://pgstudios.org/tutorials.php">Tutorials</a> by Pixelante</p>
<p>Once you&#8217;ve explored some of these tutorials and are ready to try your hand at coding some AGAL, please visit the repository for my new open source project <a href="https://github.com/Barliesque/EasyAGAL" title="Download EasyAGAL from GitHub" target="_blank">EasyAGAL now on GitHub.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://studio.barliesque.com/blog/2011/08/introducing-easyagal/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<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="swfid94ab5a46bc839c223aca37b01873594d"><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","swfid94ab5a46bc839c223aca37b01873594d","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><span style="color: #000066; font-weight: bold;">,</span> variable = <span style="color: #990000;">&quot;color&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">type</span> = <span style="color: #990000;">&quot;Color&quot;</span><span style="color: #000066; font-weight: bold;">,</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><span style="color: #000066; font-weight: bold;">,</span> variable = <span style="color: #990000;">&quot;radius&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">type</span> = <span style="color: #990000;">&quot;Number&quot;</span><span style="color: #000066; font-weight: bold;">,</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: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> h<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_width = w<span style="color: #000066; font-weight: bold;">;</span>
	_height = h<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_background<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	_background<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>_color<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	_background<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</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: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> _width<span style="color: #000066; font-weight: bold;">,</span> _height<span style="color: #000066; font-weight: bold;">,</span> _radius<span style="color: #000066; font-weight: bold;">,</span> _radius<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	_background<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> 
&nbsp;
	_tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>_width<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; x &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>_height<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	_tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000;">&#40;</span>_width <span style="color: #000066; font-weight: bold;">-</span> _tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">;</span>
	_tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000;">&#40;</span>_height <span style="color: #000066; font-weight: bold;">-</span> _tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">0.5</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</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: #000066; 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: #000066; font-weight: bold;">;</span> <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: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_radius = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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: #000066; 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: #000066; font-weight: bold;">;</span> <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: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_color = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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: #000066; 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: #000066; font-weight: bold;">;</span> <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: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_width = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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: #000066; 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: #000066; font-weight: bold;">;</span> <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: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	_height = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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: #000066; 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: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> const PARAMETER_RADIUS<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;fl.getDocumentDOM().selection[0].parameters[1].value&quot;</span><span style="color: #000066; font-weight: bold;">;</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: #000066; font-weight: bold;">.</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: #000066; font-weight: bold;">;</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: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000066; font-weight: bold;">.</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: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #990000;">&quot;#&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">color</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;#&quot;</span> <span style="color: #000066; 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: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">color</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CHANGE</span><span style="color: #000066; font-weight: bold;">,</span> setColorFromText<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	colorPicker<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>ColorPickerEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CHANGE</span><span style="color: #000066; font-weight: bold;">,</span> setColor<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	radius<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = MMExecute<span style="color: #000000;">&#40;</span>PARAMETER_RADIUS<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	radius<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CHANGE</span><span style="color: #000066; font-weight: bold;">,</span> setRadiusFromText<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	radiusSlider<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>SliderEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CHANGE</span><span style="color: #000066; font-weight: bold;">,</span> setRadius<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> setControls<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//......................</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: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	setColorFromText<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	setRadiusFromText<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> setControls<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;=&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">value</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// 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><span style="color: #000066; font-weight: bold;">;</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>50</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>1</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&#8242;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="swfidc8931a7d95f7d3161d7fc56dd74eca70"><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","swfidc8931a7d95f7d3161d7fc56dd74eca70","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: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000000;">&#41;</span><span style="color: #000066; 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: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">.</span><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><span style="color: #000066; font-weight: bold;">;</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<span style="color: #000066; font-weight: bold;">,</span> obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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: #000066; font-weight: bold;">.</span><span style="color: #004993;">getBounds</span><span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Is the DisplayObject masked?</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mask</span> <span style="color: #000066; 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: #000066; font-weight: bold;">.</span><span style="color: #004993;">intersection</span><span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mask</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getBounds</span><span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parent</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Is the DisplayObject partly or completely off-stage?</span>
	vis = vis<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">intersection</span><span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getBounds</span><span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parent</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">return</span> vis<span style="color: #000066; font-weight: bold;">;</span>
<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: #000066; font-weight: bold;">:*,</span> <span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000000;">&#41;</span><span style="color: #000066; 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: #000066; 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: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">child</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> childRect<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</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><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span>= obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">numChildren</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">child</span> = obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&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: #000066; 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: #000066; font-weight: bold;">.</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: #000066; font-weight: bold;">,</span> <span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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: #000066; font-weight: bold;">.</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: #000066; font-weight: bold;">;</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: #000066; font-weight: bold;">.</span><span style="color: #004993;">mask</span> <span style="color: #000066; 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: #000066; font-weight: bold;">.</span><span style="color: #004993;">intersection</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mask</span><span style="color: #000066; font-weight: bold;">.</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: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
				vis = vis<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">union</span><span style="color: #000000;">&#40;</span>childRect<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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: #000066; font-weight: bold;">;</span>
<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 about my &#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>

