3 Replies Latest reply on Nov 15, 2012 4:30 PM by Ned Murphy

    Using variables for function arguments AS2

    ZKM128 Level 1




      I am trying to create a function in AS2.

      After creating the function, I want to use values stored in variables for the function arguments rather than manually typing static values for carrying out the function calculation. Also, I want to use the function to assign a new value to the existing variable.


      I have asked a similar question 2 days ago here and got the answer (thank you), but now I got one more question - How can I create the function to assign a value to the variable while that variable itself is also a function argument?


      For example, I have 6 numeric variables:


      var CoinA:Number = 10;
      var CoinB:Number = 20;
      var CoinC:Number;

      var CoinD:Number = 30;
      var CoinE:Number = 40;
      var CoinF:Number;


      Then I tried to create a function to assign values to variables CoinC and CoinF:


      function CalculationA(FirstCoin, SecondCoin, ThirdCoin):Void {


           FirstCoin = SecondCoin + ThirdCoin;




      CalculationA(CoinC, CoinA, CoinB);
      CalculationA(CoinF, CoinE, CoinF);


      The above code didn't really assign the values 30 and 70 to the variables CoinC and CoinF but instead, values of CoinC and CoinF are undefined.


      Please give me the correct code if there's a correct way of doing this.


      Thank you,