Move to pan function

hey game pplz i made a nice little function that lets you take a character (mc) and a stage (area) and if the character moves to the edge it will scroll the area instead of moving the mc


//BY: Donovan Hubbard 2007
//Action Script 3, Move to Pan
function moveToPan(mc:MovieClip, area:MovieClip, speedX:Number, speedY:Number, bounds:Number) {
    var stgLeft:Number =  bounds;
    var stgRight:Number = stage.stageWidth - bounds;
    var stgUp:Number = bounds;
    var stgDown:Number = stage.stageHeight - bounds;
    var atLeft:Boolean;
    var atRight:Boolean;
    var atUp:Boolean;
    var atDown:Boolean;
    if (Math.abs(area.x - stage.stageWidth) >= area.width-20) {
        mc.x -= 1;
        area.x += 1;
        return;
    }
    if (area.x > -20) {
        mc.x += 1;
        area.x -= 1;
        return;
    }
    if (Math.abs(area.y - stage.stageHeight) >= area.height-20) {
        mc.y -= 1;
        area.y += 1;
        return;
    }
    if (area.y > -20) {
        mc.y += 1;
        area.y -= 1;
        return;
    }
    if ((mc.x < stgLeft)&&(speedX<0)) {
        area.x -= speedX;
        atLeft = true;
    } else if ((speedX>0)&&(!atRight)) {
        mc.x += speedX;
        atLeft = false;
    }
    if ((mc.x > stgRight)&&(speedX>0)) {
        area.x -= speedX;
        atRight = true;
        mc.x -= speedX;
    } else if ((speedX<0)&&(!atLeft)) {
        mc.x += speedX;
        atRight = false;
    }
    if ((mc.y > stgDown)&&(speedY>0)) {
        area.y -= speedY;
        atDown = true;
    } else if ((speedY<0)&&(!atUp)) {
        mc.y += speedY;
        atDown = false;
    }
    if ((mc.y < stgUp)&&(speedY<0)) {
        area.y -= speedY;
        atUp = true;
        mc.y -= speedY;
    } else if ((speedY>0)&&(!atDown)) {
        mc.y += speedY;
        atUp = false;
    }
}

hope this aids some of you in your game developing :p: