# Move to pan function

**URL:** https://forum.kirupa.com/t/move-to-pan-function/247208
**Category:** Uncategorized
**Created:** [December 19, 2007, 4:53pm UTC](https://forum.kirupa.com/t/move-to-pan-function/247208 "2007-12-19T16:53:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![GrndMasterFlash](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@GrndMasterFlash](https://forum.kirupa.com/u/GrndMasterFlash)
#### Post date: [December 19, 2007, 4:53pm UTC](https://forum.kirupa.com/t/move-to-pan-function/247208/1 "2007-12-19T16:53:16Z")

</div>

i posted this in the gaming forum but im sure some of you AS3 pplz who don’t do gaming would like to know about it.

//////////////////////////////////////////copy of post/////////////////////////////////////////  
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

```
Code:
//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:
