<?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>rabidGadfly &#187; intermediate</title>
	<atom:link href="http://rabidgadfly.com/category/intermediate/feed/" rel="self" type="application/rss+xml" />
	<link>http://rabidgadfly.com</link>
	<description>Simple Solutions to Nagging Coding Problems</description>
	<lastBuildDate>Wed, 19 Oct 2011 13:43:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Making Alpha Work on AS3 Dynamic Text Fields</title>
		<link>http://rabidgadfly.com/2008/10/making-alpha-work-on-as3-dynamic-text-fields/</link>
		<comments>http://rabidgadfly.com/2008/10/making-alpha-work-on-as3-dynamic-text-fields/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 13:29:28 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[intermediate]]></category>
		<category><![CDATA[alpha]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[blendmode]]></category>
		<category><![CDATA[dynamic text]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=85</guid>
		<description><![CDATA[Getting the alpha property to work with coded TextFields is another AS3 technique that you would expect to be a little easier, or at least more intuitive, than it is. Initially, you may expect something like this to render the text invisible: var myTextField:TextField = new TextField(); myTextField.text = "Doesn't Work"; addChild(myTextField); myTextField.alpha = .5; [...]]]></description>
			<content:encoded><![CDATA[<p>Getting the alpha property to work with coded TextFields is another AS3 technique that you would expect to be a little easier, or at least more intuitive, than it is. Initially, you may expect something like this to render the text invisible:</p>
<pre><code>
var myTextField:TextField = new TextField();
myTextField.text = "Doesn't Work";
addChild(myTextField);
myTextField.alpha = .5;
</code></pre>
<p>But regardless of the alpha property, the code above will be visible. The reason is that I haven&#8217;t specified a font. This means that it will be rendered by the operating system and Flash Player will have no control over it.</p>
<p>With this new knowledge you may figure that setting the font will solve the problem, so you write something like this:</p>
<pre><code>
var myTextField:TextField = new TextField();
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextField.text = "Still doesn't work";
myTextField.setTextFormat(myTextFormat);
addChild(myTextField);
myTextField.alpha = .5;
</code></pre>
<p>But it still doesn&#8217;t work. Why? Well, I really have no idea!</p>
<p>Luckily, I ran across a comment left on <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html">Adobe Livedocs</a> by Haiducii7 who suggested that by changing the blendMode to something other than NORMAL, alpha will work. The code now, looks something like this:</p>
<pre><code>
var myTextField:TextField = new TextField();
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextField.blendMode = BlendMode.LAYER;
myTextField.text = "It works!";
myTextField.setTextFormat(myTextFormat);
addChild(myTextField);
myTextField.alpha = .5;
</code></pre>
<p>And it worked! According to Flash Help, BlendMode.LAYER &#8220;forces the creation of a transparency group for the display object.&#8221; I guess that makes sense, but there&#8217;s nothing in the documentation that outlines all of the steps needed to make this happen.</p>
<p>Not even <a href="http://oreilly.com/catalog/9780596526948/">Colin Moock&#8217;s Essential ActionScript 3.0</a>, a book I&#8217;ve treasured in multiple versions, mentions the necessity of BlendMode.</p>
<p>Definitely a tip worth earmarking.</p>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2008/10/making-alpha-work-on-as3-dynamic-text-fields/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
		<item>
		<title>Easy Movie Clip Buttons Part 3 of 3: Defining Button States</title>
		<link>http://rabidgadfly.com/2007/02/easy-movie-clip-buttons-part-3-of-3-defining-button-states/</link>
		<comments>http://rabidgadfly.com/2007/02/easy-movie-clip-buttons-part-3-of-3-defining-button-states/#comments</comments>
		<pubDate>Mon, 12 Feb 2007 15:27:19 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[intermediate]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=23</guid>
		<description><![CDATA[In Part 1 I demonstrated how to dynamically populate existing movie clip buttons. in Part 2 I showed you how to dynamically place the button on screen. In the third and final installment, I&#8217;ll show you how to code your clips to behave like buttons. Using movie clips rather than buttons gives me the ability [...]]]></description>
			<content:encoded><![CDATA[<p>In <a title="Part 1" href="http://www.rabidgadfly.com/?p=3">Part 1</a> I demonstrated how to dynamically populate existing movie clip buttons. in <a title="Part 2" href="http://www.rabidgadfly.com/?p=4">Part 2</a> I showed you how to dynamically place the button on screen. In the third and final installment, I&#8217;ll show you how to code your clips to behave like buttons. Using movie clips rather than buttons gives me the ability to code as many states as I want. My buttons will have four states: Active, Over, Down, and Selected. <a title="buttonMCs_Part3.zip" href="http://www.rabidgadfly.com/fla/buttonMCs_Part3.zip">Download the sample</a> to get started. Here&#8217;s what we&#8217;ll be creating:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_buttonMCs_Part3_433330988"
			class="flashmovie"
			width="350"
			height="100">
	<param name="movie" value="http://www.rabidgadfly.com/fla/buttonMCs_Part3.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.rabidgadfly.com/fla/buttonMCs_Part3.swf"
			name="fm_buttonMCs_Part3_433330988"
			width="350"
			height="100">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><span id="more-23"></span> Let&#8217;s start by double-clicking the button in the library to bring it up in enter mode. There four sections defined, each representing a state. This could have been done in four frames but I wanted the labels to be visible. You&#8217;ll notice that my &#8216;button text&#8217; layer extends across all states. This is because the button text will remain the same. If I added a keyframe in each state for the button text, I would have to redefine it every time the state changed.</p>
<p>I placed no ActionScript inside the movie clip button, opting instead to place all of my code in the main timeline. The only code I needed to add when placing the button on the stage was the stop(); on line 14 which places each button as &#8216;active&#8217;:</p>
<blockquote><p><strong> this[container_mc].button_mc.stop();</strong></p></blockquote>
<p>Active is the default state of my button. The Over section will appear when the user moves the mouse over the button. Down is for when the user has pressed the mouse button but hasn&#8217;t yet released it. Selected is show the user which option is current. Obviously, in this specific example, the value in the fullMonth_txt text field will give that information away but most of the time it won&#8217;t be so obvious.</p>
<p>Labeling the frames that start each state section not only makes it easy to find the object states at a glance when viewing the movie clip, but also makes it easy to see what the code is doing. Now that I have a different look for each state, I&#8217;ll code the functions for each section.</p>
<p>First I start by defining a variable named selectedButton. Because I don&#8217;t want the selected button to change to any other state unless another button is clicked, I need a variable to keep track of which one is selected.</p>
<blockquote><p><strong> var selectedButton:MovieClip;</strong></p></blockquote>
<p>Now the only thing I have left to do is code the buttons, which takes very little code. First, a slight modification to the onRelease definition:</p>
<blockquote><p><strong>this[container_mc].button_mc.onRelease = function() {<br />
fullMonth_txt.text = this.monthName;<br />
if(selectedButton &#038;&#038; selectedButton != this) {<br />
selectedButton.gotoAndStop(&#8220;active&#8221;);<br />
};<br />
selectedButton = this;<br />
this.gotoAndStop(&#8220;selected&#8221;);<br />
};</strong></p></blockquote>
<p>Because I start without a selected button, selectedButton starts with a value of undefined. The first thing I added to each state function then is a check to see whether it&#8217;s been defined. If so, I then need to make sure that I don&#8217;t change the state if of the currently-selected button.</p>
<p>So, in the case of onRelease, providing that the button the user clicks is not the currently selected button, the function will first change the state of the currently-selected button back to active (unselected), then it redefines the selectedButton variable to reflect the new selection, and finally it changes the newly selected button to the â€˜selecteds frame.</p>
<p>If that seems pretty easy, you&#8217;ll be happy to know that the rest of the state functions are even easier because we don&#8217;t even have to worry about a variable to change or whether a button has been selected yet. We simply have to change the movie clip button&#8217;s frame to reflect the new state. Here are the rest of the functions:</p>
<blockquote><p><strong>this[container_mc].button_mc.onRollOver = this[container_mc].button_mc.onDragOver = function() {<br />
if (selectedButton != this) {<br />
this.gotoAndStop(&#8220;over&#8221;);<br />
};<br />
};</strong></p>
<p><strong>this[container_mc].button_mc.onRollOut = this[container_mc].button_mc.onDragOut = function() {<br />
if (selectedButton != this) {<br />
this.gotoAndStop(&#8220;active&#8221;);<br />
};<br />
};</strong></p>
<p><strong>this[container_mc].button_mc.onPress = function(){<br />
if (selectedButton != this) {<br />
this.gotoAndStop(&#8220;down&#8221;);<br />
};<br />
};</strong></p></blockquote>
<p>The one piece of code here that you may find mildy tricky is the dual-definitions for rollOver/dragOver and rollOut/dragOut. Basically, I&#8217;m just using ActionScript to define the same functions for multiple events. It&#8217;s the same as writing a = b = c to make a and b equal to the value of c. The only difference in the last three functions is the frame the movie clip moves to. Other than that, they&#8217;re identical.</p>
<p>And that&#8217;s all there is to it. You now know how to dynamically place and code multiple movie clip buttons with multiple states in only 50 lines of code.</p>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2007/02/easy-movie-clip-buttons-part-3-of-3-defining-button-states/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Easy Movie Clip Buttons Part 2 of 3: Dynamic Button Placement</title>
		<link>http://rabidgadfly.com/2007/02/easy-movie-clip-buttons-part-2-of-3-dynamic-button-placement/</link>
		<comments>http://rabidgadfly.com/2007/02/easy-movie-clip-buttons-part-2-of-3-dynamic-button-placement/#comments</comments>
		<pubDate>Mon, 05 Feb 2007 14:29:16 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[intermediate]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=4</guid>
		<description><![CDATA[Start by downloading and opening the sample file. The first difference you&#8217;ll notice from Part 1 is that there are no longer buttons on the stage. Part 1 demonstrated how to dynamically populate existing movie clip buttons. In this part, we&#8217;ll take it a step further by dynamically placing the buttons. Here&#8217;s our finished product: [...]]]></description>
			<content:encoded><![CDATA[<p>Start by downloading and opening the <a title="buttonMCs_Part2.zip" href="http://www.rabidgadfly.com/fla/buttonMCs_Part2.zip">sample file</a>. The first difference you&#8217;ll notice from <a title="Easy Movie Clip Buttons Part 1 of 3" href="http://www.rabidgadfly.com/?p=3">Part 1</a> is that there are no longer buttons on the stage. Part 1 demonstrated how to dynamically populate existing movie clip buttons. In this part, we&#8217;ll take it a step further by dynamically placing the buttons. Here&#8217;s our finished product:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_buttonMCs_Part2_1849047741"
			class="flashmovie"
			width="350"
			height="100">
	<param name="movie" value="http://www.rabidgadfly.com/swf/buttonMCs_Part2.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.rabidgadfly.com/swf/buttonMCs_Part2.swf"
			name="fm_buttonMCs_Part2_1849047741"
			width="350"
			height="100">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>As in part 1, I start off by defining my array:var month_array:Array = new Array ({month:&#8221;JAN&#8221;,fullNm:&#8221;January&#8221;},<br />
{month:&#8221;FEB&#8221;,fullNm:&#8221;February&#8221;},{month:&#8221;MAR&#8221;,fullNm:&#8221;March&#8221;},<br />
{month:&#8221;APR&#8221;,fullNm:&#8221;April&#8221;},{month:&#8221;MAY&#8221;,fullNm:&#8221;May&#8221;},<br />
{month:&#8221;JUN&#8221;,fullNm:&#8221;June&#8221;},{month:&#8221;JUL&#8221;,fullNm:&#8221;July&#8221;},<br />
{month:&#8221;AUG&#8221;,fullNm:&#8221;August&#8221;},{month:&#8221;SEP&#8221;,fullNm:&#8221;September&#8221;},<br />
{month:&#8221;OCT&#8221;,fullNm:&#8221;October&#8221;},{month:&#8221;NOV&#8221;,fullNm:&#8221;November&#8221;},<br />
{month:&#8221;DEC&#8221;,fullNm:&#8221;December&#8221;});</p>
<p>As you can see, I like defining my ActionScript arrays as arrays of objects. This allows me to treat the array as a recordset with named columns. I find it much easier to refer to a value by name rather than its index value.</p>
<p><span id="more-463"></span><br />
The next four lines define new variables that will be used to position the buttons on the screen:</p>
<p>var initX:Number=5;<br />
var nextX:Number = initX;<br />
var nextY:Number = 5;<br />
var wrapY:Number = 6;</p>
<p>initX defines the starting X coordinate of each row. nextX and nextY define the x/y coordinates of the first button. nextX will change with each loop to define the x coordinate of the subsequent button. wrapY defines the number of buttons that will be placed across before wrapping to a new line.</p>
<p>Next, I start looping through my array by creating an empty movie clip that will be used to hold my movie clip button. Each container is named dynamically using the container_mc variable. I chose to name the containers by concatenating &#8216;cont&#8217; with my loop variable so I end up with 12 containers named cont1-cont12.</p>
<p>var container_mc:String = &#8220;&#8221;;<br />
for (var a:Number = 0; a < month_array.length; a++) {<br />
container_mc = "cont" + a;<br />
this.createEmptyMovieClip(container_mc,this.getNextHighestDepth());</p>
<p>Before I can proceed to populate the container with the button mc, I need a way to reference it in the library. The object name is not used for this purpose. Instead, we have to define a linkage identifier. If you haven't done this before it may sound complicated but it's simply giving the clip a label we can refer to it by from our ActionScript.</p>
<p>To provide your button movie clip with an identifier, right-click the button_mc object in the library and click Properties. If the advanced properties are not yet open, click the Advanced button. In the Identifier field, type button_mc. I chose to make the identifier the same as the object name but that's not a necessity. I could have made the identifier 'mcButton' or 'buttonClip' or 'bushIsAhabAndIraqHisWhiteWhale' or any other ActionScript-legal name.</p>
<p>Your Symbol Properties popup should now look like this:</p>
<p>button_mc advanced object properties</p>
<p>Now I can use attachMovie to load button_mc dynamically from my library into its container. You'll notice that I also name the instance button_mc. It won't be a problem naming all 12 buttons the same thing because they are each contained in their own uniquely-named container:</p>
<p>this[container_mc].attachMovie("button_mc","button_mc",this.getNextHighestDepth, {_x:nextX,_y:nextY});</p>
<p>I then populate the the dynamic text field inside my button clip (month_txt) with the month abbreviation ('month' in my array) and assign the full month name as a button property named monthName:<br />
this[container_mc].button_mc.month_txt.text = month_array[a].month;<br />
this[container_mc].button_mc.monthName = month_array[a].fullNm;</p>
<p>The monthName property is utilized in the onRelease function that is assigned to each button. When the mouse button is released, the dynamic text field named fullMonth_txt will be populated with the value of monthName:</p>
<p>this[container_mc].button_mc.onRelease = function() {<br />
fullMonth_txt.text = this.monthName;<br />
};</p>
<p>I finish up by using my four positioning variables to either define the next button placement position as 57 pixels to the right of the leftmost position of the current button, or to wrap to the next line if I've already placed the number of buttons specified in the wrapY variable.</p>
<p>if (a == (wrapY-1)) {<br />
wrapY += 6;<br />
nextX = initX;<br />
nextY += 28;<br />
} else {<br />
nextX += 57;<br />
};</p>
<p>};</p>
<p>That's it! Using 25 lines of code and 1 library object I created and coded functionality into 12 labeled buttons. Basic stuff? Sure! But this is the basis of creating your own dynamically populated applications using a data source. In this example, I used an array for ease of demonstration but it could have just as easily been a recordset returned by a remoting call, or an XML data source.</p>
<p>In the third and last part of this tutorial I will be demonstrating how to add button states to your movie clip. I hope to have that posted by next week.</p>
<p>-rG</p>
<p>Also available: <a title="Part 1" href="http://www.rabidgadfly.com/?p=3">Part 1, <a title="Part 3" href="http://www.rabidgadfly.com/?p=23">Part 3Â </a></p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2007/02/easy-movie-clip-buttons-part-2-of-3-dynamic-button-placement/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Pass Dynamic URL Variables to a SWF using ColdFusion</title>
		<link>http://rabidgadfly.com/2006/11/how-to-pass-dynamic-url-variables-to-a-swf-using-coldfusion/</link>
		<comments>http://rabidgadfly.com/2006/11/how-to-pass-dynamic-url-variables-to-a-swf-using-coldfusion/#comments</comments>
		<pubDate>Thu, 09 Nov 2006 17:04:01 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[intermediate]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=12</guid>
		<description><![CDATA[Whew, It&#8217;s been a LONG time since I posted anything! Lucky I don&#8217;t have a big following. I recently found myself in a situation where I needed a way to pass certain URL variables to a SWF within a ColdFusion page. This may sound easy on the surface but the catch is that the page [...]]]></description>
			<content:encoded><![CDATA[<p>Whew, It&#8217;s been a LONG time since I posted anything! Lucky I don&#8217;t have a big following.</p>
<p>I recently found myself in a situation where I needed a way to pass certain URL variables to a SWF within a ColdFusion page. This may sound easy on the surface but the catch is that the page is dynamic. It never knows which SWF it&#8217;s going to call and each SWF can take different URL variables. I ended up with a pretty clean solution that didn&#8217;t take many lines of code. Note that I use <a href="http://blog.deconcept.com/swfobject/">SWFObject</a> to place my Flash objects (and so should you) and this solution is specific to that method.</p>
<p>I send one URL variable called customvars that contains all of the variable names and values I want to send to the SWF. Variable names and values are separated by commas and each name/value &#8216;set&#8217; is separated by a semi-colon. It ends up looking like this:</p>
<p>customvars=user_id,123456;eyecolor,blue;car,accord</p>
<p>Then, in my CF page I put the following code which converts the customvars string into a CF structure:</p>
<p>&lt;cfset flashVars = structNew() /&gt;<br />
&lt;cfparam name=&#8221;url.customvars&#8221; default=&#8221;"&gt;<br />
&lt;cfif len(url.customvars)&gt;<br />
	&lt;cfloop list=&#8221;#url.customvars#&#8221; delimiters=&#8221;;&#8221; index=&#8221;customFlashVar&#8221;&gt;<br />
		&lt;cfset thisRecordName = listFirst(customFlashVar,&#8221;,&#8221;)&gt;<br />
		&lt;cfset thisRecordValue = listLast(customFlashVar,&#8221;,&#8221;)&gt;<br />
		&lt;cfset flashVars[thisRecordName] = thisRecordValue&gt;<br />
	&lt;/cfloop&gt;<br />
&lt;/cfif&gt;</p>
<p>Then, in my swfObject code, I loop through the structure assigning the name and variable to swfObject&#8217;s addVariables like this:</p>
<p>&lt;cfloop collection=&#8221;#flashVars#&#8221; item=&#8221;key&#8221;&gt;<br />
	fo.addVariable(&#8220;#key#&#8221;,&#8221;#attributes.parms[key]#&#8221;);<br />
&lt;/cfloop&gt;</p>
<p>Works like a charm.</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2006/11/how-to-pass-dynamic-url-variables-to-a-swf-using-coldfusion/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

