<?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>mikestickney.com &#187; dynamic buttons</title>
	<atom:link href="http://mikestickney.com/wordpress/tag/dynamic-buttons/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikestickney.com/wordpress</link>
	<description></description>
	<lastBuildDate>Tue, 06 Jul 2010 14:28:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flash Tutorial: Dynamic Buttons</title>
		<link>http://mikestickney.com/wordpress/flash-tutorial-dynamic-buttons/</link>
		<comments>http://mikestickney.com/wordpress/flash-tutorial-dynamic-buttons/#comments</comments>
		<pubDate>Sun, 27 Apr 2008 21:02:26 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ActionScript tutorials]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Tutorial]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[actionscript tutorial]]></category>
		<category><![CDATA[dynamic buttons]]></category>

		<guid isPermaLink="false">http://mikestickney.com/wordpress/?p=29</guid>
		<description><![CDATA[Flash Tutorial: Adding buttons dynamically to the Flash stage using ActionScript
Level: This is an intermeidate lesson, so I will assume that the reader is familiar with the basic use of the Flash software including stage, timeline, drawing tools, property window, etc.
Version: I will be using Flash CS3 and AS2 (athough tut is compatible with earlier [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Flash Tutorial:</strong> Adding buttons dynamically to the Flash stage using ActionScript</p>
<p><strong>Level:</strong> This is an intermeidate lesson, so I will assume that the reader is familiar with the basic use of the Flash software including stage, timeline, drawing tools, property window, etc.</p>
<p><strong>Version:</strong> I will be using Flash CS3 and AS2 (athough tut is compatible with earlier versions of Flash) and instructions are for the Mac. Windows users would use the PC counterparts for specific instructions on Flash Menu/Shortcut instuctions.</p>
<p style="text-align: left;"><strong>Description:</strong> In this tutorial, I will explain how to add buttons to your Flash movie with dynamic text content using ActionScript:</p>
<p><strong>Demo:</strong> 
<object type="application/x-shockwave-flash" width="250" height="100">
<param name="movie" value="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/dynamicButton_tutorial.swf" />
<embed src="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/dynamicButton_tutorial.swf" type="application/x-shockwave-flash" width="250" height="100" >
</object>
</p>
<p>Let&#8217;s get started!</p>
<p><strong>Note:</strong> For this tutorial, I will be using the buttons I created for a previous tutorial titled &#8220;Animating a button using a mask effect&#8221;.</p>
<p><span id="more-29"></span>If you haven&#8217;t already, I recommend you start with that tutorial, as I will not be going over the animation process of the button symbols in this tutorial. If you already know how to create button animations, you can use your own button animation symbol, or <a title="Flash Tutorial: Animated Button with Mask Effect" href="http://mikestickney.com/wordpress/wp-content/uploads/2008/03/btnWithMask_tut1.fla" >download the previous tutorial source file here</a>.</p>
<p align="center">&#8212;- ads by google &#8212;-<br />
<script type="text/javascript"><!--
google_ad_client = "pub-7252304256657784";
google_ad_slot = "4730110072";
google_ad_width = 234;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
<p>Select &#8220;File &gt; New&#8221; (command-&#8221;N&#8221;) and select Flash File (ActionScript 2.0) to open a new Flash document file. Save the file, and give it the appropriate name. I will call this &#8220;dynamicButton_tutorial.fla&#8221;. Feel free to change the document dimensions to whatever you like (&#8220;Modify &gt; Document or &#8220;command-J&#8221;), but for the purpose of this tutorial, I will use 250&#215;100 pixels.</p>
<p>Choose &#8220;File &gt; Import &gt; Open External Library&#8221; (shift-cmd-O), and navigate to where you placed the source file of our previous tutorial (btnWithMask_tut1.fla) and click &#8220;Open&#8221;. What this will do is open up just the &#8220;Symbol Library&#8221; of that source file. Tip: You can also access the symbol library of any .fla file you have open with the dropdown menu in your Symbol Library window (Fig. 1).</p>
<p><img src="http://www.spitshine-design.com/images/tutorials/tut10_fig1.gif" alt="Dynamic button tutorial fig. 1" width="450" height="455" /></p>
<p>We will be using the symbol called &#8220;mc_btn1&#8243; from the Button With Masked Animation source file, so we can simply click and drag this symbol from one library to the other. (Fig. 1). If you notice, when you drag the one symbol, it should also place the symbol &#8220;img_highlight&#8221; in your current file symbol library. This is because the &#8220;img_highlight&#8221; symbol is used within the &#8220;mc_btn1&#8243; symbol, so Flash knows to import all associated symbols as well.</p>
<p>You can go ahead and close the external symbol library so save space since we don&#8217;t need any other symbols from there. In our dynamic button .fla symbol library, double click on our &#8220;mc_btn1&#8243; symbol to bring us into symbol editing mode. You should see several layers and animation tweens in your timeline. We are going to leave all of this as is, so go ahead and lock all of these layers. What we need to do is add our text boxes that we will be using as our button labels. Add a new layer above your layer named &#8220;mask&#8221; and call it &#8220;text&#8221;. WIth the text tool (T), draw a box roughly the same width of our button, and position it on the center of our button shape. Select your text box, and in the Properties Panel (WIndow &gt; Properties &gt; Properties (cmd-F3)), and give it the settings in Fig. 2.</p>
<p><img src="http://www.spitshine-design.com/images/tutorials/tut9_fig2.gif" alt="Dynamic button tutorial fig. 2" width="350" height="85" /></p>
<p>Now, select the text box, choose Edit &gt; Copy (cmd-C) and then Edit &gt; Paste in Place (cmd-shift-V), and move it 2 or three pixels up and to the left. In Properties Panel, leave all the settings the same, except change the instance name from &#8220;textBlack&#8221; to &#8220;textWhite&#8221;, and change the color to white. What we are doing is simply giving our button label a basic &#8220;dropshadow&#8221; effect, just to make it more easily legible on all the button states.</p>
<p>We are now done editing our button, but since we are going to be placing our button on the stage using ActionsScript, the final thing we need to do is assign our buttona &#8220;Linkage&#8221; identifier name. Not to be confused with &#8220;symbol name&#8221; or &#8220;instance name&#8221;, an identifier name is used to call our button in ActionScript in order to be place on our stage. To give you button an id, right-click (control-click) on your button symbol in your library, and select &#8220;Linkage&#8230;&#8221; from the menu. This will open the Linkage Properties window (Fig. 3). Click on the &#8220;Export for ActionScript&#8221; check box and in the &#8220;Identifier&#8221; field, type &#8220;button&#8221; and hit OK.</p>
<p><img src="http://www.spitshine-design.com/images/tutorials/tut10_fig3.gif" alt="Dynamic button tutorial fig. 3" width="400" height="255" /></p>
<p>Now, it&#8217;s time for our ActionScript. It may look like a lot, but don&#8217;t be too intimidated, it&#8217;s not nearly as complicated as it looks, I promise!</p>
<p>On our main timeline, click on the first (and only) layer and give it a name of &#8220;actions&#8221;. In keyframe one, open the Actions Panel (Window &gt; Actions or alt-F9) and paste the following code:</p>
<p style="text-align: left; padding-left: 30px;"><span style="color: #000080;">onLoad = function(){<br />
var button:Array = [home, about, contact];</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">var xPosition:Number = 50;<br />
var yPosition:Number = 15;</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">for(i=0;i&lt;button.length;i++){<br />
_root.attachMovie(&#8220;button&#8221;,&#8221;btn&#8221;+i,_root.getNextHighestDepth());</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">_root["btn"+i]._x = xPosition;<br />
_root["btn"+i]._y = yPosition;</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">yPosition = yPosition + 25;</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">_root.btn0.textBlack.text = &#8220;Home&#8221;;<br />
_root.btn1.textBlack.text = &#8220;About&#8221;;<br />
_root.btn2.textBlack.text = &#8220;Contact&#8221;;</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">_root.btn0.textWhite.text = &#8220;Home&#8221;;<br />
_root.btn1.textWhite.text = &#8220;About&#8221;;<br />
_root.btn2.textWhite.text = &#8220;Contact&#8221;;</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">_root.btn0.link = &#8220;http://www.spitshine-design.com&#8221;;<br />
_root.btn1.link = &#8220;http://www.spitshine-design.com/about.html&#8221;;<br />
_root.btn2.link = &#8220;http://www.spitshine-design.com/contact.html&#8221;;</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">_root["btn"+(i)].onRollOver = btnOver;<br />
_root["btn"+(i)].onRollOut = btnOut;<br />
_root["btn"+(i)].onRelease = btnRelease;<br />
_root["btn"+(i)].onPress = btnPress;<br />
}<br />
}</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">function btnOver(){<br />
this.gotoAndPlay(&#8220;over&#8221;);<br />
}</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">function btnOut(){<br />
this.gotoAndPlay(&#8220;off&#8221;);<br />
}</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">function btnPress(){<br />
this.gotoAndStop(&#8220;down&#8221;);<br />
}</span></p>
<p style="padding-left: 30px;"><span style="color: #000080;">function btnRelease() {<br />
this.gotoAndStop(&#8220;off&#8221;);<br />
getURL(this.link);<br />
}</span></p>
<p style="text-align: left;">That&#8217;s it! Go ahead and test your movie. You should see 3 buttons appear, stacked, with the top one labled &#8220;home&#8221;, the middle one labeled &#8220;about&#8221; and the bottom one labeled &#8220;contact&#8221;. You should also see the animation on the different rollover states as well.</p>
<p>Since there is a lot of code here, rather than explain it all here, I decided to heavily comment the code in the source file. Since the real objective of any tutorial is for the reader to actually learn WHY things work and not just how, I encourage you to <a title="Flash Tutorial: Dynamic Buttons source file" href="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/dynamicButton_tutorial.fla" >download the source file</a> and read through the comments. The comments also help to explain the different items that need to be edited to customize your menu, such as placement, position and labels.</p>
<p>As always, I hope you found this tutorial helpful, and comments/questions are welcome. Thanks for reading!</p>
<p><strong>Source Files (Flash 8): </strong><a title="Flash Tutorial: Dynamic Buttons" href="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/dynamicButton_tutorial.fla" >Flash Tutorial: Character Movement with Arrow Keys</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikestickney.com/wordpress/flash-tutorial-dynamic-buttons/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

