title: Flash error 1151 in a for loop
body: <p>I have a strange problem regarding Flash error 1151: A conflict exists with definition i in namespace internal.</p>
  
  <p>Here is the problematic code:</p>
  
  <pre><code>for(var i:Number=dt.getFullYear(); i &gt;= dt.getFullYear()-90; i--)
  {
      dtYear.addItem( {label:i, data:i} );
  } //for
  
  //-*-*-* Month
  for(var i:Number=0; i &lt; months.length; i++)
  {
      dtMonth.addItem( {label:i, data:i} );
  } //for
  </code></pre>
  
  <p>Or a more blatant example:</p>
  
  <pre><code>for(var i:Number=0; i &lt; 12; i++)
  {
      trace(i);
  } //for
  
  //-*-*-* Month
  for(var i:Number=0; i &lt; 12; i++)
  {
  } //for
  </code></pre>
  
  <p>Adobe gives an explanation:</p>
  
  <p><code>You cannot declare more than one variable with the same identifier name within the same scope unless all such variables are declared to be of the same type. In ActionScript 3.0, different code blocks (such as those used in two for loops in the same function definition) are considered to be in the same scope.</code></p>
  
  <p>What the friggin hell is this? I mean the i variable is all the time exists as a Number, typecasted as a Number, why the hell would the above code then fail?</p>
  
  <p>If I modify it this way, it works, BUT THATS UGLY AND WHY IS THIS NEEDED? AAARGGGHHHH...Flash development makes me crazy. Gimme a gun :). Someone explain this one to me please.</p>
  
  <p>Working code:</p>
  
  <pre><code>for(var i:Number=dt.getFullYear(); i &gt;= dt.getFullYear()-90; i--)
  {
      dtYear.addItem( {label:i, data:i} );
  } //for
  
  //-*-*-* Month
  for(i=0; i &lt; months.length; i++)
  {
      dtMonth.addItem( {label:i, data:i} );
  } //for
  </code></pre>