Hey all, I'm new to as3 and I can't understand why this doesn't work. Here's the code:

Actionscript Code:
for(var i:Number=0;i<def.length;i++)
{
    this["term" + i].addEventListener(MouseEvent.MOUSE_DOWN, function(evt:MouseEvent){
    startMove(evt, i)});

    this["term" + i].addEventListener(MouseEvent.MOUSE_UP, function(evt:MouseEvent){
    stopMove(evt, i)});
}

Expected outcome:
Actionscript Code:
this.term0.addEventListener(MouseEvent.MOUSE_DOWN, function(evt:MouseEvent){
    startMove(evt, 0)});

this.term1.addEventListener(MouseEvent.MOUSE_DOWN, function(evt:MouseEvent){
    startMove(evt, 1)});

What is actually happening:
Actionscript Code:
this.term0.addEventListener(MouseEvent.MOUSE_DOWN, function(evt:MouseEvent){
    startMove(evt, 7)});

this.term1.addEventListener(MouseEvent.MOUSE_DOWN, function(evt:MouseEvent){
    startMove(evt, 7)});

So somehow the startMove/stopMove is always being sent the last number in my sequence, but the term variable is being sent the correct sequence and yet they are both populated by 'i'...

Can anyone provide any views on this for me? I don't see how this outcome is even possible!

Thanks!