Need a little help

Hey everyone,

I was just messing around trying to get a certain effect that I was looking for, I’ve pretty much got it but there are a few things that I would like to get some help with. my example is at The first issue is when you drag the button I want it to stop when I let go. The code on mc is:
_root.first._x = _root.dragButton._x

function myScroll() {
vel = (_root.dragButton._x - _root.first._x)/20;
_root.pos = Math.round(vel + _root.pos);
_root.first._x = _root.pos;
And I have some drag actions on an invisible button and I want the circle to stop moving when I stop dragging the button, so I tried myScroll.stop(); but that didn’t work. Finally, sorry if this is long, is there any easier way of containing my draggable button to the line mc that I have because I have just entered the pixels in the startDrag() and its not very accurate. If anyone could help me out it would be greatly apprieciated.

Thanks Alot


Hi Kyle,

I downloaded your fla and will take a peek after supper. I may have a few pointers for you. :slight_smile:

Hi Kyle,

If I read your post correctly, you were looking for several things:

  1. The slider should stay constrained to the slider bar.
  2. The blue ball should stop when you release the slider.
  3. The blue ball should stop when you still have the slider pressed, but have stopped dragging it.


  1. I’ve learned that it’s a good idea to “tie” the boundaries for the button to the constraining movie clip. This way, you can change the constraining art very easily, and your code won’t break. First, I made your slider and your slider bar the same (20 px) height so the effect looked right to me. Also, I made the invisible button and the slider art the same size (100 px x 20 px), both with upper-left registration. Then, the following code in the slider movie clip:

_root.drag = false;

_root.sliderW = this._width;
_root.sliderH = this._height;
_root.boundL = _root.bound._x;
_root.boundR = _root.bound._x + _root.bound._width - _root.sliderW;
_root.boundT = _root.bound._y;
_root.boundB = _root.bound._y + _root.bound._height - _root.sliderH;

{{you’ll see that I name almost all variables to the root; it’s my version of global variables in flash 5…}}

Then, on the button:

on(press) {
	startDrag(this, false, _root.boundL, _root.boundT, _root.boundR, _root.boundB);
	_root.drag = true;

on(release) {
	_root.drag = false;

  1. All we had to do to get the ball to stop on release was check for the drag variable. So, on the movie clip “first”:

onClipEvent(load) {
	this._x = _root.dragButton._x;

onClipEvent(enterFrame) {
	if(_root.drag) {
		vel = (_root.dragButton._x - _root.first._x)/20;
		_root.pos = Math.round(vel + _root.pos);
		this._x = _root.pos;

  1. This, I’ll leave to better flashers than myself. There are only so many button events we can trap, and the drag variable is tied to the button event press/release.

Good luck.

Thanks so much I havent’ seen the .fla but I see that your code will work. Thanks so much again. I knew that I had to constrain the dragbutton using width and height and stuff but wasn’t sure how, you helped clear that up. just a question how long have you been scripting in flash, how did you advance your scripting? Finally, for some reason it won’t let me download the attachment, so if possible could you e-mail it to me at [email protected].

Thanks so much



Hi Kyle,

Glad the code helped you out a little.

I’ve been working with Flash for a little over a year now, I guess. In a lot of ways, I still consider myself just a newbie, and learn new things every day. I learned by reading books and the forums, doing tutorials and most of all, by making tons of mistakes.

Several weeks ago, I went to New York for a week to take a class in it. I learned a tremendous amount in that class, not only in actionscript, but I’ll be able to apply it to all the programming I do.

In reality, I work with VBA far more than I work with Actionscript. How I keep the syntax straight between them is beyond me! I do find myself wanting to put “;” after every statement in VBA, and I constantly make the mistake of using “=” as the comparitive operator in actionscript. (oopsie! lol)

Again, glad I could help you out.