Closed ghost closed 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
It's C# thing. http://blog.roboblob.com/2012/09/30/dot-net-gotcha-nr2-loop-variables-and-closures/
I using code:
but code error out of index of ListA. When I using, It's work OK
Can you explain of error? Thanks