Walking Animation

Hey I want it so when my character walks the animation starts, and when he stops so does the animation.

var isWalking: boolean;

function Update(){

    if (isWalking){
       animation.Play ("walk");
    } else {
       animation.Stop("walk");
    }
}

Something like that, dropped on the model. Here's the documentation