# actionscript3 , set stage limit

**URL:** <https://forum.kirupa.com/t/actionscript3-set-stage-limit/570264>\
**Category:** flash\
**Created:** [March 9, 2015, 2:16am UTC](https://forum.kirupa.com/t/actionscript3-set-stage-limit/570264 "2015-03-09T02:16:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shockwave3](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@shockwave3](https://forum.kirupa.com/u/shockwave3)\
**Post date:** [March 9, 2015, 2:16am UTC](https://forum.kirupa.com/t/actionscript3-set-stage-limit/570264/1 "2015-03-09T02:16:36Z")

</div>

Hi, I want to do righr/left button controlled movie clip but dont know how to set X axis/stage limit, the movieclip doesnt leave stage. Wil anybody help me?

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [March 9, 2015, 2:56am UTC](https://forum.kirupa.com/t/actionscript3-set-stage-limit/570264/2 "2015-03-09T02:56:22Z")

</div>

```javascript
if(newX < stage.stageWidth - my_mc.width && newX > 0) my_mc.x = newX

```

Add a condition similar to that in the part of your code that sets a new position for the MovieClip.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [March 9, 2015, 3:00pm UTC](https://forum.kirupa.com/t/actionscript3-set-stage-limit/570264/3 "2015-03-09T15:00:55Z")

</div>

Note that the above example works best when you have the registration point at the [top] left of your movie clip. Here’s an alternate version where that doesn’t matter, and it also works for any kind of transform that might be applied (like rotation)

```javascript
var my_bounds = my_mc.getBounds(my_mc.parent)
var leftEdge = my_mc.x - my_bounds.left
var rightEdge = my_mc.x - my_bounds.right + stage.stageWidth

if(newX < rightEdge){
   if(newX > leftEdge){
      my_mc.x = newX
   }else{
      my_mc.x = leftEdge
   }
}else{
   my_mc.x = rightEdge
}

```

(and this is also assuming my\_mc’s parent is either the main timeline or in a parent who’s located at 0,0 of the main timeline otherwise additional offsets will exist).
