title: ActionScript 3: Turning a String into and Operator?
body: <p>I'm trying to create a simple calculator program in ActionScript for a school project, and I'm struggling to find a concise way to take an equation from an array such as this: "4","+","2"; and manipulate it so that the answer to the equation can be deduced. The problem is taking the String "+" from the equation array and turning it into a usable operator. At the moment, when an operator button is pressed on the calculator GUI it adds the operator to the equation array as a String (i.e. pressing the '÷' button will add "/" to the equation array).</p>
  
  <p>I looked for an answer to this on Google and found <a href="https://forums.adobe.com/message/2855191" rel="nofollow">something about a JavaScript function</a> that I used in the code below (in lines 1 and 4), but all I end up with in the Output feed is "null", or "0" depending on whether I changed the variable 'answer' to a String, or a Number.</p>
  
  <p>Here's the code I have so far:</p>
  
  <pre><code>import flash.external.ExternalInterface;
  
  var equationArray:Array = new Array("4","+","2");
  var answer:Number = ExternalInterface.call("eval",equationArray[0] + equationArray[1] + equationArray[2]);
  trace(answer);
  </code></pre>
  
  <p>I'd prefer to use something like this rather than writing a long if statement to pick between different operators if that's possible. <em>Thanks for the help!</em></p>