<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Making a button work in Flash CS3 with ActionScript 3.0 - it&#8217;s not too bad</title>
	<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/</link>
	<description>...the site you can never remember how to type...</description>
	<pubDate>Thu, 28 Aug 2008 12:32:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: James</title>
		<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-506</link>
		<dc:creator>James</dc:creator>
		<pubDate>Mon, 25 Aug 2008 18:37:05 +0000</pubDate>
		<guid>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-506</guid>
		<description>Help! I have created a Flash CS3 Home page. I have a preloader on Frame 1 of my Actions layer. I have a stop action on Frame 32. I have 7 rollover buttons that animate as the come into the page. If I test the movie, it plays and stops on Frame 32. Each button is on its own layer. Where in the heck do I add the scripts that I want to add a URL script to each button? I have tried several places. If I add it to Frame 32, after the "stop();" the movie just keeps looking instead of stopping. This is so much of a pain than AS2. Why can't you add a script to a button directly? Any advice would be much appreciated. - James</description>
		<content:encoded><![CDATA[<p>Help! I have created a Flash CS3 Home page. I have a preloader on Frame 1 of my Actions layer. I have a stop action on Frame 32. I have 7 rollover buttons that animate as the come into the page. If I test the movie, it plays and stops on Frame 32. Each button is on its own layer. Where in the heck do I add the scripts that I want to add a URL script to each button? I have tried several places. If I add it to Frame 32, after the &#8220;stop();&#8221; the movie just keeps looking instead of stopping. This is so much of a pain than AS2. Why can&#8217;t you add a script to a button directly? Any advice would be much appreciated. - James</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laura G</title>
		<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-446</link>
		<dc:creator>Laura G</dc:creator>
		<pubDate>Sat, 16 Aug 2008 15:43:51 +0000</pubDate>
		<guid>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-446</guid>
		<description>Jonathan - i got the same error message referring to the first line of script</description>
		<content:encoded><![CDATA[<p>Jonathan - i got the same error message referring to the first line of script</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-445</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Fri, 15 Aug 2008 20:52:55 +0000</pubDate>
		<guid>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-445</guid>
		<description>Why on earth would they make it more complex? You would think that they would make the code shorter or something instead of twice as LONG!</description>
		<content:encoded><![CDATA[<p>Why on earth would they make it more complex? You would think that they would make the code shorter or something instead of twice as LONG!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Jason</title>
		<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-444</link>
		<dc:creator>Jonathan Jason</dc:creator>
		<pubDate>Fri, 15 Aug 2008 16:25:19 +0000</pubDate>
		<guid>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-444</guid>
		<description>Josh

take a look at where you placed your code it sounds like the code is in the wrong place 

try putting it on a frame that can be read through out the whole movie

if that doesn't work post your code so we can take a look at it.</description>
		<content:encoded><![CDATA[<p>Josh</p>
<p>take a look at where you placed your code it sounds like the code is in the wrong place </p>
<p>try putting it on a frame that can be read through out the whole movie</p>
<p>if that doesn&#8217;t work post your code so we can take a look at it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Jason</title>
		<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-443</link>
		<dc:creator>Jonathan Jason</dc:creator>
		<pubDate>Fri, 15 Aug 2008 16:21:14 +0000</pubDate>
		<guid>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-443</guid>
		<description>LOST in AS3 here is the code I think you need for your project when trying to flip from one frame to another you can use really simple math and the "Read Only" property of the MovieClip time line "currentFrame" and by using if statements you can loop from the first frame to the last with out running out of bounds.

stop();

function imgFoward(evt:MouseEvent):void{
	if(this.currentFrame == 10){
		this.gotoAndStop(1);
	}
	this.gotoAndStop(this.currentFrame +1);
}


function imgRewind( evt:MouseEvent):void{
	if(this.currentFrame == 1){
		this.gotoAndStop(10);
	}
	this.gotoAndStop(this.currentFrame -1);
}

fowardBtn.addEventListener(MouseEvent.CLICK, imgFoward);
rewindBtn.addEventListener(MouseEvent.CLICK, imgRewind);</description>
		<content:encoded><![CDATA[<p>LOST in AS3 here is the code I think you need for your project when trying to flip from one frame to another you can use really simple math and the &#8220;Read Only&#8221; property of the MovieClip time line &#8220;currentFrame&#8221; and by using if statements you can loop from the first frame to the last with out running out of bounds.</p>
<p>stop();</p>
<p>function imgFoward(evt:MouseEvent):void{<br />
	if(this.currentFrame == 10){<br />
		this.gotoAndStop(1);<br />
	}<br />
	this.gotoAndStop(this.currentFrame +1);<br />
}</p>
<p>function imgRewind( evt:MouseEvent):void{<br />
	if(this.currentFrame == 1){<br />
		this.gotoAndStop(10);<br />
	}<br />
	this.gotoAndStop(this.currentFrame -1);<br />
}</p>
<p>fowardBtn.addEventListener(MouseEvent.CLICK, imgFoward);<br />
rewindBtn.addEventListener(MouseEvent.CLICK, imgRewind);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Jason</title>
		<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-442</link>
		<dc:creator>Jonathan Jason</dc:creator>
		<pubDate>Fri, 15 Aug 2008 15:48:42 +0000</pubDate>
		<guid>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-442</guid>
		<description>Laura G

try it like this

function mouseDownHandler (event:MouseEvent):void{
this.gotoAndStop(71);
}

english.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); 

you error was you didn't put assign function to the event handler at the end of your line of code.</description>
		<content:encoded><![CDATA[<p>Laura G</p>
<p>try it like this</p>
<p>function mouseDownHandler (event:MouseEvent):void{<br />
this.gotoAndStop(71);<br />
}</p>
<p>english.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); </p>
<p>you error was you didn&#8217;t put assign function to the event handler at the end of your line of code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Jason</title>
		<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-441</link>
		<dc:creator>Jonathan Jason</dc:creator>
		<pubDate>Fri, 15 Aug 2008 15:40:43 +0000</pubDate>
		<guid>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-441</guid>
		<description>You People are using AS3 in a really primitive way specially for the use of multiple buttons writting function after function after function and the  same with event handlers that’s to much work guys why not use the power of Arrays and Loops to assign one function to all your buttons?  

let me explain 

first off create all your buttons and there functionality I prefer to use MovieClips to make my buttons for the flexibility.

Give them simple names for example you can name them the same as the sections of let’s say a website like (home, aboutUs, contactUs) you will be surprised how much easier this makes things later when you can use the names of your buttons to do a lot of other things using AS3's classes

Now create an Array with all your buttons names in it like so;

var btnArray:Array = new Array(home, aboutUs, contactUs);

We will loop through the array later using a (for Loop) to access the buttons by the index number of the array.

Then write your on click, over and out functions and issue the instruction to the event target button instead of a particular button, this makes your function reusable and that is one of the biggest advantages of OOP languages like AS3. If this doesn't make sense keep  reading

Leave them blank for now!


function onMouseClick (event:MouseEvent):void {

}

function onMouseOver (evt:MouseEvent):void {

}

function onMouseOut (evt:MouseEvent):void {

}

now the For Loop this is where the magic happens !!!





Let me explain!


write a loop that uses a variable give it the name of a single letter I will use the letter (i) make it an integer and give it the value of 0, then compare that variable with the array's length property by setting it less then the array.length property of the array class, and finally increase the variable by one by using the ++ method of AS3.

inside the loop we add the button functionality by assessing the button through the arrays index by using our  loop variable to access it like so "btnArray[i]",  

and if you use MovieClips for your buttons 2 little bits of code to make them work like true buttons the buttonMode and the mouseChildren property’s of the MovieClip class they both get a Boolean value so there really easy to set.

for (var i: int = 0; i&#60; btnArray.length; i++){
btnArray[i].addEventListener(MouseEvent.CLICK, onMouseClick);
btnArray[i].addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
btnArray[i].addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
btnArray[i].buttonMode = true;
btnArray[i].mouseChildren = true;
}


now add your functionality to your functions if the buttons are going to do totally different things the use if and else if statements to assign the functionality if they are for navigation to a url then use the navigateToUrl property of the flash.net class and if it is for navigation in the flash file then go back to your flash file and at the beginning of each section put a frame label with the same name as the button that will navigate to that section then use the event.target.name property to go there like so;

function onMouseClick (event:MouseEvent):void {
this.gotoAndStop(home);
navigateToUrl(new URLRequest(http://flashthusiast.com))
}

function onMouseOver (event:MouseEvent):void {
event.target.gotoAndPlay(over)
}

function onMouseOut (event:MouseEvent):void {
event.target.gotoAndPlay(out)
}


I hope that was clear enough for the smart ones lol any how the complete code is a lot more clean and short the writing ten functions and ten event listeners here it is 


var btnArray:Array = new Array(home, aboutUs, contactUs);

function onMouseClick (event:MouseEvent):void {
this.gotoAndStop(home);
navigateToUrl(new URLRequest("http://flashthusiast.com"))
}

function onMouseOver (event:MouseEvent):void {
event.target.gotoAndPlay(over)
}

function onMouseOut (event:MouseEvent):void {
event.target.gotoAndPlay(out)
}



for (var i: int = 0; i&#60; btnArray.length; i++){
btnArray[i].addEventListener(MouseEvent.CLICK, onMouseClick);
btnArray[i].addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
btnArray[i].addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
btnArray[i].buttonMode = true;
btnArray[i].mouseChildren = true;
}</description>
		<content:encoded><![CDATA[<p>You People are using AS3 in a really primitive way specially for the use of multiple buttons writting function after function after function and the  same with event handlers that’s to much work guys why not use the power of Arrays and Loops to assign one function to all your buttons?  </p>
<p>let me explain </p>
<p>first off create all your buttons and there functionality I prefer to use MovieClips to make my buttons for the flexibility.</p>
<p>Give them simple names for example you can name them the same as the sections of let’s say a website like (home, aboutUs, contactUs) you will be surprised how much easier this makes things later when you can use the names of your buttons to do a lot of other things using AS3&#8217;s classes</p>
<p>Now create an Array with all your buttons names in it like so;</p>
<p>var btnArray:Array = new Array(home, aboutUs, contactUs);</p>
<p>We will loop through the array later using a (for Loop) to access the buttons by the index number of the array.</p>
<p>Then write your on click, over and out functions and issue the instruction to the event target button instead of a particular button, this makes your function reusable and that is one of the biggest advantages of OOP languages like AS3. If this doesn&#8217;t make sense keep  reading</p>
<p>Leave them blank for now!</p>
<p>function onMouseClick (event:MouseEvent):void {</p>
<p>}</p>
<p>function onMouseOver (evt:MouseEvent):void {</p>
<p>}</p>
<p>function onMouseOut (evt:MouseEvent):void {</p>
<p>}</p>
<p>now the For Loop this is where the magic happens !!!</p>
<p>Let me explain!</p>
<p>write a loop that uses a variable give it the name of a single letter I will use the letter (i) make it an integer and give it the value of 0, then compare that variable with the array&#8217;s length property by setting it less then the array.length property of the array class, and finally increase the variable by one by using the ++ method of AS3.</p>
<p>inside the loop we add the button functionality by assessing the button through the arrays index by using our  loop variable to access it like so &#8220;btnArray[i]&#8221;,  </p>
<p>and if you use MovieClips for your buttons 2 little bits of code to make them work like true buttons the buttonMode and the mouseChildren property’s of the MovieClip class they both get a Boolean value so there really easy to set.</p>
<p>for (var i: int = 0; i&lt; btnArray.length; i++){<br />
btnArray[i].addEventListener(MouseEvent.CLICK, onMouseClick);<br />
btnArray[i].addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);<br />
btnArray[i].addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);<br />
btnArray[i].buttonMode = true;<br />
btnArray[i].mouseChildren = true;<br />
}</p>
<p>now add your functionality to your functions if the buttons are going to do totally different things the use if and else if statements to assign the functionality if they are for navigation to a url then use the navigateToUrl property of the flash.net class and if it is for navigation in the flash file then go back to your flash file and at the beginning of each section put a frame label with the same name as the button that will navigate to that section then use the event.target.name property to go there like so;</p>
<p>function onMouseClick (event:MouseEvent):void {<br />
this.gotoAndStop(home);<br />
navigateToUrl(new URLRequest(http://flashthusiast.com))<br />
}</p>
<p>function onMouseOver (event:MouseEvent):void {<br />
event.target.gotoAndPlay(over)<br />
}</p>
<p>function onMouseOut (event:MouseEvent):void {<br />
event.target.gotoAndPlay(out)<br />
}</p>
<p>I hope that was clear enough for the smart ones lol any how the complete code is a lot more clean and short the writing ten functions and ten event listeners here it is </p>
<p>var btnArray:Array = new Array(home, aboutUs, contactUs);</p>
<p>function onMouseClick (event:MouseEvent):void {<br />
this.gotoAndStop(home);<br />
navigateToUrl(new URLRequest(&#8221;http://flashthusiast.com&#8221;))<br />
}</p>
<p>function onMouseOver (event:MouseEvent):void {<br />
event.target.gotoAndPlay(over)<br />
}</p>
<p>function onMouseOut (event:MouseEvent):void {<br />
event.target.gotoAndPlay(out)<br />
}</p>
<p>for (var i: int = 0; i&lt; btnArray.length; i++){<br />
btnArray[i].addEventListener(MouseEvent.CLICK, onMouseClick);<br />
btnArray[i].addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);<br />
btnArray[i].addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);<br />
btnArray[i].buttonMode = true;<br />
btnArray[i].mouseChildren = true;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laura G</title>
		<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-437</link>
		<dc:creator>Laura G</dc:creator>
		<pubDate>Thu, 14 Aug 2008 02:38:08 +0000</pubDate>
		<guid>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-437</guid>
		<description>Hi Jen, I tried using your script for my button:

stop();
english.addEventListener(MouseEvent.MOUSE_DOWN);
function mouseDownHandler(event:MouseEvent):void 
{gotoAndStop(71);}

And I get: syntax error: extra characters found after end of program - which refers specifically to line of script starting with "english"  - what am I doing wrong??</description>
		<content:encoded><![CDATA[<p>Hi Jen, I tried using your script for my button:</p>
<p>stop();<br />
english.addEventListener(MouseEvent.MOUSE_DOWN);<br />
function mouseDownHandler(event:MouseEvent):void<br />
{gotoAndStop(71);}</p>
<p>And I get: syntax error: extra characters found after end of program - which refers specifically to line of script starting with &#8220;english&#8221;  - what am I doing wrong??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: josesenra</title>
		<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-395</link>
		<dc:creator>josesenra</dc:creator>
		<pubDate>Wed, 30 Jul 2008 00:34:07 +0000</pubDate>
		<guid>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-395</guid>
		<description>hi Josh.. can you be more specific as what you mean by going to another page???</description>
		<content:encoded><![CDATA[<p>hi Josh.. can you be more specific as what you mean by going to another page???</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: josesenra</title>
		<link>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-394</link>
		<dc:creator>josesenra</dc:creator>
		<pubDate>Wed, 30 Jul 2008 00:32:16 +0000</pubDate>
		<guid>http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/#comment-394</guid>
		<description>hi Kohaku

maybe you should try this:

1 - the "loop" animation goes into a separate movieclip running on frame one (must have a stop there)

2 - place a button in frame one and write the following code on the frame's actions panel (IMPORTANT!!! don't select the button to write the code.. select the frame)

function goAhead(e:MouseEvent):void {
  runningLoop_mc.stop();
  this.gotoAndStop(2);
}

clickedButton.addEventListener(MouseEvent.CLICK, goAhead);

well... what have we got here?? simple actually... you got a movieclip on frame 1 that's just there doing it's thing... you got a button wating to be clicked and when it gets cicked it sends the main timeline to frame 2 and stop there, after stoping the movieclip on frame 1.

good luck ;)</description>
		<content:encoded><![CDATA[<p>hi Kohaku</p>
<p>maybe you should try this:</p>
<p>1 - the &#8220;loop&#8221; animation goes into a separate movieclip running on frame one (must have a stop there)</p>
<p>2 - place a button in frame one and write the following code on the frame&#8217;s actions panel (IMPORTANT!!! don&#8217;t select the button to write the code.. select the frame)</p>
<p>function goAhead(e:MouseEvent):void {<br />
  runningLoop_mc.stop();<br />
  this.gotoAndStop(2);<br />
}</p>
<p>clickedButton.addEventListener(MouseEvent.CLICK, goAhead);</p>
<p>well&#8230; what have we got here?? simple actually&#8230; you got a movieclip on frame 1 that&#8217;s just there doing it&#8217;s thing&#8230; you got a button wating to be clicked and when it gets cicked it sends the main timeline to frame 2 and stop there, after stoping the movieclip on frame 1.</p>
<p>good luck ;)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
