Ok, your goal is to go to a certain frame, depending on what caused the MouseEvent
.
One way of doing this is to save what object corresponds to what frame.
Think of this like a telephone book. It associates a person with a number to be called.
To create such a "telephone book" in actionscript, you use a dictionary. First add all associations to it like so:
var object2frame:Dictionary = new Dictionary();
object2frame[play] = 2; // associate play with the number 2
object2frame[play2] = 3;
DISCLAIMER: I replaced your non English identifiers with English ones. You should always write your code in English. This makes it easier for people to read the code who do not know your language. Get used to it.
the second part of the solution is currentTarget
, a property of the Event
object that references the object that caused the Event
.
I hope you can see how this comes together now:
- If the function is called, first find out who caused it, that is,
what object was clicked.
- Knowing the source of the Event, use that information to look up the
frame that you should go to in the dictionary.
- Go to that frame.
Here's how the code could look like:
var object2frame:Dictionary = new Dictionary();
object2frame[play] = 2; // associate play with the number 2
object2frame[play2] = 3;
play.addEventListener(MouseEvent.CLICK, click);
play2.addEventListener(MouseEvent.CLICK, click);
function click(e:MouseEvent):void
{
gotoAndStop(object2frame[e.currentTarget]);
}
There are other solutions to this problem.