0 Replies Latest reply on Jun 9, 2009 12:12 PM by SiHoop

    Problem declaring a variable

    SiHoop Level 1

      The following code is part of a method from a class that I created.I'm having a problem declaring a variable to use with the method. If I declare the variable within the method and set its value to one the the incoming parameters (i.e.  var xPos:Number=_xPos), everything works fine. However, if I declare the variable in the class constructor (i.e. private var xPos: Number) and then change the value of xPos in the method (i.e. xPos = _xPos) I start having problems. I know what the problem is, but I can't fix it: The value of xPos is always the value of the parameter associated with the last use of the method. So If I use the method 3 times with parameters 2, 6, and 4 the value of xPos is always 4.


        public function addMazes(_blankTextWidth:Number, _xPos:Number ,_yPos:Number):void{
              var xPos:Number=_xPos
              var yPos:Number=_yPos


      I assume I need to declare the variable xPos in the constructor as I use it in a function associated with an event handler and don't know of any other way for the function to access its value (see below for an example).

              function setAnswersIntoPosition(event:Event):void{






      So my question is how should I resolve this problem?

      Thank you!