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?
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.
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)
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).