# What's wrong with my function?

**URL:** <https://forum.kirupa.com/t/whats-wrong-with-my-function/301660>\
**Category:** flash\
**Created:** [December 13, 2009, 2:03pm UTC](https://forum.kirupa.com/t/whats-wrong-with-my-function/301660 "2009-12-13T14:03:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ash\_at\_risk](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@ash\_at\_risk](https://forum.kirupa.com/u/ash_at_risk)\
**Post date:** [December 13, 2009, 2:03pm UTC](https://forum.kirupa.com/t/whats-wrong-with-my-function/301660/1 "2009-12-13T14:03:46Z")

</div>

Hi all,  
I am confused ,what’s wrong with this function although it does not cause any errors but my man(player) never stops at the scrolling rightEdge.  
RightEdge is the distance from rightside of screen where screen starts to scroll in reverse direction.  
I wanna to display it in full screen mode.i.e stage.stageWidth=1276  
here rect is the instance name of the big rectangle which consists of all my movieclip,rect.width=9341 & rect.x=-1414.8;

```php

         var edgeDistance:Number=200;
       function ScrollWithMan()
	{
		var stagePosition:Number=rect.x + man.mc.x;
		var rightEdge:Number=stage.stageWidth-edgeDistance;
		var leftEdge:Number=edgeDistance-1250.8;
		//trace(stage.stageWidth);
		trace("Pos="+ rect.x);
		trace("man.x="+man.mc.x);
		{
			if (stagePosition > rightEdge-100)
			{
				rect.x-=(stagePosition-rightEdge-100)
				if (rect.x < -(rect.width-stage.stageWidth)) 
				rect.x = -(rect.width-stage.stageWidth);
	                 }
				else if (stagePosition <leftEdge)
				{
					rect.x+=(stagePosition-leftEdge);
					//if (rect.x < 100) rect.x = 100;
				}
	          }
	  }

```
