actionscript 3 - Flash error 1151 in a for loop -
i have strange problem regarding flash error 1151: conflict exists definition in namespace internal.
here problematic code:
for(var i:number=dt.getfullyear(); >= dt.getfullyear()-90; i--) { dtyear.additem( {label:i, data:i} ); } //for //-*-*-* month for(var i:number=0; < months.length; i++) { dtmonth.additem( {label:i, data:i} ); } //for
or more blatant example:
for(var i:number=0; < 12; i++) { trace(i); } //for //-*-*-* month for(var i:number=0; < 12; i++) { } //for
adobe gives explanation:
you cannot declare more 1 variable same identifier name within same scope unless such variables declared of same type. in actionscript 3.0, different code blocks (such used in 2 loops in same function definition) considered in same scope.
what friggin hell this? mean variable time exists number, typecasted number, why hell above code fail?
if modify way, works, thats ugly , why needed? aaarggghhhh...flash development makes me crazy. gimme gun :). explain 1 me please.
working code:
for(var i:number=dt.getfullyear(); >= dt.getfullyear()-90; i--) { dtyear.additem( {label:i, data:i} ); } //for //-*-*-* month for(i=0; < months.length; i++) { dtmonth.additem( {label:i, data:i} ); } //for
this called variable hoisting, in as3 there no scope variable, compiler move declared variable @ top of function, can't declare twice same variable in same function.
here documentation variable usage , declaration deeper information.
Comments
Post a Comment