# Easy code i don't get

**URL:** <https://forum.kirupa.com/t/easy-code-i-dont-get/26784>\
**Category:** Uncategorized\
**Created:** [July 26, 2003, 8:57am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784 "2003-07-26T08:57:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![blah\_de\_blah](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@blah\_de\_blah](https://forum.kirupa.com/u/blah_de_blah)\
**Post date:** [July 26, 2003, 8:57am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/1 "2003-07-26T08:57:58Z")

</div>

Ok this should be easy, but theres 1 thing that confuses me (this is for a scrollbar btw; not the componenet ones) and i got this from a flash 5 source, but i am using MX…

ok there are 3 keyframes. On keyframe 1 there is the code:  
[AS]  
oldY = 0;  
newY = 0;  
Y = 0;  
[/AS]

Keyframe2 code:  
[AS]  
dragY = \_root.dragMC.buttonMC.\_y;  
newY = oldY+(dragY-oldY)/8;  
\_root.mainScroll.scrolledMC.\_y = newY;  
oldY = newY;  
play();  
[/AS]

Keyframe3 code:  
[AS]  
prevFrame();  
[/AS]

ok so i get all that, except the line in keyframe 2, if you dont’ get the above, forget it, the bit below is the important bit 🙂

newY = oldY+(dragY-oldY)/8;

This line is what is confusing me, because 2 lines under that, it says:

oldY = newY.

And in the line i just showed you, it says:

newY = oldY (…blahblahblah)

So if they both equal each other, than whats the point?! I know what i just said was confusing :-\ Hope you can help thanks!

---

<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:** [July 26, 2003, 9:11am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/2 "2003-07-26T09:11:35Z")

</div>

What’s the point, huh? None. Remove it!! 😛  
[AS]newY += (dragY-newY)/8;[/AS]

---

<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:** [July 26, 2003, 9:17am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/3 "2003-07-26T09:17:54Z")

</div>

ok now this is getting mroe confusin…

newY += dragy-newy

so dragY minus itself?!!? ok anyways this doesn’t seem to work :-\i’ll post the fla for you to see. I’m trying to optimize this crappy flash 5 code to flash MX 🙂

---

<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:** [July 26, 2003, 9:27am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/4 "2003-07-26T09:27:46Z")

</div>

… Where’s the code? :whistle:

---

<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:** [July 26, 2003, 10:03am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/5 "2003-07-26T10:03:01Z")

</div>

yea thats what i thogutht the first time i saw it…its in the see through dot on stage…or if you open the library…its in ‘script’.

---

<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:** [July 26, 2003, 10:10am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/6 "2003-07-26T10:10:13Z")

</div>

I thought I checked every symbol in the Library, I must have missed that one! 😛

---

<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:** [July 26, 2003, 10:23am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/7 "2003-07-26T10:23:09Z")

</div>

heh, you think its possible to ‘optimize’ that code?? It seems a bit messy :-\

---

<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:** [July 26, 2003, 11:07am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/8 "2003-07-26T11:07:48Z")

</div>

Well, I would remove those variables, create the MovieClip by using ActionScript and update the content position by using an onEnterFrame handler. I don’t like static event handlers, so I’d remove them too…

Remove the MovieClip _script_ and throw this code in the main timeline:  
[AS]dragMC.buttonMC.onPress = function() {  
this.startDrag(false, 0, -1010, 0, 0);  
};  
dragMC.buttonMC.onRelease = function() {  
this.stopDrag();  
};  
dragMC.buttonMC.onReleaseOutside = dragMC.buttonMC.onRelease;  
this.createEmptyMovieClip(“controller”, 9876);  
controller.onEnterFrame = function() {  
mainScroll.scrolledMC.\_y += (dragMC.buttonMC.\_y-mainScroll.scrolledMC.\_y)/8;  
};[/AS]  
… But I guess that you wanted to somehow automate the process, so you don’t have to hardcode the whole thing (the startDrag parameters, for instance)? :-\

Uhmm… I don’t think I’m explaining myself very well. I’ve never been good at it. 😛

---

<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:** [July 26, 2003, 11:10am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/9 "2003-07-26T11:10:27Z")

</div>

thanks! that looks nice, but what does the createemptymovieclip create?! I know it creates an empty movieclip 😉 But what are we going to use it for?

EDIT: ok from what i understand it controls the easing thing right?!but thats only after the user releases the mouse off the dragger :-\ or i think i am wrong actually

---

<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:** [July 26, 2003, 11:17am UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/10 "2003-07-26T11:17:52Z")

</div>

It creates the MovieClip which will act as a controller (self explanatory instance name) to move the MovieClip, _scrolledMC_, to the correct position.

Now that I think about it, you don’t need that either. Remove those lines of the code and assign the onEnterFrame handler to _scrolledMC_:  
[AS]mainScroll.scrolledMC.onEnterFrame = function() {  
this.\_y += (dragMC.buttonMC.\_y-this.\_y)/8;  
};[/AS]  
Much better… 😛

---

<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:** [July 26, 2003, 2:33pm UTC](https://forum.kirupa.com/t/easy-code-i-dont-get/26784/11 "2003-07-26T14:33:45Z")

</div>

woo it works !! thanks kax, you are the man 🙂
