# Trying to streamline if/then function

**URL:** <https://forum.kirupa.com/t/trying-to-streamline-if-then-function/634648>\
**Category:** flash\
**Created:** [May 19, 2016, 5:58pm UTC](https://forum.kirupa.com/t/trying-to-streamline-if-then-function/634648 "2016-05-19T17:58:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![svenghoulieil](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/svenghoulieil/32/7633_2.png) [@svenghoulieil](https://forum.kirupa.com/u/svenghoulieil)\
**Post date:** [May 19, 2016, 5:58pm UTC](https://forum.kirupa.com/t/trying-to-streamline-if-then-function/634648/1 "2016-05-19T17:58:35Z")

</div>

I am creating a word search game and am using this conditional statement to determine if the letter has been selected, then add or subtract a value dependent on that. I wrote the following function that works, but seems a bit lengthy - any ideas on how to streamline this function?

thanks!

```auto
if(e.currentTarget.name=="a1" && MovieClip(e.currentTarget.bak).currentFrameLabel =="on")
		{
			wordCount=-1.1;
		}
	if(e.currentTarget.name=="a1" && MovieClip(e.currentTarget.bak).currentFrameLabel =="off")
		{
			wordCount=1.1;
		}

```

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [May 19, 2016, 9:12pm UTC](https://forum.kirupa.com/t/trying-to-streamline-if-then-function/634648/2 "2016-05-19T21:12:17Z")

</div>

Perhaps this, though the trade between memory and code length is one which I might not make.

```auto
if(e.currentTarget.name == "a1") {
    var s:String = MovieClip(e.currentTarget.bak).currentFrameLabel
    if(s == "on") wordCount = -1.1
    else if(s == "off") wordCount = 1.1
}

```

Don’t know how to format code…

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [May 20, 2016, 4:12am UTC](https://forum.kirupa.com/t/trying-to-streamline-if-then-function/634648/3 "2016-05-20T04:12:27Z")

</div>

```auto
const o:* = e.currentTarget
o.name == 'a1' && wordCount = o.bak['currentFrameLabel'] == 'on' ? -1.1 : 1.1

```

Not exactly equivalent if there are frames other than ‘on’ and ‘off’.

---

<div class="post-metadata">

**Author:** ![svenghoulieil](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/svenghoulieil/32/7633_2.png) [@svenghoulieil](https://forum.kirupa.com/u/svenghoulieil)\
**Post date:** [May 21, 2016, 1:28am UTC](https://forum.kirupa.com/t/trying-to-streamline-if-then-function/634648/4 "2016-05-21T01:28:04Z")

</div>

Thanks!
