<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: How to Build a Basic Toggle Button (AS2)</title>
	<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2</link>
	<description>Luck is the residue of good design.</description>
	<pubDate>Wed, 19 Nov 2008 04:15:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-101371</link>
		<pubDate>Thu, 15 Nov 2007 01:34:27 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-101371</guid>
					<description>Max,

Thanks!</description>
		<content:encoded><![CDATA[<p>Max,</p>
<p>Thanks!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Max</title>
		<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-98728</link>
		<pubDate>Thu, 08 Nov 2007 23:06:32 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-98728</guid>
					<description>Great tutorial. Easy to understand and good use of grammar (which is hard to find these days!)

cheers</description>
		<content:encoded><![CDATA[<p>Great tutorial. Easy to understand and good use of grammar (which is hard to find these days!)</p>
<p>cheers
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-87248</link>
		<pubDate>Mon, 01 Oct 2007 16:54:46 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-87248</guid>
					<description>Trey,

Based on your description, it sounds like you have at least three buttons: Prev, Next, and Pause/Play. If your Prev and Next buttons cause the main timeline to resume &amp;#8212; effectively the same as untoggling the Pause/Play button &amp;#8212; then it makes sense that your toggle will get out of sync. You'll need to program your Prev and Next buttons not only to direct the timeline, but also to communicate with the Pause/Play button.

Since you're not using &lt;code&gt;on()&lt;/code&gt; for Pause/Play (that is, &lt;code&gt;btnToggle&lt;/code&gt;), I encourage you to do the same for Prev and Next.  By keeping all your code in a single layer, it makes your ActionScript easier to find and maintain layer (see my &quot;&lt;a href=&quot;http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Museum Pieces&lt;/a&gt;&quot; article). It looks like clicking the Next button (for example) needs to continue doing what it currently does, and in addition, set &lt;code&gt;btnToggle&lt;/code&gt;'s &lt;code&gt;toggled&lt;/code&gt; property to &lt;code&gt;false&lt;/code&gt; and send it to frame 1 of its own timeline:

&lt;pre&gt;&lt;code&gt;btnNext.onRelease = function():Void {
  this._parent.gotoAndPlay(386);
  btnToggle.toggled = false;
  btnToggle.gotoAndStop(1);
}&lt;/code&gt;&lt;/pre&gt;

Note the expression &lt;code&gt;this._parent&lt;/code&gt; ... you may have to adjust that path to suit, but the expression as shown assumes that your &quot;mainmovie&quot; target is the immediate parent of the Next button and that your Next button has the instance name &lt;code&gt;btnNext&lt;/code&gt;.  I'm not sure what &quot;mainmovie&quot; refers to, but you no longer need the dated &lt;code&gt;tellTarget()&lt;/code&gt; function to instruct other objects.  It's often easier on the eye to simply use the same sort of dot notation to path to your objects as you're already doing elsewhere in the code.</description>
		<content:encoded><![CDATA[<p>Trey,</p>
<p>Based on your description, it sounds like you have at least three buttons: Prev, Next, and Pause/Play. If your Prev and Next buttons cause the main timeline to resume &mdash; effectively the same as untoggling the Pause/Play button &mdash; then it makes sense that your toggle will get out of sync. You&#8217;ll need to program your Prev and Next buttons not only to direct the timeline, but also to communicate with the Pause/Play button.</p>
<p>Since you&#8217;re not using <code>on()</code> for Pause/Play (that is, <code>btnToggle</code>), I encourage you to do the same for Prev and Next.  By keeping all your code in a single layer, it makes your ActionScript easier to find and maintain layer (see my &#8220;<a href="http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent" target="_blank" rel="nofollow">Museum Pieces</a>&#8221; article). It looks like clicking the Next button (for example) needs to continue doing what it currently does, and in addition, set <code>btnToggle</code>&#8217;s <code>toggled</code> property to <code>false</code> and send it to frame 1 of its own timeline:</p>
<pre><code>btnNext.onRelease = function():Void {
  this._parent.gotoAndPlay(386);
  btnToggle.toggled = false;
  btnToggle.gotoAndStop(1);
}</code></pre>
<p>Note the expression <code>this._parent</code> &#8230; you may have to adjust that path to suit, but the expression as shown assumes that your &#8220;mainmovie&#8221; target is the immediate parent of the Next button and that your Next button has the instance name <code>btnNext</code>.  I&#8217;m not sure what &#8220;mainmovie&#8221; refers to, but you no longer need the dated <code>tellTarget()</code> function to instruct other objects.  It&#8217;s often easier on the eye to simply use the same sort of dot notation to path to your objects as you&#8217;re already doing elsewhere in the code.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Trey</title>
		<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-86396</link>
		<pubDate>Fri, 28 Sep 2007 07:53:38 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-86396</guid>
					<description>i was wrong. the play state of the button stops working after the 1st time. to restart the movie i have to click the previous/next buttons. i can then stop the movie again with the play/pause button. but i can not use it to play the movie after i stop it.

trey</description>
		<content:encoded><![CDATA[<p>i was wrong. the play state of the button stops working after the 1st time. to restart the movie i have to click the previous/next buttons. i can then stop the movie again with the play/pause button. but i can not use it to play the movie after i stop it.</p>
<p>trey
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Trey</title>
		<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-86394</link>
		<pubDate>Fri, 28 Sep 2007 07:44:33 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-86394</guid>
					<description>i have a slide show movie made using the timeline. i put a previous play/pause and next button in the movie. I use your method and it works fine. there is an unexpected behavior that happens when the movie is paused/stopped. if the previous or next button is clicked while the movie is stopped the movie will begin to play again but the play/pause button will not toggle and the movie goes to the correct frame number. if i click play/pause again it works fine. the previous/next buttons work fine. oh yeah. the play/pause button is on the main timeline. the previous/next buttons are on the movie symbol. any thoughts? my actionscript is below.

btnToggle.stop();
btnToggle.toggled = false;

btnToggle.onRelease = function():Void {
this.toggled = !this.toggled; // this flip-flips the Boolean
  if (this.toggled) {
    this.gotoAndStop(2);
   	tellTarget (&quot;mainmovie&quot;) {
		stop();
	}
	}
	else {
    this.gotoAndStop(1);
   	tellTarget (&quot;mainmovie&quot;) {
		start();
	}
	}
}


__________________________________
example previous next actionscript:
on (release) {
this.gotoAndPlay(386);
}

thanks for any and all help.
trey</description>
		<content:encoded><![CDATA[<p>i have a slide show movie made using the timeline. i put a previous play/pause and next button in the movie. I use your method and it works fine. there is an unexpected behavior that happens when the movie is paused/stopped. if the previous or next button is clicked while the movie is stopped the movie will begin to play again but the play/pause button will not toggle and the movie goes to the correct frame number. if i click play/pause again it works fine. the previous/next buttons work fine. oh yeah. the play/pause button is on the main timeline. the previous/next buttons are on the movie symbol. any thoughts? my actionscript is below.</p>
<p>btnToggle.stop();<br />
btnToggle.toggled = false;</p>
<p>btnToggle.onRelease = function():Void {<br />
this.toggled = !this.toggled; // this flip-flips the Boolean<br />
  if (this.toggled) {<br />
    this.gotoAndStop(2);<br />
   	tellTarget (&#8221;mainmovie&#8221;) {<br />
		stop();<br />
	}<br />
	}<br />
	else {<br />
    this.gotoAndStop(1);<br />
   	tellTarget (&#8221;mainmovie&#8221;) {<br />
		start();<br />
	}<br />
	}<br />
}</p>
<p>__________________________________<br />
example previous next actionscript:<br />
on (release) {<br />
this.gotoAndPlay(386);<br />
}</p>
<p>thanks for any and all help.<br />
trey
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-78193</link>
		<pubDate>Mon, 03 Sep 2007 12:47:03 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-78193</guid>
					<description>nab,

Terrific!</description>
		<content:encoded><![CDATA[<p>nab,</p>
<p>Terrific!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: nab</title>
		<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-78092</link>
		<pubDate>Mon, 03 Sep 2007 04:39:50 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-78092</guid>
					<description>thnx a lot mate i already accomplished it :D</description>
		<content:encoded><![CDATA[<p>thnx a lot mate i already accomplished it <img src='http://www.quip.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-76381</link>
		<pubDate>Tue, 28 Aug 2007 15:31:44 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-76381</guid>
					<description>nab,

Your question encompasses quite a few sub-questions, which leads to a general principle on approaching any goal in Flash (and programming in general):  big things are made up of lots of little things.  This maxim has helped me through so many projects over the years, I've lost count.  The basic idea &amp;#8212; and it's not revolutionary, just surprisingly hard to remember sometimes &amp;#8212; is simply to break down massive goals into smaller ones until the small ones make sense.  As you approach each step, master that step in isolation, then gather your acquired knowledge toward the main destination.

In this case, I would start with the gallery at lukamaras.com.  Get that working solidly.  Next, isolate the portion of that tutorial that responds to user clicks.  Whatever handles the mouse clicks (an &lt;code&gt;onRelease&lt;/code&gt; handler, presumably) can be instructed to perform other things as well.  Whatever function is associated with advancing the gallery itself (or changing categories, or whatever) can make additional function calls &amp;#8212; and those additional calls will be up to you.

This is where I'd recommend you begin the &quot;isolation&quot; portion of your endeavor.  Save your work and start a new FLA altogether.  In the new FLA, you'll create the MP3 player on its own, in isolation, away from the code of the gallery itself.  Work your way toward playing a series of play lists.  You might start with &lt;code&gt;Array&lt;/code&gt; instances at first, then progress toward XML.  There's nothing especially magical about XML ... it's just a way to separate your list of songs from inside the SWF to the outside.  One of the benefits is an easier update (you can change the song lists without recompiling the SWF) and one of the cons is complexity (you'll have to instantiate the &lt;code&gt;XML&lt;/code&gt; class and handle loading the document, responding to its loading, etc.).

Any time a particular path on your trail gets too overgrown with complexity, break down your goal again.  Maybe it's time to create yet another FLA that deals with XML only.  Practice creating XML objects and loading documents until you nail it.  Eventually, you'll build up to using XML in cahoots with the &lt;code&gt;Sound&lt;/code&gt; class, which means eventually you'll have an MP3 player that depends successfully on external play lists.  Form there, you'll be able to load new XML documents as desired, to play new songs, and that will be triggered by a function or method you've written.  That function or method can be triggered from anywhere, including the gallery created from the lukamaras.com tutorial.</description>
		<content:encoded><![CDATA[<p>nab,</p>
<p>Your question encompasses quite a few sub-questions, which leads to a general principle on approaching any goal in Flash (and programming in general):  big things are made up of lots of little things.  This maxim has helped me through so many projects over the years, I&#8217;ve lost count.  The basic idea &mdash; and it&#8217;s not revolutionary, just surprisingly hard to remember sometimes &mdash; is simply to break down massive goals into smaller ones until the small ones make sense.  As you approach each step, master that step in isolation, then gather your acquired knowledge toward the main destination.</p>
<p>In this case, I would start with the gallery at lukamaras.com.  Get that working solidly.  Next, isolate the portion of that tutorial that responds to user clicks.  Whatever handles the mouse clicks (an <code>onRelease</code> handler, presumably) can be instructed to perform other things as well.  Whatever function is associated with advancing the gallery itself (or changing categories, or whatever) can make additional function calls &mdash; and those additional calls will be up to you.</p>
<p>This is where I&#8217;d recommend you begin the &#8220;isolation&#8221; portion of your endeavor.  Save your work and start a new FLA altogether.  In the new FLA, you&#8217;ll create the MP3 player on its own, in isolation, away from the code of the gallery itself.  Work your way toward playing a series of play lists.  You might start with <code>Array</code> instances at first, then progress toward XML.  There&#8217;s nothing especially magical about XML &#8230; it&#8217;s just a way to separate your list of songs from inside the SWF to the outside.  One of the benefits is an easier update (you can change the song lists without recompiling the SWF) and one of the cons is complexity (you&#8217;ll have to instantiate the <code>XML</code> class and handle loading the document, responding to its loading, etc.).</p>
<p>Any time a particular path on your trail gets too overgrown with complexity, break down your goal again.  Maybe it&#8217;s time to create yet another FLA that deals with XML only.  Practice creating XML objects and loading documents until you nail it.  Eventually, you&#8217;ll build up to using XML in cahoots with the <code>Sound</code> class, which means eventually you&#8217;ll have an MP3 player that depends successfully on external play lists.  Form there, you&#8217;ll be able to load new XML documents as desired, to play new songs, and that will be triggered by a function or method you&#8217;ve written.  That function or method can be triggered from anywhere, including the gallery created from the lukamaras.com tutorial.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: nab</title>
		<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-75460</link>
		<pubDate>Sat, 25 Aug 2007 07:30:41 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-75460</guid>
					<description>hi david and guys
well i need some help here
i dont exactly know where to put it but here is my question 
there is a tutorial for a dynamic gallery on site i want to add a mp3 player to it which will also switch different play list as we click different categories on the menu 
any idea how to approach to it ?
http://www.lukamaras.com/tutorials/actionscript/ultimate-dynamic-image-gallery-2.html  how can i chnge the mp3 players play list based on xml when the user will chnge the categories in gallery  thanx  for help guys</description>
		<content:encoded><![CDATA[<p>hi david and guys<br />
well i need some help here<br />
i dont exactly know where to put it but here is my question<br />
there is a tutorial for a dynamic gallery on site i want to add a mp3 player to it which will also switch different play list as we click different categories on the menu<br />
any idea how to approach to it ?<br />
<a href='http://www.lukamaras.com/tutorials/actionscript/ultimate-dynamic-image-gallery-2.html' rel='nofollow'>http://www.lukamaras.com/tutorials/actionscript/ultimate-dynamic-image-gallery-2.html</a>  how can i chnge the mp3 players play list based on xml when the user will chnge the categories in gallery  thanx  for help guys
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: NSurveyor</title>
		<link>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-75403</link>
		<pubDate>Sat, 25 Aug 2007 02:16:58 +0000</pubDate>
		<guid>http://www.quip.net/blog/2007/flash/how-to-build-basic-toggle-as2#comment-75403</guid>
					<description>Haha yeah, it's been awhile. Strangely, I seem to take a few month break from Flash almost every year. Yesterday, I remembered about Flash and restarted my activity here, on the Adobe forums, and the Keyframer forum. Hopefully, I'll stop hibernating and be using Flash year round!</description>
		<content:encoded><![CDATA[<p>Haha yeah, it&#8217;s been awhile. Strangely, I seem to take a few month break from Flash almost every year. Yesterday, I remembered about Flash and restarted my activity here, on the Adobe forums, and the Keyframer forum. Hopefully, I&#8217;ll stop hibernating and be using Flash year round!
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
