gree / lwf

LWF - Lightweight SWF
http://gree.github.com/lwf/
zlib License
627 stars 167 forks source link

About using this.AddMovieEventHandle #98

Closed ghost closed 10 years ago

ghost commented 10 years ago

I using code:


 for(int i = 0; i< 4; i++)
{
 this.AddMovieEventHandler( "InstanceName" , load:(m) => { m.GotoAndStop(ListA[i].x); });
 this.AddMovieEventHandler( "InstanceName" , load:(m) => { m.GotoAndStop(ListA[i].x); });

}

but code error out of index of ListA. When I using, It's work OK

int z = 0;
if(z < 4)
{
this.AddMovieEventHandler("InstanceName",load:(m) => { m.GotoAndStop(ListA[0].x); });
z++;
}
if(z < 4)
{
this.AddMovieEventHandler("InstanceName",load:(m) => { m.GotoAndStop(ListA[1].x); });
z++;
}
if(z < 4)
{
this.AddMovieEventHandler("InstanceName",load:(m) => { m.GotoAndStop(ListA[2].x); });
z++;
}
if(z < 4)
{
this.AddMovieEventHandler("InstanceName",load:(m) => { m.GotoAndStop(ListA[3].x); });
z++;
}

Can you explain of error? Thanks

splhack commented 10 years ago

It's C# thing. http://blog.roboblob.com/2012/09/30/dot-net-gotcha-nr2-loop-variables-and-closures/