View Full Version : using mousewheel in a scrollPane
mcmcom
10-19-2004, 06:07 PM
Has anyone got this to work.
I tried this code
onClipEvent (load) {
_root.scrollPane1.setFocus();
//create mouse wheel listener
var mouseListener:Object = new Object();
mouseListener.onMouseWheel = function(delta) {
var cnt = _root.scrollPane1.getScrollContent();
if (cnt._height>_root.scrollPane1.getSize().height) {
cnt._y += delta*3;
_root.scrollPane1.invalidate();
}
};
Mouse.addListener(mouseListener);
}
And it works, its just that the vertical slider does not move until you click
within the scrollPane, then it refreshes.
Invalidate() and refreshPane() both do nothing.
Any ideas?
McM
mcmcom
10-19-2004, 07:42 PM
i figured it out
I replaced
_root.scrollPane1.invalidate();
with
_root.scrollPane1.setScrollContent(0,Math.abs(cnt. _y));
that above snippet wasn't working because Negative numbers were being passed
Math.abs takes care of that.
r3tic
10-22-2004, 04:07 AM
I'm using mx 2004 pro 7.2 and I am unable to get the mouse wheel to function using your code. Is there any way you could post a sample file?
Thanks
rrickybal2
01-24-2005, 09:13 AM
i use flash mx 2004 put this code on de scrollpane instance:
onClipEvent (load) {
scrollinstance.setFocus();
var mouseListener:Object = new Object();
mouseListener.onMouseWheel = function(delta) {
i = scrollinstance.vPosition;
j = scrollinstance.content._y;
p = scrollinstance.vPageScrollSize;
h = maxscroll;
if (i == 0 && delta<0) {
scrollinstance.content._y += (delta/3)*p;
scrollinstance.vPosition -= (delta/3)*p;
} else if (i>0 && i<h) {
if (i>(h-p)) {
scrollinstance.content._y = -h;
scrollinstance.vPosition = h;
} else if (i<p) {
scrollinstance.content._y = 0;
scrollinstance.vPosition = 0;
} else {
scrollinstance.content._y += (delta/3)*p;
scrollinstance.vPosition -= (delta/3)*p;
}
} else if (i == h && delta>0) {
scrollinstance.content._y += (delta/3)*p;
scrollinstance.vPosition -= (delta/3)*p;
} else if (i>h) {
scrollinstance.content._y = -h;
scrollinstance.vPosition = h;
}
};
Mouse.addListener(mouseListener);
} where scrollinstance is _root.movie1.scrollpane1 where you will load the scrollpane.(you will need to change it to your scrollpane instance path).
and the other thing that you'll gonna change is maxscroll with the max of "i" , for that you will need to insert a trace(i); before the function finish and trace the value of i when you drag the scroll down to the end and then wheel up.
rrickybal2
01-25-2005, 04:02 AM
onClipEvent (load) {
u = targetPath(this);
eval(u).setFocus();
var mouseListener:Object = new Object();
mouseListener.onMouseWheel = function(delta) {
i = eval(u).vPosition;
j = eval(u).content._y;
p = eval(u).vPageScrollSize;
h = maxscroll;
if (i == 0 && delta<0) {
eval(u).content._y += (delta/3)*p;
eval(u).vPosition -= (delta/3)*p;
} else if (i>0 && i<h) {
if (i>=(h-p)) {
if (i>=(h-p) && delta<0) {
eval(u).content._y = -h+0.2;
eval(u).vPosition = h-0.2;
} else {
eval(u).content._y += (delta/3)*p;
eval(u).vPosition -= (delta/3)*p;
}
} else if (i<p && delta>0) {
eval(u).content._y = 0;
eval(u).vPosition = 0;
} else {
eval(u).content._y += (delta/3)*p;
eval(u).vPosition -= (delta/3)*p;
}
} else if (i == h && delta>0) {
eval(u).content._y += (delta/3)*p;
eval(u).vPosition -= (delta/3)*p;
} else if (i>h) {
eval(u).content._y = -h;
eval(u).vPosition = h;
}
};
Mouse.addListener(mouseListener);
} now you dont need to change the scrollinstance cause its detect automactly now you only need to change is the maxscroll value
indolicious
02-08-2005, 03:01 PM
Help, when i use this script it seems that i first have to activate the scrollpane by clicking on it and then i can use the scroll wheel from my mouse.
Im using flash 7.2
Anyone know how i can bypass this and use my mousewheel directly on the scrollpane without first using the scrollbar.
red penguin
05-05-2005, 06:27 PM
scrollPaneClip.vLineScrollSize = 100;
SImple solution...
of course, that # can be adjusted to your needs.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.