title: Property of an object is reset upon entering a new function
body: <pre><code>if (mapY[i][j].buttonType != 0) //checks whether or not the button should be added
  {
      mapY[i][j].addEventListener(MouseEvent.CLICK, createBattleGUI); //adds event listener
      stage.addChild(mapY[i][j]); //adds it to stage
  }
  </code></pre>
  
  <p>In a nested for loop (for a 2D grid), I've created a random map generator. Basically, it assigns a value to each button based on its significance (0 = don't add, 1 = start point, 2 = end point, 3 = point on the shortest path from 1 to 2). I've added an event listener that takes it to the battle stage; so whenever a button is clicked, it starts a new battle. In that function, I have this:</p>
  
  <pre><code>for (i = 0; i &lt;= 9; i++)
  {
      for (j = 0; j &lt;= 9; j++)
      {
          if (mapY[i][j].buttonType != 0)
          {
              stage.removeChild(mapY[i][j]);
          }
  
      }
  
  }
  </code></pre>
  
  <p>That should remove all of the buttons. However, when I trace all of the buttonType properties, all of them are now reset to 0. If I trace it in the part that adds them to the stage, it displays correctly.</p>