I think you are saying you have four buttons, each with its
own instance name and event listener. Each listener calls the same
function. That being the case, you can reference the button name
that was clicked instead of passing a parameter.
For example:
I have four buttons on the screen called product1_btn,
profuct2_btn, etc.
I have four event listeners something like
product1_btn.addEventListener(MouseEvent.CLICK, clickFunction);
Now, there are two basic ways to approach this:
Method 1: You can change the reference to clickFunction to
four separate functions and write the functions as:
function prod1Click(event.MouseEvent):void{
productClick(1, "product1.jpg");
}
function prod2Click(event.MouseEvent):void{
productClick(2, "product2.jpg");
}
function productClick(myProduct:int, myImage:String):void{
// Do your thing here.
}
The second method would be to reference the name of the
button clicked in your function and use a conditional statement to
perform the action.
function productClick(event:MouseEvent):void{
var whosClicked:String = this.name;
trace(whosClicked); // Displays product1_btn, product2_btn,
etc.
}
There is a third, more advanced method you can use which is
to create a display object container and place all of your buttons
in the container. From there you can reference the index number of
the button clicked, then select your image from an array. If you
want to go that way, let me know and I'll get you a sample of the
code.