# Class problems

**URL:** <https://forum.kirupa.com/t/class-problems/214353>\
**Category:** Uncategorized\
**Created:** [January 27, 2007, 9:43pm UTC](https://forum.kirupa.com/t/class-problems/214353 "2007-01-27T21:43:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![puthem1st](https://avatars.discourse-cdn.com/v4/letter/p/ecb155/32.png) [@puthem1st](https://forum.kirupa.com/u/puthem1st)\
**Post date:** [January 27, 2007, 9:43pm UTC](https://forum.kirupa.com/t/class-problems/214353/1 "2007-01-27T21:43:34Z")

</div>

Hello, I posted yesterday an article similar to this but I went back over the tutorial on OOP [http://www.kirupa.com/net/oop\_intro\_classes\_pg1.htm](http://www.kirupa.com/net/oop_intro_classes_pg1.htm) and made some changes but it seems that there is still something wrong. I’m just trying to display a simple question through a class file, but its not working.

Here is what I had in .fla file that I converted to .as. The .fla file worked so the issue is setting up my class file.

```auto

var myEquations:Array = [];
var myOperators:Array = ["+","-","*","/"];
for (var i:Number = 0;i < 10;i++) {
 var num1:Number = Math.round((Math.random() * 10) + 1);
 var num2:Number = Math.round((Math.random() * 10) + 1);
 var randOp:Number = Math.round(Math.random() * (myOperators.length - 1));
 var temp:String = num1.toString() + " " + myOperators[randOp] + " " + num2.toString();
 trace("this is random string " + i + ": " + temp);
 myEquations.push(temp);
}
//first, I'll set up a variable to hold
//the current equation we're on.
var currentEq:Number = 0;
//now here's a function that will place
//the equation in the left textfield.
var setEquation:Function = function() {
 eq_txt.text = myEquations[currentEq];
}
//And, now that our equations are all inside the
//myEquations array, let's see how
//we can compute them:
var checkFunction:Function = function() {
 var ta:Array = myEquations[currentEq].split(" ");
 trace("here's ta: " + ta);
 var tmp:Number;
 switch(ta[1]) {
  case "+" : 
   trace("we're adding");
   tmp = parseInt(ta[0]) + parseInt(ta[2]);
   break;
  case "-" : 
   trace("we're subtracting");
   tmp = parseInt(ta[0]) - parseInt(ta[2]);
   break; 
  case "*" : 
   trace("we're multiplying");
   tmp = parseInt(ta[0]) * parseInt(ta[2]);
   break; 
  case "/" : 
   trace("we're dividing");
   tmp = parseInt(ta[0]) / parseInt(ta[2]);
   break; 
 }
 trace("and tmp is: " + tmp);
 if (tmp.toString() == ans_txt.text) {
  trace("correct!");
  ans_txt.text = "";
  currentEq ++;
  setEquation();
 } else {
  trace("wrong!");
 }
}
setEquation();
check_mc.onRelease = checkFunction;

```

//Here is where I have converted the code into a class file

```auto
class Mathlesson {
//declare class variables this is the variable set up to get the users info from the text box.
 var ans_txt: String;
/ ******************************************************************************* /
 //class constructor
 function Mathlesson() {
  var ans_txt= userinput;
 }
/ ******************************************************************************* /
//define methods sets up the question to be displayed
public function getuserinput():String {
  return userinput;
 }
public function checkFunction() {
  var ta:Array = myEquations[currentEq].split("");
  var tmp:Number;
  switch(ta[1]) {
    case "+" :
   trace ("we're adding");
   tmp = parseInt(ta[0]) + parseInt(ta[2]);
   break;
    case "-" :
   trace ("we're subtrating");
   tmp = parseInt(ta[0]) + parseInt(ta[2]);
   break;
    case "*" :
   trace("we're multiplying");
   tmp = parseInt(ta[0]) + parseInt(ta[2]);
   break;
    case "/" :
     trace ("we're dividing");
   tmp = parseInt(ta[0]) + parseInt(ta[2]);
   break;
  }
  trace ("and tmp is: " +tmp);
  if (tmp.toString() == ans_txt.text) {
   trace("Correct!");
   ans_txt.text="";
   currentEq ++;
   setEquation();
  } else {
   trace("wrong!");
  }
 }
 setEquation();
 check_mc.onRelease =checkFunction;
/ ********************************************************************************
//sets up the question to be displayed
********************************************************************************* /
 private function displayquest(){
    var myEquations:Array = [];
    var myOperators:Array = ["+","-","*","/"];
 for (var i:Number = 0;i < 10;i++) {
    var num1:Number = Math.round((Math.random() * 50) + 1);
    var num2:Number = Math.round((Math.random() * 50) + 1);
    var randOp:Number = Math.round(Math.random() * (myOperators.length - 1));
    var temp:String = num1.toString() + " " + myOperators[randOp] + " " + num2.toString();
    //var temp:String = num1.toString() + myOperators[randOp] + num2.toString();
    myEquations.push(temp);
}
var currentEq:Number =0;
var setEquation:Function = function() {
 eq_txt.text = myEquations[currentEq];
}
 }
}

```

I would appreciate any help. I’m not too sure what I’m doing wrong. :book:
