View Full Version : Easy code i don't get...
blah-de-blah
July 26th, 2003, 04:57 AM
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:
oldY = 0;
newY = 0;
Y = 0;
Keyframe2 code:
dragY = _root.dragMC.buttonMC._y;
newY = oldY+(dragY-oldY)/8;
_root.mainScroll.scrolledMC._y = newY;
oldY = newY;
play();
Keyframe3 code:
prevFrame();
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!
kode
July 26th, 2003, 05:11 AM
What's the point, huh? None. Remove it!! :P
newY += (dragY-newY)/8;
blah-de-blah
July 26th, 2003, 05:17 AM
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 :)
kode
July 26th, 2003, 05:27 AM
... Where's the code? :whistle:
blah-de-blah
July 26th, 2003, 06:03 AM
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'.
kode
July 26th, 2003, 06:10 AM
I thought I checked every symbol in the Library, I must have missed that one! :P
blah-de-blah
July 26th, 2003, 06:23 AM
heh, you think its possible to 'optimize' that code?? It seems a bit messy :-\
kode
July 26th, 2003, 07:07 AM
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:
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;
};
... 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. :P
blah-de-blah
July 26th, 2003, 07:10 AM
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
kode
July 26th, 2003, 07:17 AM
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:
mainScroll.scrolledMC.onEnterFrame = function() {
this._y += (dragMC.buttonMC._y-this._y)/8;
};
Much better... :P
blah-de-blah
July 26th, 2003, 10:33 AM
woo it works !! thanks kax, you are the man :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.