# To toggle

**URL:** <https://forum.kirupa.com/t/to-toggle/2842>\
**Category:** Uncategorized\
**Created:** [March 29, 2002, 8:13pm UTC](https://forum.kirupa.com/t/to-toggle/2842 "2002-03-29T20:13:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2002, 8:13pm UTC](https://forum.kirupa.com/t/to-toggle/2842/1 "2002-03-29T20:13:31Z")

</div>

hello there,\r\ri have this situation here\ronstage: a button and a movieclip\r\rthe button says:\r\ron (press) {\r\_ \_ \_ \_ SAM = not SAM;\r}\r\rand the movieclip says:\r\ronClipEvent (enterFrame) {\r\_ \_ \_ \_ if (SAM) {\r\_ \_ \_ \_ this._rotation+=20;\r_ \_ \_ \_ } else {\r\_ \_ \_ \_ this._rotation =180;\r_ \_ \_ \_ }\r}\r\rbut it doesn’t work, the toggling…\r\rwhat gives? \r\rmeesje

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2002, 12:14am UTC](https://forum.kirupa.com/t/to-toggle/2842/2 "2002-03-30T00:14:28Z")

</div>

Try

```auto
 on (press) {SAM=!SAM}

```

pom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2002, 7:45am UTC](https://forum.kirupa.com/t/to-toggle/2842/3 "2002-03-30T07:45:11Z")

</div>

hi pom, thanks for your reply, alas it’s still no go… ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2002, 10:29am UTC](https://forum.kirupa.com/t/to-toggle/2842/4 "2002-03-30T10:29:36Z")

</div>

i know i can solve this by…\r\rnot adding a script TO the MC\rbut make 2 keyframes IN the MC\rand make the button tell targets to goplay some frame\r\rbut i really would like to know why this script\r(which seems to me a more elegant solution)\rdoesn’t work…\r\rmeesje

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2002, 10:50am UTC](https://forum.kirupa.com/t/to-toggle/2842/5 "2002-03-30T10:50:42Z")

</div>

I know : if (\_root.SAM)…\rSAM is located in \_root., not in your movie clip. Does that make sense to you ?\r\rpom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2002, 11:11am UTC](https://forum.kirupa.com/t/to-toggle/2842/6 "2002-03-30T11:11:39Z")

</div>

another problem might be that you never toggle SAM (at least it’s not toggled in the code you provide).\rif you want the button to toggle, do this:\ron(release){\rif(!sam){\rsam=true;\r} else {\rsam=false;\r}\r}\rif you want the button to toggle one way and the movie to toggle the other…\rbutton:\rif(!sam){\rsam=true;\r}\r}\rmovie:\ronClipEvent(enterFrame){\rif(\_root.sam){\r\_rotation+=20;\r\_root.sam=false;\r} else {\r\_rotation=180\r}\r}\r\rif i understand your situation correctly those examples should work for you.\r:) \rjeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2002, 11:24am UTC](https://forum.kirupa.com/t/to-toggle/2842/7 "2002-03-30T11:24:14Z")

</div>

YEEHA! again happy happy here ))\r\r(\_root.SAM) worked\ri never knew one had to write the path of the variable\r\ras for the toggler\r\ron (press) {\r&nbsp &nbsp &nbsp &nbsp SAM = not SAM;\r}
