<?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; flash</title>
	<atom:link href="http://rabidgadfly.com/tag/flash/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>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_420316526"
			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_420316526"
			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__1099793617"
			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__1099793617"
			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__852333396"
			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__852333396"
			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>FBTracer: Flash Tracer Chocolate in Firebug Peanut Butter</title>
		<link>http://rabidgadfly.com/2010/04/fbtracer-flash-tracer-chocolate-in-firebug-peanut-butter/</link>
		<comments>http://rabidgadfly.com/2010/04/fbtracer-flash-tracer-chocolate-in-firebug-peanut-butter/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 14:38:16 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[extension]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[fbtracer]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[flashtracer]]></category>
		<category><![CDATA[trace]]></category>
		<category><![CDATA[tracing]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=152</guid>
		<description><![CDATA[As a longtime fan of both Flash Tracer, the Firefox Flash tracing extension, and Firebug, arguably the best free web development extension available, I was ecstatic to hear that Alessandro Crugnola had created a FlashTracer plug-in for Firebug. While it&#8217;s possible to have both individual Flash Tracer and Firebug extensions running at the same time, [...]]]></description>
			<content:encoded><![CDATA[<p>As a longtime fan of both <a href="http://www.sephiroth.it/firefox/flashtracer/" alt="Flash Tracer">Flash Tracer</a>, the Firefox Flash tracing extension, and <a href="http://getfirebug.com/" alt="Firebug">Firebug</a>, arguably the best free web development extension available, I was ecstatic to hear that Alessandro Crugnola had created a FlashTracer plug-in for Firebug.</p>
<p>While it&#8217;s possible to have both individual Flash Tracer and Firebug extensions running at the same time, performance often suffers significantly. Adding Flash Tracer as a Firebug extension seems to have improved performance while making it more convenient and accessible.</p>
<p>As of this writing, it&#8217;s still in early beta but it&#8217;s working well enough for me. Check it out for yourself at <a href="http://www.sephiroth.it/firefox/fbtracer/" alt="FBTracer">sephiroth.it</a> .</p>
<div style="width:600px;text-align:center;margin:15px 0;"><img align="center" style="border:1px solid #000;" src="http://www.rabidgadfly.com/wp-content/uploads/fbtracer.png" alt="FBTracer" title="FBTracer" width="471" height="270" class="size-full wp-image-154" /></div>
<p>- Glenn</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2010/04/fbtracer-flash-tracer-chocolate-in-firebug-peanut-butter/feed/</wfw:commentRss>
		<slash:comments>3</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_1559272105"
			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_1559272105"
			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_1754234671"
			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_1754234671"
			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>Passing an Array or Object using Flash AS3 Remoting? Don&#039;t Forget the Object Encoding!</title>
		<link>http://rabidgadfly.com/2008/05/passing-an-array-or-object-using-flash-as3-remoting-dont-forget-the-object-encoding/</link>
		<comments>http://rabidgadfly.com/2008/05/passing-an-array-or-object-using-flash-as3-remoting-dont-forget-the-object-encoding/#comments</comments>
		<pubDate>Tue, 20 May 2008 20:12:35 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[amf]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[objectEncoding]]></category>
		<category><![CDATA[remoting]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=65</guid>
		<description><![CDATA[Earlier today I posted about an issue I was having when attempting to pass a structure to a ColdFusion web service using AS3 netConnection. Whenever I attempted to pass a structure to the web service, the call would be rejected before it even reached the method it was calling. The error I was receiving was [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier today <a href="http://www.rabidgadfly.com/?p=64">I posted about an issue</a> I was having when attempting to pass a structure to a ColdFusion web service using AS3 netConnection. Whenever I attempted to pass a structure to the web service, the call would be rejected before it even reached the method it was calling. The error I was receiving was</p>
<p>&#8220;Unknown object type tag (17)&#8221;</p>
<p>The <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/usingSalsaN_4.html">Adobe documentation</a> insisted this was possible but I tried everything I could think of with no success. There were a few <a href="http://www.google.com/search?q=%22Unknown+object+type+tag+(17)%22&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:en-US:official&#038;client=firefox-a">developers sharing my misery</a> but their calls for help went unanswered, and by extension, so did mine.</p>
<p>After spending the better part of two days tooling around with the code and searching the web, I finally hit on the solution. It derived from a combination of <a href="http://oscartrelles.com/archives/as3_flash_remoting_example">Oscar Trelles&#8217; post</a> on AS3 Flash Remoting and a <a href="http://www.laflash.org/node/560">post on laflash.org</a> about AS3 and Flash Media Server. In order to pass a structure to a ColdFusion component, I had to set the netConnection&#8217;s objectEncoding to AMF0 (the default is AMF3).</p>
<p>I&#8217;m guessing that this qualifies as a bug since AMF0 is supposed to be for serializing AS1 and AS2 objects and AMF3 is supposed to be optimized for AS3 objects. While I was able to send simple objects, like strings and integers, to the web service using the default setting, I ran into a wall when sending an Array, Object, or Dictionary type.</p>
<p>Until this issue is addressed, if you&#8217;re going to be sending complex objects to a ColdFusion web service, make sure to set the object encoding to AMF0. Here&#8217;s a simple example that sends a structure containing a string to a web service. The web service then returns the string:</p>
<p>AS3 CODE</p>
<pre><code>
var myService = new NetConnection()
////////////////////////////////////////////////
//set encoding to AMF0 for complex objects
myService.objectEncoding = 0;
///////////////////////////////////////////////
myService.connect("http://www.yourdomain.com/flashservices/gateway")

var responder = new Responder(getTest_Result, onFault);
var mystruct:Array = new Array();
mystruct.mystring = "foo";
myService.call("testAPI.test", responder, mystruct);

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

function onFault( f){
	trace("There was a problem: " + f.description);
}
</code></pre>
<p>COLDFUSION WEB SERVICE:<br />
<code>
<pre>
<cfcomponent>

	<cffunction name="test" output="no" access="remote" returntype="any" >
		<cfargument name="argstruct" type="any" />
		<cfset mystr1 =argstruct["mystring"]>
		<cfreturn  mystr1 />
	</cffunction>

</cfcomponent>
</pre>
<p></code></p>
<p>If you&#8217;re REALLY interested in objectEncoding, you can <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/ObjectEncoding.html">read up on it in Adobe&#8217;s livedocs</a> .</p>
<p>I hope this post saves someone the two days I just blew figuring it out!</p>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2008/05/passing-an-array-or-object-using-flash-as3-remoting-dont-forget-the-object-encoding/feed/</wfw:commentRss>
		<slash:comments>8</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>
	</channel>
</rss>

