# Reusing functions

**URL:** <https://forum.kirupa.com/t/reusing-functions/296243>\
**Category:** flash\
**Created:** [September 11, 2009, 2:34pm UTC](https://forum.kirupa.com/t/reusing-functions/296243 "2009-09-11T14:34:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyan](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@cyan](https://forum.kirupa.com/u/cyan)\
**Post date:** [September 11, 2009, 2:34pm UTC](https://forum.kirupa.com/t/reusing-functions/296243/1 "2009-09-11T14:34:03Z")

</div>

I was hoping someone could help me; I somehow am able to write bits of code but am still learning how to restructure code so that it is more efficient.

I have 15 buttons. Each one, when rolled over, should change the color of 2 movieclips underneath it (and when rolled out, should change back). I have the below code so far but I don’t think I have to re-write the functions each time. How do I “re-use” the function code (or, only write the function code once), but specify what movieclips the function should be applied to?

These are just 2 of the buttons of the 15:

```auto
menu_mc.invis1.addEventListener(MouseEvent.MOUSE_OVER, changeColor);
menu_mc.invis1.addEventListener(MouseEvent.MOUSE_OUT, changeBack);
function changeColor(event:MouseEvent):void
{
	var colorT:ColorTransform = new ColorTransform();
	colorT.color = 0xFFFFFF;
	menu_mc.threem.transform.colorTransform = colorT;
	
	var colorB:ColorTransform = new ColorTransform();
	colorB.color = 0x000000;
	menu_mc.threembox.transform.colorTransform = colorB;
}

function changeBack(event:MouseEvent):void
{
	var colorT:ColorTransform = new ColorTransform();
	colorT.color = 0x000000;
	menu_mc.threem.transform.colorTransform = colorT;
	
	var colorB:ColorTransform = new ColorTransform();
	colorB.color = 0xDFDFCE;
	menu_mc.threembox.transform.colorTransform = colorB;
}

menu_mc.invis2.addEventListener(MouseEvent.MOUSE_OVER, nbColor);
menu_mc.invis2.addEventListener(MouseEvent.MOUSE_OUT, nbBack);
function nbColor(event:MouseEvent):void
{
	var colorT:ColorTransform = new ColorTransform();
	colorT.color = 0xFFFFFF;
	menu_mc.nbType.transform.colorTransform = colorT;
	
	var colorB:ColorTransform = new ColorTransform();
	colorB.color = 0x000000;
	menu_mc.nbBox.transform.colorTransform = colorB;
}

function nbBack(event:MouseEvent):void
{
	var colorT:ColorTransform = new ColorTransform();
	colorT.color = 0x000000;
	menu_mc.nbType.transform.colorTransform = colorT;
	
	var colorB:ColorTransform = new ColorTransform();
	colorB.color = 0xDFDFCE;
	menu_mc.nbBox.transform.colorTransform = colorB;
}

```
