Image pan nested mc

Hi all,

I’ve modified Kirupa’s image pan script to work on both x- and y-axis, which works fine when using a modestly sized graphic converted to a movieclip. Only, I want to use it on a nested MC with multiple MC-ed images that are each twice the size of the stage. I don’t know why, but it behaves strangely: I can’t pan the entire area and I can’t pan back to the point I started at…

Somebody?

Thanks!
Tim

Here’s the code that’s pasted on the first frame of my actions layer:



this.onMouseMove = function() {

constrainedMove(bg_mc, 10, 1);

};
function constrainedMove(target:MovieClip, speed:Number, dir:Number) {

var xmousePercent:Number = _xmouse/Stage.width;
var ymousePercent:Number = _ymouse/Stage.height;

var xArrived:Boolean=FALSE;
var yArrived:Boolean=FALSE;

var mSpeed:Number;

if (dir == 1) {

xSpeed = 1-xmousePercent;
ySpeed = 1-ymousePercent;

} else {

xSpeed = xmousePercent;
ySpeed = ymousePercent;

}

target.destX = Math.round(-((target._width-Stage.width)*xSpeed));
target.destY = Math.round(-((target._height-Stage.height)*ySpeed));

target.onEnterFrame = function() {

if (target._x == target.destX) {
    xArrived=TRUE;
} else {
    target._x += Math.ceil((target.destX-target._x)*(speed/100));
}

if (target._y == target.destY) {
    yArrived=TRUE;
} else {
    target._y += Math.ceil((target.destY-target._y)*(speed/100));
}

if ((xArrived) && (yArrived)) delete target.onEnterFrame;

};

}