<?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; as3</title>
	<atom:link href="http://rabidgadfly.com/category/as3/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>Flex Optimization Tip: Evaluate Your Setter Parameter</title>
		<link>http://rabidgadfly.com/2011/03/flex-optimization-tip-evaluate-your-setter-parameter/</link>
		<comments>http://rabidgadfly.com/2011/03/flex-optimization-tip-evaluate-your-setter-parameter/#comments</comments>
		<pubDate>Thu, 10 Mar 2011 18:37:39 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[flash builder]]></category>
		<category><![CDATA[getter]]></category>
		<category><![CDATA[setter]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=529</guid>
		<description><![CDATA[Flash Builder makes it easy to generate getters and setters from a variable definition. Just select the variable, right-click and choose Source > Generate getters/setters. The generated code is simple; the getter returns the value and the setter sets the value: Oftentimes in Flex, however, changing a variable is a trigger that causes other code [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://rabidgadfly.com/2011/03/flex-optimization-tip-evaluate-your-setter-parameter/fb5/" rel="attachment wp-att-534"><img src="http://rabidgadfly.com/wp-content/uploads/2011/03/fb5.png" alt="" title="fb5" width="150" height="150" class="alignright size-full wp-image-534" /></a>Flash Builder makes it easy to generate getters and setters from a variable definition. Just select the variable, right-click and choose Source > Generate getters/setters.</p>
<p>The generated code is simple; the getter returns the value and the setter sets the value:</p>
<pre class="brush: as3; title: ; notranslate">
private var _myData:String;

public function get myData():String {
    return _myData;
}

public function set myData(value:String):void {
   _myData = value;
}
</pre>
<p>Oftentimes in Flex, however, changing a variable is a trigger that causes other code to run or update. But  why would you want this extra processing to occur if the value that is being assigned hasn&#8217;t changed?<br />
<span id="more-529"></span><br />
Instead, add a quick comparison:</p>
<pre class="brush: as3; title: ; notranslate">
public function set myData(value:String):void {
    if(_myData != value) {
       _myData = value;
    }
}
</pre>
<p>Note that you would use ObjectUtil.compare rather than equality to compare complex Objects: </p>
<pre class="brush: as3; title: ; notranslate">
public function set myObjectData(value:Object):void {
    if(ObjectUtil.compare(_myObjectData,value) != 0 ) {
       _myObjectData = value;
    }
}
</pre>
<p>Obviously, depending on the complexity and size of the objects, and the amount of work to be done after an update, comparing Objects may not make sense in all circumstances. That&#8217;s a judgement call you can make based on your particular code.</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2011/03/flex-optimization-tip-evaluate-your-setter-parameter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unusual Flex Problem? Check Your Metadata!</title>
		<link>http://rabidgadfly.com/2011/02/unusual-flex-problem-check-your-metadata/</link>
		<comments>http://rabidgadfly.com/2011/02/unusual-flex-problem-check-your-metadata/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 18:46:31 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash builder]]></category>
		<category><![CDATA[metadata]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=469</guid>
		<description><![CDATA[I&#8217;ve been working with Flash Builder 4 every day for about six months now, and I love it. Overall, Flash Builder is a great programming environment offering helpful debugging tools, plenty of useful keyboard shortcuts, code-hinting and completion, and error feedback on compilation issues. The compilation errors can be SO helpful that you rely on [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="attachment wp-att-476" href="http://rabidgadfly.com/2011/02/unusual-flex-problem-check-your-metadata/angry_2x2/"><img class="alignright size-full wp-image-476" title="Stressed" src="http://rabidgadfly.com/wp-content/uploads/2011/02/angry_2x2.jpg" alt="" width="200" height="200" /></a>I&#8217;ve been working with Flash Builder 4 every day for about six months now, and I love it. Overall, Flash Builder is a great programming environment offering helpful debugging tools, plenty of useful keyboard shortcuts, code-hinting and completion, and error feedback on compilation issues.</p>
<p>The compilation errors can be SO helpful that you rely on them as guides. When refactoring code the errors tell you where you need to go to fix affected code. And if you use metadata correctly, the errors can tell you when you&#8217;ve forgotten to include a required component.</p>
<p>As helpful as the metadata, code-hinting and error-checking is, it&#8217;s not quite perfect; and it&#8217;s these little imperfections that can set you off on an afternoon-long detour. Reason being, while metadata can help enforce rules and enhance code-hinting, and while error-checking can point out problems with your code, metadata itself is not error-checked.</p>
<p>Enter my problem&#8230;</p>
<p><span id="more-469"></span>I added a skin state and skin parts to an existing component and couldn&#8217;t for the life of me figure out why the component class would not update the content of the text fields I had placed in the skin. I&#8217;d done this several times before but this time it just wouldn&#8217;t work.</p>
<p>I made sure I had defined the skin parts in my component, I traced and debugged for several hours, I googled  and traversed several blogs, I read through the Adobe online help reading in-depth descriptions of getCurrentSkinState, invalidateSkinState, and attachSkin.</p>
<p>Finally, it dawned on me. I scrolled once again up to the section of my component where I defined the skin parts and looked closely at the meta data definition. Sure enough, there was the problem.  I had type &#8220;Skinpart&#8221; instead of &#8220;SkinPart&#8221;. I forgot to capitalize the P. No warnings, no errors; just a bunch of text fields in the skin and variables in the component that were acting appropriately on their own, but were not connected in any way.</p>
<p>It took about a half hour to remove all of the ridiculous code I had added to try to compensate for that lowercase p. In the end, I walk away with a better knowledge of Flex skins, and hopefully an ability to recognize that issue sooner in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2011/02/unusual-flex-problem-check-your-metadata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Style Items in a Flex 4 Spark List</title>
		<link>http://rabidgadfly.com/2010/09/styling-items-in-flex-4-list/</link>
		<comments>http://rabidgadfly.com/2010/09/styling-items-in-flex-4-list/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 16:38:25 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[flex 4]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[spark]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=374</guid>
		<description><![CDATA[I&#8217;ve often heard it said that while Flex has a knack for making difficult tasks easy, it also has the same knack for making seemingly easy tasks difficult. While I agree that on occasion it seems that way up front, I usually find that the solution isn&#8217;t usually difficult, just difficult to find. That was [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve often heard it said that while Flex has a knack for making difficult tasks easy, it also has the same knack for making seemingly easy tasks difficult. While I agree that on occasion it seems that way up front, I usually find that the solution isn&#8217;t usually difficult, just difficult to find.</p>
<p>That was the case I found when recently working with the Spark List Component. Dynamically assigning an ArrayList as a Spark List&#8217;s data provider was a quick task and everything worked as expected. I was thrilled. Now I just had to tweak the spacing between the list items and I&#8217;d be finished. Easy, right? Ultimately the answer is yes. However, arriving at the solution took me a couple of hours!</p>
<p>The Spark List component automatically adds cool rollover and select effects. It also allows you to change rollover colors, set the width, and adjust the font size with simple attributes. What it <em>doesn&#8217;t</em> let you do so easily is set the spacing between list items. <em>( Note that I&#8217;m referring to a dynamically populated List, not one in which you define each item individually where you have the luxury of modifying the attributes of each item )</em>.</p>
<p>Here&#8217;s some code to demonstrate the situation:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
	xmlns:mx=&quot;library://ns.adobe.com/flex/mx&quot;
	preinitialize=&quot;preinitHandler(event)&quot;  &gt;
	&lt;fx:Script&gt;
		&lt;![CDATA[
		import mx.collections.ArrayList;
		import mx.events.FlexEvent;

		[Bindable]
		private var monthsList:ArrayList;

		protected function preinitHandler(event:FlexEvent):void {
			monthsList = new ArrayList([&quot;January&quot;, &quot;February&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;, &quot;June&quot;, &quot;July&quot;, &quot;August&quot;, &quot;September&quot;, &quot;October&quot;, &quot;November&quot;,&quot;December&quot;]);
		}
		]]&gt;
	&lt;/fx:Script&gt;

	&lt;s:List id=&quot;months&quot; dataProvider=&quot;{monthsList}&quot; /&gt;
&lt;/s:Application&gt;
</pre>
<p>The code above populates a Spark List with months. Very quick and easy! But now I want to close up the space between the months. Simple padding or gap attribute on the list, right? Nope. lineheight? No. Custom VerticalLayout? Uh uh. Google? Majority of results show examples where each item is defined manually&#8230;that doesn&#8217;t help either.</p>
<p>The answer it turns out is to define a custom ItemRenderer. This is used to tell the results how they should render when displayed. Common sense, right? And it&#8217;s pretty easy to do too:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;s:List id=&quot;months&quot; dataProvider=&quot;{monthsList}&quot; &gt;
	&lt;s:itemRenderer&gt;
		&lt;fx:Component&gt;
			&lt;s:ItemRenderer&gt;
				&lt;s:Label text=&quot;{data}&quot; paddingTop=&quot;3&quot; paddingBottom=&quot;3&quot; fontSize=&quot;11&quot; /&gt;
			&lt;/s:ItemRenderer&gt;
		&lt;/fx:Component&gt;
	&lt;/s:itemRenderer&gt;
&lt;/s:List&gt;
</pre>
<p>You can style the output any way you like by styling the label in the ItemRenderer. Note that if your data source contains multiple &#8220;fields&#8221; with property names, you&#8217;ll need to tweak the label text value slightly to reflect the property name of the value you&#8217;ll be displaying. So, instead of {data}, you would use something like {data.propertyName}.</p>
<p><strong>Bonus tip:</strong> For reusability and flexibility you can define the the ItemRenderer as a separate MXML file and assign it to the itemRenderer property of the Spark List. Even better, you can add the Label style to a style sheet and use it throughout your application.</p>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2010/09/styling-items-in-flex-4-list/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Font Embedding with Flex 4</title>
		<link>http://rabidgadfly.com/2010/04/font-embedding-with-flash-builder-4/</link>
		<comments>http://rabidgadfly.com/2010/04/font-embedding-with-flash-builder-4/#comments</comments>
		<pubDate>Sat, 01 May 2010 00:41:56 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[embed font]]></category>
		<category><![CDATA[flash builder]]></category>
		<category><![CDATA[font]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=321</guid>
		<description><![CDATA[I&#8217;ve been noodling around a bit with Flash Builder 4 lately. After creating a few simple apps I decided to look into font embedding. There are quite a few posts to be found via Googling about embedding fonts in Flex. Some are very good, others not so much, but I think I managed to compile [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been noodling around a bit with Flash Builder 4 lately. After creating a few simple apps I decided to look into font embedding. There are quite a few posts to be found via Googling about embedding fonts in Flex. Some are very good, others not so much, but I think I managed to compile the info into a useful example. My goal was to create custom font swfs, load them into flex, and then apply them to a text field through the use of some type of selector.</p>
<h4>1. Create the Font SWF</h4>
<p><a href="http://www.rabidgadfly.com/wp-content/uploads/charembed.jpg"><img style="border:1px solid #ccc;margin:0 10px 5px 10px;"  src="http://www.rabidgadfly.com/wp-content/uploads/charembed.jpg" alt="Embed Characters" title="Embed Characters" width="350" height="303" class="alignright size-full wp-image-324" /></a>The first step is to use Flash to create a font swf. To do so, create a new Flash document and add a dynamic text field to the stage. Select the text field and choose the font you want to use in your Flex application. Next, click the Character Embedding button from the Property panel and choose the characters that you want available to your Flex application. Choose only the characters you need as each extra character will add unnecessary size. Finally, publish the swf and place a copy in your Flex application folder.</p>
<p>Make a font swf for each font you want to use in your Flex application then close Flash.</p>
<h4>2. Embed the Font SWF</h4>
<p>The next step is to pull those font swfs into your Flex application and create classes, or styleNames, for them. This is done inside the fx:Style tag (mx:Style in Flex 3)</p>
<pre class="brush: xml; title: ; notranslate">
&lt;fx:Style &gt;
		@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;
		@namespace mx &quot;library://ns.adobe.com/flex/mx&quot;;

		@font-face	{
			src: url(&quot;fonts/calvin.swf&quot;);
			font-family: &quot;Calvin and Hobbes&quot;;
		}
		@font-face {
			src:url(&quot;fonts/lcd.swf&quot;);
			font-family:&quot;LCD&quot;;
		}
		@font-face {
			src:url(&quot;fonts/ransom.swf&quot;);
			font-family:&quot;RansomNote&quot;;
		}

		.calvin {font-family: &quot;Calvin and Hobbes&quot;;}
		.lcd {font-family: &quot;LCD&quot;;}
		.ransom {font-family: &quot;RansomNote&quot;;}

	&lt;/fx:Style&gt;
</pre>
<p>Note that the font-family is the name of the font as listed in the Flash IDE. Once this is done I can assign the styleNames &#8220;smack&#8221;, &#8220;square&#8221;, and &#8220;curlz&#8221; to an mx:Text field and it will be presented in that font, something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;mx:Text id=&quot;myText&quot; text=&quot;This is my text&quot; styleName=&quot;calvin&quot;  /&gt;
</pre>
<p>If you stop here you will have a text field using your embedded font.</p>
<h4>3. Create a Font Selector</h4>
<p>We can take this an additional step by adding a radio button group and a simple function to allow dynamic switching between fonts:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;fx:Declarations&gt;
	&lt;s:RadioButtonGroup id=&quot;radiogroup1&quot;/&gt;
&lt;/fx:Declarations&gt;
&lt;mx:Text id=&quot;myText&quot; x=&quot;159&quot; y=&quot;28&quot; text=&quot;Select another font&quot; styleName=&quot;calvin&quot;   fontSize=&quot;20&quot;/&gt;
&lt;s:RadioButton id=&quot;calvin&quot; x=&quot;10&quot; y=&quot;10&quot; label=&quot;Calvin&quot; groupName=&quot;radiogroup1&quot; click=&quot;handleChangeFont(event)&quot; selected=&quot;true&quot;/&gt;
&lt;s:RadioButton id=&quot;lcd&quot; x=&quot;10&quot; y=&quot;36&quot; label=&quot;LCD&quot; groupName=&quot;radiogroup1&quot; click=&quot;handleChangeFont(event)&quot;/&gt;
&lt;s:RadioButton id=&quot;ransom&quot; y=&quot;62&quot; label=&quot;Ransom Note&quot; groupName=&quot;radiogroup1&quot; click=&quot;handleChangeFont(event)&quot; x=&quot;10&quot;/&gt;
</pre>
<p>Note that, as an id for each radiobutton I used the class name they will invoke. This will allow me to use only one line of code in one function to assign the appropriate styleName to my text field:</p>
<pre class="brush: as3; title: ; notranslate">
&lt;fx:Script&gt;
	&lt;![CDATA[

		protected function handleChangeFont(evt:Event):void {
		myText.styleName = evt.target.id;
	        }

	]]&gt;
&lt;/fx:Script&gt;
</pre>
<p>The finished product looks something like this:</p>
<div align="center" style="margin:15px auto;">

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_FontEmbedding_1894176975"
			class="flashmovie"
			width="500"
			height="100">
	<param name="movie" value="http://www.rabidgadfly.com/swf/fontembedding/FontEmbedding.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.rabidgadfly.com/swf/fontembedding/FontEmbedding.swf"
			name="fm_FontEmbedding_1894176975"
			width="500"
			height="100">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
</div>
<p style="margin:5px 5px 20px 5px;">Right-click on the swf and then click &#8220;View Source&#8221; to view or download the source.</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2010/04/font-embedding-with-flash-builder-4/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Simple XML-Driven Flash AS3 Slider</title>
		<link>http://rabidgadfly.com/2010/04/simple-xml-driven-flash-as3-slider/</link>
		<comments>http://rabidgadfly.com/2010/04/simple-xml-driven-flash-as3-slider/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 13:20:47 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[slide]]></category>
		<category><![CDATA[slider]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=250</guid>
		<description><![CDATA[
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm__1779425423"
			class="flashmovie"
			width="300"
			height="250">
	<param name="movie" value="http://www.rabidgadfly.com/swf/slider.swf?contentfolder=/swf/slidercontent/" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.rabidgadfly.com/swf/slider.swf?contentfolder=/swf/slidercontent/"
			name="fm__1779425423"
			width="300"
			height="250">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object> Download the source here When I was creating my coding portfolio I wanted a slider app that would display a series of screenshots from some of my recent projects. While it was easy to find several WordPress widgets that presented slideshows, it was very difficult to find one that allowed [...]]]></description>
			<content:encoded><![CDATA[<div align="center" style="float:right;display:inline;padding:5px 0 5px 10px;">

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm__528837746"
			class="flashmovie"
			width="300"
			height="250">
	<param name="movie" value="http://www.rabidgadfly.com/swf/slider.swf?contentfolder=/swf/slidercontent/" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.rabidgadfly.com/swf/slider.swf?contentfolder=/swf/slidercontent/"
			name="fm__528837746"
			width="300"
			height="250">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
Download the source <a href="http://www.rabidgadfly.com/fla/slider_rg.zip">here</a>
</div>
<p>When I was creating my <a href="http://www.rabidgadfly.com/index.php/coding-portfolio/" alt="My coding portfolio">coding portfolio</a> I wanted a slider app that would display a series of screenshots from some of my recent projects. While it was easy to find several WordPress widgets that presented slideshows, it was very difficult to find one that allowed multiple instances on the same page. Many didn&#8217;t even allow multiple instances across the blog.</p>
<p>I decided it would be easiest to create one myself. Admittedly it&#8217;s nothing flashy, but it fit the purpose well and I thought it may be useful to post. It utilizes Tweener, an amazingly simple open-source tweening library, for transitions. The library is included with the source. Other version and documentation are available on <a href="http://code.google.com/p/tweener/">Google code</a>.</p>
<h3>How to set up a slider</h3>
<ol>
<li>Create a subfolder under the folder where the slider swf will be stored. Each slideshow must have its own separate subfolder.
<li>Create a series of 250px(w) x 175px(h) images and place them in the subfolder.</li>
<li>Create an XML file named slides.xml in the subfolder with your images. This involves adding the image name, an optional title, and an optional description. The structure is as follows:
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;slides&gt;
	&lt;slide&gt;
		&lt;title&gt;Slide 1 Title&lt;/title&gt;
		&lt;desc&gt;Here is a description of Slide 1&lt;/desc&gt;
		&lt;image&gt;slide1.png&lt;/image&gt;
	&lt;/slide&gt;
	&lt;slide&gt;
		&lt;title&gt;Slide 2 Title&lt;/title&gt;
		&lt;desc&gt;Here is a description of Slide 2&lt;/desc&gt;
		&lt;image&gt;slide2.png&lt;/image&gt;
	&lt;/slide&gt;
&lt;/slides&gt;
</pre>
</li>
<li>VERY IMPORTANT: Pass the folder path to the SWF as a flashvar named contentfolder. For example, if you&#8217;re using Adobe&#8217;s embedding method and your xml and images are on your site under /swf/myslides, you would add <strong>&#8216;flashvars&#8217;,'contentfolder=/swf/myslides/&#8217;</strong> at the end of the AC_FL_RunContent function (don&#8217;t forget to add a comma before it to separate it from the other values). </li>
</ol>
<h3>Tips</h3>
<ul>
<li>The code is in a <a href="http://www.adobe.com/devnet/flash/quickstart/external_files_as3/" alt="What is a document class?" target="_blank">document class</a> named CustomDocument.as under the com subfolder.</li>
<li>If you want to change the navigation buttons, you can change them in the library. nextGraphic and prevGraphic are the base graphics and Next and Prev apply filtering and state modifications.</li>
<li>If you want slides of a different size, it should only take a couple of tweaks. First, resize your document ( Modify > Document ). Then, modify the buttons and Slide to accommodate your new size. These objects are in the library (The Next and Previous buttons, and the Slide itself, are all in the library ( Window > Library ). Finally, modify the nextX and nextY variables in the CustomDocument.as file. nextX is the X coordinate where the first slide will be placed. nextY is the Y coordinate.</li>
<li>The source is packaged using the _sans device font. You can change the font inside the Slide movie clip. Remember to embed the characters or your font will not appear!</li>
<li>If your images won&#8217;t load then you&#8217;re probably either forgetting to pass the contentfolder flashvar, or your images aren&#8217;t in the right place. <a href="http://getfirebug.com/" target="_blank">Firebug</a> is a great tool for troubleshooting this issue.</li>
</ul>
<p style="padding:20px;">Glenn</p>
<p><a href="http://www.rabidgadfly.com/fla/slider_rg.zip"><img caption="Download source" align="right" src="http://www.rabidgadfly.com/images/download.png" alt="Download the AS3 Slider source" title="AS3 Slider source" width="74" height="56" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2010/04/simple-xml-driven-flash-as3-slider/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>AS3 Easy Dynamic Movie Clip Buttons</title>
		<link>http://rabidgadfly.com/2010/03/as3-easy-dynamic-movie-clip-buttons/</link>
		<comments>http://rabidgadfly.com/2010/03/as3-easy-dynamic-movie-clip-buttons/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 14:22:25 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[buttons]]></category>
		<category><![CDATA[document class]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[event listener]]></category>
		<category><![CDATA[movie clip]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=145</guid>
		<description><![CDATA[This example demonstrates how to dynamically place and code movie clip buttons using AS3. It also demonstrates the use of a Document Class.]]></description>
			<content:encoded><![CDATA[<p>Back in 2007 I posted a <a href="http://www.rabidgadfly.com/index.php/2007/02/12/easy-movie-clip-buttons-part-3-of-3-defining-button-states/" alt="Easy Movie Clip Buttons Part 3 of 3: Defining Button States" target="_blank">tutorial</a> explaining how to dynamically create movie clip buttons using AS2. I received a lot of feedback on it including some great questions, like &#8220;How can I auto-select a button?&#8221; and &#8220;Can you do this in AS3?&#8221;. Like the <a href="http://www.rabidgadfly.com/index.php/2007/03/20/clickable-button-inside-a-draggable-movie-clip/" alt="AS2 Clickable Button in a Draggable Clip" target="_blank">Clickable Button in a Draggable Clip</a> app that I <a href="http://www.rabidgadfly.com/index.php/2010/03/15/as3-clickable-button-inside-a-draggable-movie-clip/" alt="AS3 Clickable Button in a Draggable Clip" target="_blank">re-coded in AS3</a>, I felt that recoding this app could be a good exercise that would offer an introduction to some basic, frequently-used techniques for someone learning AS3.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_buttonMCs_Part3_2065457292"
			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_2065457292"
			width="350"
			height="100">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><span id="more-145"></span></p>
<p><a href="http://www.rabidgadfly.com/fla/MCButtons_as3.zip">Download the source</a></p>
<p>The first upgrade I made was to take the code out of the timeline and place into a <a href="http://help.adobe.com/en_US/Flash/10.0_UsingFlash/WS3e7c64e37a1d85e1e229110db38dec34-7fa4a.html#WS026C9121-F7D4-496d-94C8-368BF6938149a" target="_blank">Document class</a>. The Document class is a class that will execute when your application starts. In most cases it extends the main timeline, which is a MovieClip. You define your Document class in the &#8220;Document Class&#8221; field of the Property Inspector when nothing is selected. It can also be defined in the ActionScript 3 Settings section of your Publish Settings ( File > Publish Settings > [Flash] > Settings > Document Class.</p>
<p>There are plenty of reasons to like the Document class but one of my favorites is that it allows me to code in the FlashDevelop IDE rather than in the confining embrace of the Flash IDE code editor. If you&#8217;re a PC user and you&#8217;ve never seen <a href="http://www.flashdevelop.org/wikidocs/index.php?title=Main_Page" target="_blank">FlashDevelop</a> you should check it out.</p>
<p>A few things to remember about the Document class that differ from the timeline method:<br />
1) The Document class is a Class like any other that must follow the correct syntax. You must include the package (folder) and define it as an extension of a Display Object ( public class CustomDocument extends MovieClip ).<br />
2) You need to include the classes required to support the objects that you are using. For example,  if you are using a TextField you must import flash.text.Textfield.<br />
3) If you are referencing any objects that exist on the stage from your Document Class you must define a variable for that object. For example, because my application has a text field in the first frame with an instance name of fullMonth_txt, I must declare that variable in my Document class ( public var fullMonth_txt:TextField; )</p>
<p>If you don&#8217;t think you&#8217;re ready to start using a Document class, have no fear, I modified the code on the timeline too. Just uncomment it and remove the Document Class reference and you&#8217;re good to go old-school!</p>
<p>When the application starts it stops the main timeline, then proceeds to loop through the array of months that I declared earlier:</p>
<pre class="brush: as3; title: ; notranslate">
private var month_array:Array = new Array ({month:&quot;JAN&quot;,fullNm:&quot;January&quot;},{month:&quot;FEB&quot;,fullNm:&quot;February&quot;},...;
...
for (var a:Number = 0; a &lt; month_array.length; a++) {
	container_mc = new MovieClip();
	button_mc = new ButtonMC();
	addChild(container_mc);
	container_mc.addChild(button_mc);
	container_mc.x = nextX;
	container_mc.y = nextY;
	button_mc.month_txt.text = month_array[a].month;
	button_mc.monthName = month_array[a].fullNm;
	button_mc.mouseChildren = false;
	...
</pre>
<p>ButtonMC is a class that was created dynamically by Flash using the button_mc movie clip in the library. You can do this for any movie clip simply by going into its properties and clicking &#8220;Export for ActionScript.&#8221;</p>
<p>For every month, a new instance of my button is placed on the stage. The month abbreviation is used to update the dynamic text field inside the button named month_txt. The full month name is stored as a dynamic property of the button. This will be used to populate the fullMonth_txt text field when the button is clicked.</p>
<p>&#8220;button_mc.mouseChildren = false;&#8221; tells the player to ignore any children of button_mc for mouse actions. Without this line the mouse events would not work if the user were to hover over the button text. This drove me batty for a while!</p>
<p>Next is the code that will set the current month&#8217;s button to the selected state. If you don&#8217;t want a button to be selected at startup just get rid of this code:</p>
<pre class="brush: as3; title: ; notranslate">
private var today:Date = new Date();
private var thisMonth:Number = today.getMonth();
...
if(a == thisMonth) {
	button_mc.gotoAndStop(&quot;selected&quot;);
	selectedButton = button_mc;
} else {
	button_mc.stop();
}
&lt;/code&gt;&lt;/pre&gt;
</pre>
<p>When I declare the variable thisMonth above, I set it to the number of the current month. Because month numbering starts with 0, it will align perfectly with my loop through the months array. Therefore, when &#8216;a&#8217; (the loop index) equals &#8216;thisMonth&#8217;, that button is set to the selected state.</p>
<p>Next I assign the mouse event listeners. This is how you code button functionality in AS3. The listeners will be responsible for calling the appropriate function when a mouse event takes place:</p>
<pre class="brush: as3; title: ; notranslate">
button_mc.addEventListener(MouseEvent.CLICK,buttonClick);
button_mc.addEventListener(MouseEvent.MOUSE_OVER,buttonOver);
button_mc.addEventListener(MouseEvent.MOUSE_OUT,buttonOut);
button_mc.addEventListener(MouseEvent.MOUSE_DOWN,buttonDown);
</pre>
<p>For example, when the mouse clicks button_mc it will fire the buttonClick function. The buttonClick function takes the event as a parameter and executes its code which populates the Month Name text field (fullMonth_txt), moves the previously selected button to the active state, moves itself to the selected state, and assigns itself as selectedButton.</p>
<pre class="brush: as3; title: ; notranslate">
private function buttonClick(evt:MouseEvent):void {
	fullMonth_txt.text = evt.target.monthName;
	if(selectedButton &amp;&amp; (selectedButton != evt.target)) {
		selectedButton.gotoAndStop(&quot;active&quot;);
	}
	selectedButton = evt.target;
	evt.target.gotoAndStop(&quot;selected&quot;);
}
</pre>
<p>The selectedButton Movie Clip that I declared at the top of the Document class always holds a reference to the selected button. The target of the event (evt.target) is the object that was clicked. That&#8217;s how one function can handle the changes for any button without having to poll all buttons for their states every time a new button is selected.</p>
<p>There&#8217;s a little more in the actual code but those are most of the key points. If you find this post useful, be sure to check out my previous post, <a href="http://www.rabidgadfly.com/index.php/2010/03/15/as3-clickable-button-inside-a-draggable-movie-clip/" alt="AS3 Clickable Button in a Draggable Clip">AS3 Clickable Button Inside a Draggable Movie Clip</a> .</p>
<p>If you missed the link to the example above, you can <a href="http://www.rabidgadfly.com/fla/MCButtons_as3.zip">download it here</a>.</p>
<p>-Glenn</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2010/03/as3-easy-dynamic-movie-clip-buttons/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AS3 Clickable Button Inside a Draggable Movie Clip</title>
		<link>http://rabidgadfly.com/2010/03/as3-clickable-button-inside-a-draggable-movie-clip/</link>
		<comments>http://rabidgadfly.com/2010/03/as3-clickable-button-inside-a-draggable-movie-clip/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 17:08:52 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[click]]></category>
		<category><![CDATA[drag]]></category>
		<category><![CDATA[movieclip]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=129</guid>
		<description><![CDATA[Demonstrates how to use AS3 to create a clickable button inside a draggable movie clip.]]></description>
			<content:encoded><![CDATA[<p>A few years back I wrote <a href="http://www.rabidgadfly.com/?p=33" alt="AS2 Clickable Button Inside a Draggable Movie Clip">a popular post</a> that demonstrated an AS2 technique to have a clickable button inside of a draggable movie clip. Recently, I received a request to see how it would be accomplished in AS3.</p>
<p>I haven&#8217;t posted in a LONG time and I thought it was a great idea. Not only does it get me blogging again, but it&#8217;s a great, short introduction to a couple of the new features in AS3.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_buttonInDraggableMC_as3_439688934"
			class="flashmovie"
			width="450"
			height="400">
	<param name="movie" value="http://www.rabidgadfly.com/swf/buttonInDraggableMC_as3.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.rabidgadfly.com/swf/buttonInDraggableMC_as3.swf"
			name="fm_buttonInDraggableMC_as3_439688934"
			width="450"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><span id="more-129"></span></p>
<p style="margin:5px 0 15px 0;"><em><a href="http://www.rabidgadfly.com/fla/buttonInDraggableMC_as3_cs3.zip">Download the sample</a></em></p>
<p>AS3 uses events to handle mouse click functionality. Rather than the AS2 method of adding an onRelease function to the clickable object, you now assign an event listener. While this is a pretty significant difference that may take a bit of getting used to, programmatically it makes a lot of sense.</p>
<p>AS3 used the DOM event model as a basis for its own event handling. So, instead of something that looks like this:</p>
<pre class="brush: as3; title: ; notranslate">
//AS2 button event
container_mc.drag_btn.onPress = function() {
	startDrag(this._parent);
};
</pre>
<p>The AS3 method looks like this:</p>
<pre class="brush: as3; title: ; notranslate">
//AS3 event handling
container_mc.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler_Drag);
function mouseDownHandler_Drag(mEvent:MouseEvent):void {
	mEvent.target.startDrag();
}
</pre>
<p><em>For a good introduction to AS3 Event Handlers, check out the <a href="http://www.newtonflash.com/blog/2009/03/05/as3-event-handling-part-1/">Newton Flash 6 part series</a>. Even though he uses the moniker of &#8220;Devigner&#8221;, which I can&#8217;t stand, the posts are pretty informative and to the point.</em></p>
<p>Another significant difference is that I no longer need an invisible button to allow me to drag the container around. AS3&#8242;s event bubbling makes it possible to listen to both the container and the button within the container at the same time. Ruben Swieringa wrote a <a href="http://www.rubenswieringa.com/blog/eventbubbles-eventcancelable-and-eventcurrenttarget">great post explaining AS3 bubbling</a> which is definitely worth a look.</p>
<p>One addition to the code that may trip you up is the assignment of buttonMode to the Click Me button. AS3 does not assume that you want the hand cursor to appear over a movie clip just because you added a listener. Because of this, by default the cursor will remain an I-bar unless you set the clip&#8217;s buttonMode to true:</p>
<pre class="brush: as3; title: ; notranslate">
container_mc.btn.buttonMode = true;
</pre>
<p>Another change to notice in the sample code is that there are no longer referrals to &#8220;_parent.&#8221; (Though if there were, you would see that the new syntax drops the underscore so that it is simply &#8220;parent&#8221;.) The reason it was required in the first place was because I needed to reference an object that was out of the clickable objects scope, and I didn&#8217;t want to use _root. AS3&#8242;s Event Handling method allows you to put the function code in the same scope as the outer container. This means that I can refer to it directly rather than having to navigate upwards:</p>
<pre class="brush: as3; title: ; notranslate">
//as2
this._parent._parent.text_txt.text=&quot;\rclick #&quot;+counter;

//as3
text_txt.text=&quot;\rclick #&quot;+counter;
</pre>
<p>One final piece that I&#8217;d like to point out is the reference to mEvent.target in my handler functions. mEvent is a reference to the mouse event pulled from the function&#8217;s parms. mEvent.target is a reference to the object that the listener was attached to. So, when I want to start dragging the object that was clicked, I just refer to the target of the event:</p>
<pre class="brush: as3; title: ; notranslate">
mEvent.target.startDrag();
</pre>
<p>My apologies for such a long post about such a short sample. I just felt that this sample offered a great opportunity to address some of the early stumbling blocks when making the move to AS3.</p>
<p>-Glenn</p>
<p>NOTE: If you didn&#8217;t notice the sample link above, <em><a href="http://www.rabidgadfly.com/fla/buttonInDraggableMC_as3.zip">here it is again</a></em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2010/03/as3-clickable-button-inside-a-draggable-movie-clip/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Can I access Stage from an AS3 Class with no DisplayObject?</title>
		<link>http://rabidgadfly.com/2008/10/refer-to-stage-from-as3-class/</link>
		<comments>http://rabidgadfly.com/2008/10/refer-to-stage-from-as3-class/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 12:59:47 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[stage]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=80</guid>
		<description><![CDATA[I&#8217;m working on a project that requires creating and adding a Movie Clip to the Stage from a class file. Seemed like an easy task, however, referring to the Stage from my class turned out to be trickier than I thought. I know that, although you can&#8217;t refer to Stage directly, it is a property [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project that requires creating and adding a Movie Clip to the Stage from a class file. Seemed like an easy task, however, referring to the Stage from my class turned out to be trickier than I thought.</p>
<p>I know that, although you can&#8217;t refer to Stage directly, it is a property of every DisplayObject named &#8216;stage&#8217; (lower case &#8216;s&#8217;). For example, if my class extends Sprite, I can get the Stage width by referring to &#8220;stage.width&#8221;.</p>
<p>The problem arises when a class does not extend a DisplayObject and a DisplayObject is not passed to your class. The project I&#8217;m working on fell into this category. The purpose of my class is simply to create and manage instances of another class. The problem I ran into was that I could not refer to the Stage because my class had no reference to a DisplayObject.</p>
<p>I ended up working around the problem by passing a DisplayObject instance, but out of curiosity, I&#8217;d like to know if there is any way around this issue. Is there a way to refer to the Stage from a class file that has no DisplayObject instance?</p>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2008/10/refer-to-stage-from-as3-class/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Is it possible to pass a structure to ColdFusion using Flash AS3 / Remoting</title>
		<link>http://rabidgadfly.com/2008/05/is-it-possible-to-pass-a-structure-to-coldfusion-using-flash-as3-remoting/</link>
		<comments>http://rabidgadfly.com/2008/05/is-it-possible-to-pass-a-structure-to-coldfusion-using-flash-as3-remoting/#comments</comments>
		<pubDate>Tue, 20 May 2008 14:57:15 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[remoting]]></category>
		<category><![CDATA[amf]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[netconnection]]></category>
		<category><![CDATA[objectEncoding]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=64</guid>
		<description><![CDATA[UPDATE: This problem has been solved. The solution is after the post. I&#8217;ve posted on a few forums now with no results so I&#8217;m resorting to my own blog. What I&#8217;m trying to do is pass a structure to a ColdFusion component from Flash. I&#8217;ve tried using Array, Object, and Dictionary types but it keeps [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE:</strong> This problem has been solved. The solution is after the post.</p>
<p>I&#8217;ve posted on a few forums now with no results so I&#8217;m resorting to my own blog. What I&#8217;m trying to do is pass a structure to a ColdFusion component from Flash. I&#8217;ve tried using Array, Object, and Dictionary types but it keeps failing with this error:</p>
<p>&#8220;Unknown object type tag (17)&#8221;</p>
<p>The error seems to be returned before the method is even reached suggesting that the cfc is rejecting the Remoting request altogether. I know the code is sound because I can change the structure to a string and get results back. I&#8217;ve also tried the Flash.Params method.</p>
<p>I&#8217;ve done a fair amount of research already, including studying <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=usingSalsaN_4.html">Adobe livedocs</a> which insists that it&#8217;s possible to do.</p>
<p>Here is my code:</p>
<pre><code>
loadData_btn.addEventListener(MouseEvent.MOUSE_DOWN, loadData)

var myService = new NetConnection()
myService.connect("http://localhost/flashservices/gateway/")

function loadData(evt:MouseEvent){
    var responder = new Responder(getTest_Result, onFault);
/* I've tried everything here including defining it as an Object and Dictionary. I also tried
defining it using dot notation and sending it as an object like so: {mystring:"hello"} */
	var mystruct:Array = new Array();
	mystruct["mystring"] = "hello";
	myService.call("com.mycomponent.test", responder, mystruct);
}

function getTest_Result(result){
    trace("success: "+ result);
}

function onFault( f){
	trace("There was a problem: " + f.description);
}
</code></pre>
<p>&#8230;and here&#8217;s my component function (I&#8217;ve tried with an argument type of &#8216;struct&#8217; as well as &#8216;any&#8217;):</p>
<pre><code>
<cffunction name="test" output="no" access="remote" returntype="string" >
	<cfargument name="argstruct" type="any" required="no" />
	<cfset mystr =arguments.argstruct["mystring"]>
	<cfreturn  mystr />
</cffunction>
</code></pre>
<p>Thanks in advance for any help!</p>
<p>rG</p>
<p><strong>SOLUTION:</strong> <em>After many hours of Googling, and much trial and error, I figured out how to make this work&#8230;and it&#8217;s a one line solution. Simply add myService.objectEncoding=0 before the myService.connect line at the top. It has to do with the way objects are serialized using AMF. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2008/05/is-it-possible-to-pass-a-structure-to-coldfusion-using-flash-as3-remoting/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>AS3 Event Generator Extension</title>
		<link>http://rabidgadfly.com/2008/02/as3-event-generator-extension/</link>
		<comments>http://rabidgadfly.com/2008/02/as3-event-generator-extension/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 18:20:31 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=58</guid>
		<description><![CDATA[Lee Brimelow, master of Flash tutorials (see gotoAndLearn.com), has released a free AS3 Event Generator extension for Flash CS3. The extension adds an &#8216;Event Generator&#8217; option under your Window > Other Panels menu. Once installed you simply select a named movie clip, select the event functionality you require for your application, click the &#8216;Copy to [...]]]></description>
			<content:encoded><![CDATA[<p>Lee Brimelow, master of Flash tutorials (see <a href="http://www.gotoandlearn.com/">gotoAndLearn.com</a>), has released a free AS3 Event Generator extension for Flash CS3. The extension adds an &#8216;Event Generator&#8217; option under your Window > Other Panels menu. Once installed you simply select a named movie clip, select the event functionality you require for your application, click the &#8216;Copy to Clipboard&#8217; button, then paste the code wherever you want it. The Event Generator code adds event listeners for the selected movie clip and creates supporting function skeletons.</p>
<p><a href="http://theflashblog.com/?p=331">Check it out!</a><br />
<img src="http://www.rabidgadfly.com/images/eventext.jpg" alt="Brimelow's Event Generator" /></p>
<p>rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2008/02/as3-event-generator-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

