How to simplify this function ?
Hello, I am trying to add fish of different colors on the canvas by triggering a function on a button click, each color has its own movieclip (in this case, fishred and fishblue)).
The thing is that the function are all the same but only the var for color changes, and I have to make multiple colors.
Is there a way to change it into a single function that will choose which movieclip will be added when clicking on a specific button ?
var red:fishred = new fishred();
var blue:fishblue = new fishblue();
function addRed(e:Event) {
if (red.stage) {
red.parent.removeChild(red);
} else {
red.x = Math.random() * 550;
red.y = Math.random() * 400;
red.dx = Math.round(Math.random() * 550);
red.dy = Math.round(Math.random() * 400);
addChild(red);
}
function addBlue(e:Event) {
if (blue.stage) {
blue.parent.removeChild(red);
} else {
blue.x = Math.random() * 550;
blue.y = Math.random() * 400;
blue.dx = Math.round(Math.random() * 550);
blue.dy = Math.round(Math.random() * 400);
addChild(blue);
}
}
