2 Replies Latest reply on Nov 19, 2012 5:10 PM by kglad

    How can I change actions parameters within a function using different function

    mr.alexblah

      Cant think of another way to ask it, I've looked EVERYWHERE and tried doing it to my best of my knowledge but no luck.
      Suppose I got 10 squares respectfully named sq1, sq2... sq10 and I have a 10 button that, when pressed, calls a function that makes its respectful  square move and change color. This would be a problem if it were only 10 squares and just do 2 actions, just change the instance name of each function... something like:

       

      button1.onPress = movesquare1 ();

      button2.onPress = movesquare2();

      ....... and so on

       

      function movesquare1 ();

      sq1._x = sq._x + 1;

       

      function movesquare2 ();

      sq2._x = sq._x + 1;

      ....... and so on

       

      is there a way to have a general movesquare function, designate an N variable so that when a button is pressed the N variable would be designated?

      something like:

      button1.onPress = movesquare(n=1)

       

      function movesquare ();

      sqn._x = sqn._x + 1;

       

      this way I only have the change the number of n=1 so that it points to the right sq and this avoiding writing  A LOT of movesquare functions to accommodate for each sq...

       

      Long post but tried to explain my dilemma it the best way possible.

       

      Tried using var:String and var:number but no luck...

       

      Many thanks