Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá pessoal.
Eu estou usando um scroller, funciona muito bem. Mas eu gostaria que ele pudesse ser controlado também pelas setas "up" e "down" do teclado. Seria possível editar o código de forma que ele aceitasse as duas formas de controle?
Segue o código do mesmo.
Agradeço qualquer dica.
:D
// ok here is the load event handler
// diff_y is the total amount that the scrollbar can movethe bound_box is a movie clip that surrounds everything. its just a clear box
// next line we set bounds to the bounding area of the bound_box clip getBounds() returns 4 variable yMin yMax xMin & xMax they are the bounding area that well use for a lot of stuff
// top is the highest amount the scrollbar can go
// bottom is the lowest
// updateScrollbar() is the function for setting the content clip to the right spot
// "scroller._y - top/diff_y" is a percent of the scroll bar's position we multiply it by the amount we can scroll of the content
// friction is how much the scrollbar should slow down by after throwing it
onClipEvent (load) {
diff_y = bound_box._height-scroller._height;
bounds = bound_box.getBounds(this);
top = bounds.yMin+(scroller._height/2);
bottom = bounds.yMax-(scroller._height/2);
function updateScrollbar () {
content._y = -(((scroller._y-top)/diff_y)*(content._height-bound_box._height));
}
friction = 0.90;
}
// this detects if you clicked on the scroller it starts a drag with the scroller to be from the "top" which we defined earlier to the "bottom"
// we then set scrolling to true
onClipEvent (mouseDown) {
if (scroller.hitTest(_root._xmouse, _root._ymouse)) {
startDrag ("scroller", false, scroller._x, top, scroller._x, bottom);
scrolling = true;
}
}
// here we stop the drag and set scrolling to false
onClipEvent (mouseUp) {
stopDrag ();
scrolling = false;
}
// every frame it sees if your scrolling then it updates the scrollbar to the right place based on the y position of the scroller
// it also calculates the speed of your scrolling
onClipEvent (enterFrame) {
if (scrolling) {
updateScrollbar();
newY = scroller._y;
yspeed = (newY-oldY)*0.50;
oldY = newY;
done = false;
} else if (!done) {
// here it adds the speed to the y position of the scroller
// then it asks if the speed is at a number that you can see it moving if it is then it decreases the speed by multiplying it by a decimal
oldypos = scroller._y;
newypos = oldypos+yspeed;
if (yspeed<-0.2 || yspeed>0.2) {
yspeed *= friction;
} else {
yspeed = 0;
done = true;
}
// the next two if statements test if it hit the top or bottom if it had it makes the speed negative to what it is so itll change its direction - neat bounce effect to it
if (newypos<top) {
yspeed = -1*yspeed*friction;
newypos = top;[/code]
}
if (newypos>bottom) {
yspeed = -1*yspeed*friction;
newypos = bottom;
}
// here we set the scrollers y position to newyposition (the variable we are adding the speed to)
// it then sets the mc to whereever the scroller is
// then its going to keep on doing this enterFrame business untill speed has reduced itself to 0
scroller._y = newypos;
updateScrollbar();
}
}Carregando comentários...