# Need a little help

**URL:** <https://forum.kirupa.com/t/need-a-little-help/1136>\
**Category:** Uncategorized\
**Created:** [August 9, 2002, 7:32am UTC](https://forum.kirupa.com/t/need-a-little-help/1136 "2002-08-09T07:32:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceman](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@iceman](https://forum.kirupa.com/u/iceman)\
**Post date:** [August 9, 2002, 7:32am UTC](https://forum.kirupa.com/t/need-a-little-help/1136/1 "2002-08-09T07:32:14Z")

</div>

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 [usrcrew.freewebspace.com/finally.html](http://usrcrew.freewebspace.com/finally.html) The first issue is when you drag the button I want it to stop when I let go. The code on mc is:  
onClipEvent(load){  
\_root.first.\_x = \_root.dragButton.\_x

}  
onClipEvent(enterFrame){  
function myScroll() {  
vel = (\_root.dragButton.\_x - \_root.first.\_x)/20;  
\_root.pos = Math.round(vel + \_root.pos);  
\_root.first.\_x = \_root.pos;  
}  
myScroll();  
}  
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

Kyle:)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 9, 2002, 11:45pm UTC](https://forum.kirupa.com/t/need-a-little-help/1136/2 "2002-08-09T23:45:51Z")

</div>

Hi Kyle,

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 10, 2002, 12:50am UTC](https://forum.kirupa.com/t/need-a-little-help/1136/3 "2002-08-10T00:50:12Z")

</div>

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.

Well…

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:

```auto

_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:

```auto

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

on(release) {
	stopDrag();
	_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”:

```auto

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 10, 2002, 2:51am UTC](https://forum.kirupa.com/t/need-a-little-help/1136/4 "2002-08-10T02:51:17Z")

</div>

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 [iceman4@sympatico.ca](mailto:iceman4@sympatico.ca).

Thanks so much

Kyle

😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 10, 2002, 1:05pm UTC](https://forum.kirupa.com/t/need-a-little-help/1136/5 "2002-08-10T13:05:55Z")

</div>

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.
