# \[FMX\] changing mouse events into function calls

**URL:** <https://forum.kirupa.com/t/fmx-changing-mouse-events-into-function-calls/14540>\
**Category:** flash\
**Created:** [February 27, 2003, 3:09pm UTC](https://forum.kirupa.com/t/fmx-changing-mouse-events-into-function-calls/14540 "2003-02-27T15:09:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcell](https://avatars.discourse-cdn.com/v4/letter/d/d26b3c/32.png) [@dcell](https://forum.kirupa.com/u/dcell)\
**Post date:** [February 27, 2003, 3:09pm UTC](https://forum.kirupa.com/t/fmx-changing-mouse-events-into-function-calls/14540/1 "2003-02-27T15:09:48Z")

</div>

Hiya,  
I’m a semi-newbie and could sure use some help.  
I have 4 invisible buttons that all do basically the same thing. I am learning how to consolidate my code using functions and I’m stuck on this one. I am using onRollover, on Rollout and onReleases in a frame actionscript. The code is below for 2 of the buttons.

mission\_btn.onRollOver =function(){  
mission\_mc.gotoAndPlay(“on”);  
}

mission\_btn.onRollOut=function(){  
mission\_mc.gotoAndPlay(“off”);  
}

mission\_btn.onRelease = function(){  
sectionLoader (“mission”)  
}

facilities\_btn.onRollOver =function(){  
facilities\_mc.gotoAndPlay(“on”);  
}

facilities\_btn.onRollOut=function(){  
facilities\_mc.gotoAndPlay(“off”);  
}

facilities\_btn.onRelease = function(){  
sectionLoader (“facilities”)  
}

is this enough info to help me change these events into a function?  
or should I just continue with this method for the other buttons?

Thanks for the insight!  
David

---

<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:** [February 27, 2003, 3:46pm UTC](https://forum.kirupa.com/t/fmx-changing-mouse-events-into-function-calls/14540/2 "2003-02-27T15:46:44Z")

</div>

they already are functions

:q:

---

<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:** [February 27, 2003, 4:03pm UTC](https://forum.kirupa.com/t/fmx-changing-mouse-events-into-function-calls/14540/3 "2003-02-27T16:03:59Z")

</div>

Ok,  
so I’m not the sharpest pencil in the box.  
Maybe me question no phrased good.

I guess I wanted to consolidate these button scripts.  
like only have 1 onRollover etc,  
and where mission\_btn is or facilities\_btn is, generate that name dynamically and assign it to the rollover or release etc.

Does that make anymore sense?

I’m really trying to explain…

thanks for the patience  
David

---

<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:** [February 27, 2003, 5:10pm UTC](https://forum.kirupa.com/t/fmx-changing-mouse-events-into-function-calls/14540/4 "2003-02-27T17:10:13Z")

</div>

```auto
btn = [mission_btn, facilities_btn];
for (var b in btn) {
	btn**.onRollOver = function () {
		this._parent[this._name.substring(0, this._name.lastIndexOf("_"))+"_mc"].gotoAndPlay("on");
	}
	btn**.onRollOut = function () {
		this._parent[this._name.substring(0, this._name.lastIndexOf("_"))+"_mc"].gotoAndPlay("off");
	}
	btn**.onRelease = function () {
		sectionLoader(this._name.substring(0, this._name.lastIndexOf("_")));
	}
}

```

that’s the only way i could get it to work :-\

[size=1]well … for five minutes of work it’s not that bad :P[/size]

---

<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:** [February 28, 2003, 2:04pm UTC](https://forum.kirupa.com/t/fmx-changing-mouse-events-into-function-calls/14540/5 "2003-02-28T14:04:13Z")

</div>

instead of using substring you could just start off with the prefix and then add \_btn or \_mc making it a little easier I think :q:  
the array being

sections = [“mission”, “facilities”];

etc?

---

<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:** [February 28, 2003, 2:08pm UTC](https://forum.kirupa.com/t/fmx-changing-mouse-events-into-function-calls/14540/6 "2003-02-28T14:08:02Z")

</div>

hmm … good point =)

---

<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:** [February 28, 2003, 4:02pm UTC](https://forum.kirupa.com/t/fmx-changing-mouse-events-into-function-calls/14540/7 "2003-02-28T16:02:28Z")

</div>

> **senocular**  
> [size=1]redraw(“lostinbeta”);[/size]

**kax**  
[size=1]erase(“lostinbeta”);[/size]  
😛 😛 😛

---

<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:** [February 28, 2003, 4:04pm UTC](https://forum.kirupa.com/t/fmx-changing-mouse-events-into-function-calls/14540/8 "2003-02-28T16:04:52Z")

</div>

yeah … i saw it a few minutes ago 😛

seems like he won’t let me erase **lostinbeta** :-\
