Tengo un scroll de texto normal con una barra, funciona perfecto. Ahora le quise agregar la función para poder moverlo también con la rueda del mouse. Agregué un código que me proporcionaron y efectivamente mueve la barra, pero no el texto.
Texto normal del scroll:
Código :
stop(); var pos_ini_barra:Number = mask._y; var pos_fin_barra:Number = (mask._y+mask._height)-barra._height; var pos_x_barra:Number = barra._x=375; var recorrido_barra:Number = pos_fin_barra-pos_ini_barra; var pos_ini_texto:Number = mascara._y; var pos_fin_texto:Number = mascara._y-(texto._height-mascara._height); var recorrido_texto:Number = 0; if (pos_fin_texto<0) { t = pos_fin_texto*(-1); recorrido_texto = mascara._y+t; } else { recorrido_texto = pos_inicio_texto-pos_fin_texto; } function mover() { muevo2 = ((pos_fin_barra-barra._y)*100)/recorrido_barra; muevo = 100-muevo2; move = (muevo*recorrido_texto)/100; texto.onEnterFrame = null; r = mascara._y-move; texto.onEnterFrame = function() { r2 = (r-this._y)/8; if (r2>=0.5 || r2<-0.5) { this._y += r2; } else { this.onEnterFrame = null; } }; } barra.onPress=function() { this.startDrag(false, pos_x_barra, pos_ini_barra, pos_x_barra, pos_fin_barra); id = setInterval(mover, 100); }; barra.onRelease=barra.onReleaseOutside=function() { this.stopDrag(); clearInterval(id); };
Texto para la función de la rueda del mouse:
Código :
var minScroll:Number = 6; var maxScroll:Number = 170; mouseListener = new Object(); mouseListener.onMouseWheel = function(delta) { if (barra._y >= minScroll && (barra._y+barra._height) <= maxScroll){ barra._y += -delta; } barra.onEnterFrame = function() { if (this._y < minScroll) this._y = minScroll; if (this._y+this._height > maxScroll) this._y = maxScroll-this._height; }; }; Mouse.addListener(mouseListener);
Puedo proporcionarles el .fla de ser necesario.
Mil gracias!
Cristian.