How can I combine the following functions and still pass a different string to the buildUI(); function?
I have two functions that do the same thing only at the end they both call a function and pass a String value to the function. This string value is the only thing different.
Below is are my eventlisteners and functions as they are now:
female_start.addEventListener(MouseEvent.MOUSE_DOWN, startFemale);
male_start.addEventListener(MouseEvent.MOUSE_DOWN, startMale);
//FUNCTIONS THAT DO THE SAME THING AND BOTH CALL buildUI BUT PASS A DIFFERENT STRING.
function startMale(event:MouseEvent):void
{
female_start.removeEventListener(MouseEvent.MOUSE_DOWN, startFemale);
male_start.removeEventListener(MouseEvent.MOUSE_DOWN, startMale);
var removeMale = new Tween(male_start, "x", Strong.easeInOut, 540,1080, 2, true);
var removeFemale = new Tween(female_start, "x", Strong.easeInOut, 0,-540, 2, true);
//THIS IS THE ONLY DIFFERENCE BETWEEN THE TWO FUNCTIONS
buildUI("Male");
}
function startFemale(event:MouseEvent):void
{
female_start.removeEventListener(MouseEvent.MOUSE_DOWN, startFemale);
male_start.removeEventListener(MouseEvent.MOUSE_DOWN, startMale);
var removeMale = new Tween(male_start, "x", Strong.easeInOut, 540,1080, 2, true);
var removeFemale = new Tween(female_start, "x", Strong.easeInOut, 0,-540, 2, true);
//THIS IS THE ONLY DIFFERENCE BETWEEN THE TWO FUNCTIONS
buildUI("Female");
}
1 Answer