# Button with switching functions

**URL:** <https://forum.kirupa.com/t/button-with-switching-functions/318405>\
**Category:** flash\
**Created:** [January 19, 2011, 9:11am UTC](https://forum.kirupa.com/t/button-with-switching-functions/318405 "2011-01-19T09:11:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![funtasma](https://avatars.discourse-cdn.com/v4/letter/f/7ab992/32.png) [@funtasma](https://forum.kirupa.com/u/funtasma)\
**Post date:** [January 19, 2011, 9:11am UTC](https://forum.kirupa.com/t/button-with-switching-functions/318405/1 "2011-01-19T09:11:21Z")

</div>

Hello dear forum,  
I have a problem. I spend hours in google without success, so hopefully you can help me.

I’m working on a gallery. In the “Picture.as” class I load the picture and there is also a function with an animation to make the picture disappear. In the main class the pictures are put to stage by putting instances of the Picture class.

All I need to do now is to adress the function in the according Picture instance. It works fine as long as I use the direct link, but when I use a variable it does not work anymore.

Here’s my code:

```auto
 
public class.... // just for the example
{
   private var picture1:Picture;
   private var picture2:Picture;
   private var picture3:Picture;
 
   private var Nr:Number = 1;
   private var myLink:String = "picture"+Nr+".pictureDisappear"
 
   private function.... //just a function in the class
{
   myBtn = new btnDisappear();
   addChild(myBtn);
 
   picture3 = new Picture(movClip3);
   scene.addChild(picture3);
 
   picture2 = new Picture(movClip2);
   scene.addChild(picture2);
   
   picture1 = new Picture(movClip1);
   scene.addChild(picture1);
  
   myBtn.addEventListener(MouseEvent.CLICK, myFunction);
}
 
private function my Function(event:MouseEvent):void
{
   myLink;
   Nr = Nr + 1;
}
}

```

This one does not work. Somehow Flash does not work with the variable as a command.

When I instead use the direct command it works fine:

```auto
 
private function my Function(event:MouseEvent):void
{
   picture1.pictureDisappear;
}

```

But the second version does not give me any flexibility, which I need, since in the next step instance picture2 needs to be adressed and diappear, when the button is pressed again…and so forth.

I would like to use this gallery several times and with different amounts of pictures, like 43, 68, or 120 pictures. That’s why I need this automated way of switching and adressing the next instance. That’s why listing a hundred twenty or more individual event handlers is not really a solution for me.

Thanks in advance!

-Benjamin-

P.S.: I wrote the code above just with snippets of my original class to make it not longer then neccessary. I hope I did not make any more mistakes while typing it in here. 🙂
