# Mc buttons need code to navigate using them

**URL:** <https://forum.kirupa.com/t/mc-buttons-need-code-to-navigate-using-them/262738>\
**Category:** Uncategorized\
**Created:** [June 9, 2008, 3:21pm UTC](https://forum.kirupa.com/t/mc-buttons-need-code-to-navigate-using-them/262738 "2008-06-09T15:21:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrdoodle](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@mrdoodle](https://forum.kirupa.com/u/mrdoodle)\
**Post date:** [June 9, 2008, 3:21pm UTC](https://forum.kirupa.com/t/mc-buttons-need-code-to-navigate-using-them/262738/1 "2008-06-09T15:21:25Z")

</div>

Hi,

I have three movie clips that I am using as buttons.

Their instances in the movie are Espanol\_btn, Francais\_btn and Deutsch\_btn.

I have added script to control the rollover and press/release states of the buttons, and now need to get the script to recognise which of the three buttons was pressed, store that result in the variable called [COLOR=Blue]lang [COLOR=Black](The posibilities are Espanol, Francais or Deutsch), and depending on what the variable [COLOR=Blue]land [/COLOR]is, do different things. The script is below.

```
ActionScript Code:
[LEFT][COLOR=#0000FF]import[/COLOR] mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]Tween[/COLOR];

```

[COLOR=#0000FF]import[/COLOR] mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].\*;  
[COLOR=#000000] **var** [/COLOR] lang:[COLOR=#0000FF]String[/COLOR];  
[COLOR=#000000] **var** [/COLOR] year:[COLOR=#0000FF]Number[/COLOR] =[COLOR=#000080]0[/COLOR];  
[COLOR=#000000] **var** [/COLOR] unit:[COLOR=#0000FF]Number[/COLOR] =[COLOR=#000080]0[/COLOR];  
[COLOR=#000000] **var** [/COLOR] section:[COLOR=#0000FF]Number[/COLOR] =[COLOR=#000080]0[/COLOR];

[COLOR=#808080]_//===============================LOGO ANIMATES ONSTAGE=========================================_[/COLOR]  
[COLOR=#808080]_// move top logo into position_[/COLOR]  
[COLOR=#000000] **var** [/COLOR] yPosT:Tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]logoTop, [COLOR=#FF0000]"\_y"[/COLOR], Elastic.[COLOR=#000080]easeInOut[/COLOR], -[COLOR=#000080]38[/COLOR].[COLOR=#000080]5[/COLOR], -[COLOR=#000080]0[/COLOR].[COLOR=#000080]3[/COLOR], [COLOR=#000080]1[/COLOR].[COLOR=#000080]5[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];

[COLOR=#808080]_//=====================LANGUAGE BUTTONS - ROLLOVER ANIMATION FUNCTIONS=========================================_[/COLOR]  
[COLOR=#808080]_// function to grow lang\_btns on rollover_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] growCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_xscale[/COLOR] \< [COLOR=#000080]110[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_xscale[/COLOR] += [COLOR=#000080]5[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_yscale[/COLOR] += [COLOR=#000080]5[/COLOR]  
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]onEnterFrame[/COLOR] = [COLOR=#000000] **null** [/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
[COLOR=#808080]_// function to grow lang\_btns continuously on rollover_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] growOverTimeCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]onEnterFrame[/COLOR] = grow;  
[COLOR=#000000]}[/COLOR]  
[COLOR=#808080]_// function to shrink lang\_btns on rollout_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] shrinkCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_xscale[/COLOR] \> [COLOR=#000080]100[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_xscale[/COLOR] -= [COLOR=#000080]5[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_yscale[/COLOR] -= [COLOR=#000080]5[/COLOR]  
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]onEnterFrame[/COLOR] = [COLOR=#000000] **null** [/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
[COLOR=#808080]_// function to shrink lang\_btns incrementally on rollout_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] shrinkOverTimeCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]onEnterFrame[/COLOR] = shrink;  
[COLOR=#000000]}[/COLOR]

[COLOR=#808080]_//=====================LANGUAGE BUTTONS - RELEASE OUTSIDE FUNCTION=========================================_[/COLOR]  
[COLOR=#808080]\*// function to release lang\_btns & call shrink() function on onReleaseOutside \*[/COLOR]  
[COLOR=#000000] **function** [/COLOR] unpressOutsideCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_xscale[/COLOR] \> [COLOR=#000080]100[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_xscale[/COLOR] -= [COLOR=#000080]2[/COLOR].[COLOR=#000080]5[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_yscale[/COLOR] -= [COLOR=#000080]2[/COLOR].[COLOR=#000080]5[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_x[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_x[/COLOR] -[COLOR=#000080]5[/COLOR];  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_y[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_y[/COLOR] -[COLOR=#000080]5[/COLOR];  
[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]onEnterFrame[/COLOR] = [COLOR=#000000] **null** [/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]

[COLOR=#808080]_//=====================LANGUAGE BUTTONS - PRESS/RELEASE FUNCTIONS=========================================_[/COLOR]  
[COLOR=#808080]_// function to press lang\_btns onPress_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] depressCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_x[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_x[/COLOR] +[COLOR=#000080]5[/COLOR];  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_y[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_y[/COLOR] +[COLOR=#000080]5[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#808080]_// function to release lang\_btns onRelease_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] unpressCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_x[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_x[/COLOR] -[COLOR=#000080]5[/COLOR];  
[COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_y[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]\_y[/COLOR] -[COLOR=#000080]5[/COLOR];  
[COLOR=#808080]_// run ‘navigate’ function_[/COLOR]  
navigateCOLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]

[COLOR=#808080]_//=====================LANGUAGE BUTTONS - NAVIGATION SCRIPT========================================_[/COLOR]  
[COLOR=#808080]_// function to navigate to next level of buttons_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] navigateCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]lang == [COLOR=#FF0000]“Espanol”[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#0000FF]gotoAndStop[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]lang == [COLOR=#FF0000]“Francais”[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#0000FF]gotoAndStop[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]lang == [COLOR=#FF0000]“Deutsch”[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#0000FF]gotoAndStop[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]

[COLOR=#808080]_//=====================YEAR BUTTONS - FUNCTION CALLS TO OPERATE BUTTONS=========================================_[/COLOR]  
[COLOR=#808080]_// Make functions play on rollover/rollout/press/release of Unit buttons_[/COLOR]  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Espanol\_btn[/COLOR].[COLOR=#0000FF]onRollOver[/COLOR] = growOverTime;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Espanol\_btn[/COLOR].[COLOR=#0000FF]onRollOut[/COLOR] = shrinkOverTime;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Espanol\_btn[/COLOR].[COLOR=#0000FF]onPress[/COLOR] = depress;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Espanol\_btn[/COLOR].[COLOR=#0000FF]onRelease[/COLOR] [COLOR=#000000]([/COLOR]lang = [COLOR=#FF0000]“Espanol”[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Espanol\_btn[/COLOR].[COLOR=#0000FF]onRelease[/COLOR] = unpress;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Espanol\_btn[/COLOR].[COLOR=#0000FF]onReleaseOutside[/COLOR] = unpressOutside;

[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Francais\_btn[/COLOR].[COLOR=#0000FF]onRollOver[/COLOR] = growOverTime;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Francais\_btn[/COLOR].[COLOR=#0000FF]onRollOut[/COLOR] = shrinkOverTime;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Francais\_btn[/COLOR].[COLOR=#0000FF]onPress[/COLOR] = depress;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Francais\_btn[/COLOR].[COLOR=#0000FF]onRelease[/COLOR] = unpress;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Francais\_btn[/COLOR].[COLOR=#0000FF]onReleaseOutside[/COLOR] = unpressOutside;

[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Deutsch\_btn[/COLOR].[COLOR=#0000FF]onRollOver[/COLOR] = growOverTime;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Deutsch\_btn[/COLOR].[COLOR=#0000FF]onRollOut[/COLOR] = shrinkOverTime;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Deutsch\_btn[/COLOR].[COLOR=#0000FF]onPress[/COLOR] = depress;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Deutsch\_btn[/COLOR].[COLOR=#0000FF]onRelease[/COLOR] = unpress;  
[COLOR=#0000FF]\_root[/COLOR].[COLOR=#000080]Deutsch\_btn[/COLOR].[COLOR=#0000FF]onReleaseOutside[/COLOR] = unpressOutside;

[COLOR=#0000FF]stop[/COLOR]COLOR=#000000[/COLOR];  
[/LEFT]

Here is the link to the movie to give you an idea if what I’m trying to achieve  
[/COLOR][/COLOR]  
[http://www.mrdoodle.com/languagenut/](http://www.mrdoodle.com/languagenut/)  
[COLOR=Blue][COLOR=Black]  
Hopefully to some code wizard out there it will be decipherable as to what’s going on and how I can get this to work.

I thank you in advance for any help given.

Peace :party:[/COLOR][/COLOR]

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 9, 2008, 3:33pm UTC](https://forum.kirupa.com/t/mc-buttons-need-code-to-navigate-using-them/262738/2 "2008-06-09T15:33:15Z")

</div>

search the forums it aint rocket science

ie this is so easy and comes up so often you would struggle not to find…

say a very simular topic posted today for example

---

<div class="post-metadata">

**Author:** ![mrdoodle](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@mrdoodle](https://forum.kirupa.com/u/mrdoodle)\
**Post date:** [June 9, 2008, 4:25pm UTC](https://forum.kirupa.com/t/mc-buttons-need-code-to-navigate-using-them/262738/3 "2008-06-09T16:25:20Z")

</div>

I have been searching forums for the last three hours. Perhaps you think it’s not rocket science, but action script is not really my thing, and I was just trying to get a pointer in the right direction. i.e where do I define that the variable _lang_ is to be Espanol if the Espanol\_btn has been released.  
The code I have at present is:

```auto

_root.Espanol_btn.onRelease (lang = "Espanol");

```

is this correct?

I know you probably think I’m stupid, but I just cannot seem to get this working. If you just want to direct me back to a forum could you at least give me an idea of what I should try typing in when I search for te appropriate post.

Thanks

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 9, 2008, 4:54pm UTC](https://forum.kirupa.com/t/mc-buttons-need-code-to-navigate-using-them/262738/4 "2008-06-09T16:54:51Z")

</div>

Try this:  
\_root.Espanol\_btn.onRelease = function() {  
lang = “Espanol”;  
unpress;  
}

Change the other buttons too:

\_root.Francais\_btn.onRelease = function() {  
lang = “Francais”;  
unpress;  
}  
\_root.Deutsch\_btn.onRelease = function() {  
lang = “Deutsch”;  
unpress;  
}

---

<div class="post-metadata">

**Author:** ![mrdoodle](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@mrdoodle](https://forum.kirupa.com/u/mrdoodle)\
**Post date:** [June 9, 2008, 5:27pm UTC](https://forum.kirupa.com/t/mc-buttons-need-code-to-navigate-using-them/262738/5 "2008-06-09T17:27:40Z")

</div>

thanks glosrfc,

I have triend this already, but it doesn’t work.  
It doesn’t seem to run the function unpress() when i do this. Instead of returning the button to the priginal position on Release it leaves it where it is.

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 9, 2008, 6:05pm UTC](https://forum.kirupa.com/t/mc-buttons-need-code-to-navigate-using-them/262738/6 "2008-06-09T18:05:32Z")

</div>

```auto
function unpress() {
	if (this == Deutsch_btn) {
		lang = "Deutsch";
	} else if (this == Espanol_btn) {
		lang = "Espanol";
	} else {
		lang = "Francais";
	}
	trace (lang);
	this._x = this._x - 5;
	this._y = this._y - 5;
	// run 'navigate' function
	navigate();
}

```

---

<div class="post-metadata">

**Author:** ![mrdoodle](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@mrdoodle](https://forum.kirupa.com/u/mrdoodle)\
**Post date:** [June 9, 2008, 7:20pm UTC](https://forum.kirupa.com/t/mc-buttons-need-code-to-navigate-using-them/262738/7 "2008-06-09T19:20:41Z")

</div>

Thanks so much for your help glosrfc. Very much appreciated.

I had actually got it working in the end myself. Only after many hours of experimentation though. However the code you suggested is alot more concise than what I had come up with, so have swapped it over.

It’s really good to know how to do the _if else_ thing now. I know it’s good to learn things and work stuff out oneself, but to be shown an example relevant to the movie is often invaluable. And I think is just as good a way to learn. I mean I will never forget how to do this again now.

and just a small observation…  
The sharing of knowledge is a beautiful thing. I don’t see the point when people answer posts - obviously knowing how to solve or at least assist with the problem - and then just tell the poster that it’s easy and they should go and search the answer out for themselves. It defeats the whole point of having a forum. Are they not there for people to get help and assistance with their questions and problems?

Thanks again for you help.

Mike
