Easy code i don't get

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

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!

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

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

… Where’s the code? :whistle:

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’.

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

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

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. :stuck_out_tongue:

thanks! that looks nice, but what does the createemptymovieclip create?! I know it creates an empty movieclip :wink: 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

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… :stuck_out_tongue:

woo it works !! thanks kax, you are the man :slight_smile: