<head>
<meta name="verify-v1" content="jdXlNhTAizhbBbTGh41NjO2QUe5Mm/bf2bkz3sed4eU=" />
</head>
<?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>Manjit Singh - Flash Developer &#187; Tutorials</title>
	<atom:link href="http://www.msinghinteractive.com/blog/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.msinghinteractive.com/blog</link>
	<description>Flash/Air AS2, AS3 Developer</description>
	<lastBuildDate>Sun, 06 Dec 2009 01:40:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating Dynamic button in AS3</title>
		<link>http://www.msinghinteractive.com/blog/2009/09/creating-dynamic-button-in-as2/</link>
		<comments>http://www.msinghinteractive.com/blog/2009/09/creating-dynamic-button-in-as2/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 22:05:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[AS3 Simple button]]></category>
		<category><![CDATA[Dynamic button in AS3]]></category>
		<category><![CDATA[Flash Simple button]]></category>

		<guid isPermaLink="false">http://www.msinghinteractive.com/blog/?p=15</guid>
		<description><![CDATA[In this small tutorial I will explain how to create dynamic button using Flash AS3. I have divided this tutorial into different steps which are as follow:-
Step 1
Create instances SimpleButton, Sprite, TextField and TextFormat classes.
123456var simpleButton:SimpleButton=new SimpleButton&#40;&#41;;
var butttonUpState:Sprite=new Sprite&#40;&#41;;
var butttonOverState:Sprite=new Sprite&#40;&#41;;
var buttonLabel1:TextField=new TextField&#40;&#41;;
var buttonLabel2:TextField=new TextField&#40;&#41;;
var textFormat:TextFormat=new TextFormat&#40;&#41;;
Step 2
Set text align to center and bold in [...]]]></description>
			<content:encoded><![CDATA[<p>In this small tutorial I will explain how to create dynamic button using Flash AS3. I have divided this tutorial into different steps which are as follow:-</p>
<p><strong>Step 1</strong></p>
<p>Create instances SimpleButton, Sprite, TextField and TextFormat classes.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> simpleButton<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=simplebutton%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:simplebutton.html"><span style="color: #004993;">SimpleButton</span></a>=<span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=simplebutton%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:simplebutton.html"><span style="color: #004993;">SimpleButton</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> butttonUpState<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a>=<span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> butttonOverState<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a>=<span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> buttonLabel1<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a>=<span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> buttonLabel2<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a>=<span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> textFormat<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a>=<span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p><strong>Step 2</strong></p>
<p>Set text align to center and bold in textFormat instance. Asign &#8220;Submit&#8221; text to both the TextField instances and set text color, width, height properties and finally set text format to one we created above.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">textFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span>=<span style="color: #990000;">&quot;center&quot;</span><br />
textFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bold</span>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
buttonLabel1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Button&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
buttonLabel1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">textColor</span>=0xFFFFFF<span style="color: #000066; font-weight: bold;">;</span><br />
buttonLabel1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span><br />
buttonLabel1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span>=<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span><br />
buttonLabel1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setTextFormat</span><span style="color: #000000;">&#40;</span>textFormat<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
buttonLabel2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Button&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
buttonLabel2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">textColor</span>=0xFFFFFF<span style="color: #000066; font-weight: bold;">;</span><br />
buttonLabel2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span><br />
buttonLabel2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span>=<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span><br />
buttonLabel2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setTextFormat</span><span style="color: #000000;">&#40;</span>textFormat<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p><strong>Step 3</strong></p>
<p>Draw backgrounds for button Up, Over, Down, and hitTest states. In this tutorial we are using same background for button Up, Down and hitTest states but you can create different background for each.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">with</span><span style="color: #000000;">&#40;</span>butttonUpState<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
<span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x333333<span style="color: #000066; font-weight: bold;">,</span>1<span style="color: #000000;">&#41;</span><br />
<span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span>0<span style="color: #000066; font-weight: bold;">,</span>0<span style="color: #000066; font-weight: bold;">,</span>50<span style="color: #000066; font-weight: bold;">,</span>20<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">with</span><span style="color: #000000;">&#40;</span>butttonOverState<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
<span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x0066FF<span style="color: #000066; font-weight: bold;">,</span>1<span style="color: #000000;">&#41;</span><br />
<span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span>0<span style="color: #000066; font-weight: bold;">,</span>0<span style="color: #000066; font-weight: bold;">,</span>50<span style="color: #000066; font-weight: bold;">,</span>20<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Step 4 and Final</strong></p>
<p>Add textfields instances to button Up and button Over state sprites. Assign these sprites to button states like given below and add simplebutton instances to flash movie stage.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">butttonUpState<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>buttonLabel1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
butttonOverState<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>buttonLabel2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
simpleButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">upState</span>=butttonUpState<span style="color: #000066; font-weight: bold;">;</span><br />
simpleButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">overState</span>=butttonOverState<span style="color: #000066; font-weight: bold;">;</span><br />
simpleButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">downState</span>=butttonUpState<span style="color: #000066; font-weight: bold;">;</span><br />
simpleButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">hitTestState</span>=butttonUpState<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>simpleButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>I hope this simple tutorial will be helpful. <a title="Simple Button fla" href="http://www.msinghinteractive.com/downloads/SimpleButton.fla" target="_self">Download Source Fla.</a></p>
<p>Cheers</p>
<p>M</p>
]]></content:encoded>
			<wfw:commentRss>http://www.msinghinteractive.com/blog/2009/09/creating-dynamic-button-in-as2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
