# Pan Image Fail

**URL:** https://forum.kirupa.com/t/pan-image-fail/305685
**Category:** flash
**Created:** [March 1, 2010, 11:23pm UTC](https://forum.kirupa.com/t/pan-image-fail/305685 "2010-03-01T23:23:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![teddyruxpin](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@teddyruxpin](https://forum.kirupa.com/u/teddyruxpin)
#### Post date: [March 1, 2010, 11:23pm UTC](https://forum.kirupa.com/t/pan-image-fail/305685/1 "2010-03-01T23:23:32Z")

</div>

Dear People,

I’m still a bit of a noob in Action Script, but i found this script on the internet that seems to work pretty well.

I made this website: www.biezenkuilen.nl/speeltuin which has a pan script in it. The problem: When you scroll to the most far right corner it first works but if you try a second time you will scroll into a white area, which i didn’t put there. Somehow it finished my picture and therefore showing the part of my stage, which is empty white space. Obviously i want to picture to stop panning when the end is reached and no further. Can someone help me with this problem. I have no clue what to do…🙂

Thanks in advance.

Kind regards,

teddy

The script i used is:

constrainedMove(bg\_mc, 2, 1);

function constrainedMove(target:MovieClip, speed:Number, dir:int){  
var mousePercent:Number = mouseX / stage.stageWidth;

```
stage.addEventListener(MouseEvent.MOUSE_MOVE, panImage);
target.cacheAsBitmap = true;

function panImage(E:MouseEvent):void {
    var mSpeed:Number;
    mousePercent = mouseX / stage.stageWidth;
    if (dir == 1) {
        mSpeed = mousePercent;
    } else {
        mSpeed = 1 - mousePercent;
    }
    target.destX = Math.round(-((target.width - stage.stageWidth) * mSpeed));
    if(target.hasEventListener(Event.ENTER_FRAME)){
        target.removeEventListener(Event.ENTER_FRAME, del);
    }
    target.addEventListener(Event.ENTER_FRAME, del);
    E.updateAfterEvent();
}

function del(E:Event):void {
    if (Math.abs(target.x - target.destX) &lt;= 1) {
        target.x = Math.round(target.destX);
        target.removeEventListener(Event.ENTER_FRAME, arguments.callee);
    } else {
        target.x += (target.destX - target.x) * (speed / 100);
    }
}

```

}
