Bar movement via actionscript

Hi there. I’m having a problem. I want ro make a bar (a simple object in flash) to move right and left according to the mouse position. I can make the movement and so on, but i want to define some limits in wich the bar moves, or the bar would get off the screen :slight_smile: and i don’t want that. I posted the fla with this message, so i would apreciate a lot if someone download the file and see where’s the problem. Is it a coordinates problem ?? I don’s know.Plz help me

You mean like this. I presume you are going to mask it. Anyway fiddle with the && this._x>“number” to get the stop where you want it

Thanks Mate :)!!!
it was exactily want i wanted!! it woks perfectly!!!

But e need you to tell me how did you calculated de correct coordinates of each(left and rigth side!!) limit to make the bar stop when she reached one of the sides!!!Thanks very much!!!

Are you aware of registration points? Basically when you click on an mc, you’ll see a small circle with a cross in it. That’s the registration point. It’s from here that the x and y coordinates for the mc are calculated.

All you do is drag the mc to where it should stop, note where the registration point is under the ruler and that’s where the mc’s scroll limit should be:

[COLOR=blue]if (_root._xmouse>350 && this._x>"-100") {
this._x -= amount;[/COLOR]

Where you see [COLOR=blue]&& this._x>"-100"[/COLOR] is where I dragged the mc to the left and saw that the registration point was roughly around -100.

And where you see [COLOR=blue]&& this._x<“630”[/COLOR] is where I dragged the mc to the right until it was where it should be when it reaches the end, and saw that the registration point was roughly around 630.

So the [COLOR=blue]&& this._x>"-100"[/COLOR] and the [COLOR=blue]&& this._x<“630”[/COLOR] make sure that the bar only moves when the it is within these boundaries.

To view the rulers, go to View —> Rulers.

My code was similar to yours, except that i used a controller with two frames, and instead of “this._x” i used “_root.barra._x”. About the coordinates, the registration point, the small circle with a cross. The coordinates from the object are not those who appear in the properties rollout, or the info rollout are they ? Because i followed that coordinates. My mistake. I thought the registration point of an object was it’s top left corner and that the correct coordinates of the object were those who appeared in the properties rollout. My mistake, we’re always learning aren’t we ? :slight_smile:
Thanks a lot, one more time.

No probs.

If you use:

this._x

or

_root.barra._x

or even just _x it’s all the same in MX as long as you use it in the code for the movie clip. Otherwise _x and _root.barra._x can make difference between an action being carried out or not.

As for the registration point, you can make it the top left corner if you want. Modify —> Transform —> Free Transform, and drag the white square where you want the registration poin to be.

I believe there is a tutorial on this site somewhere about that.