Se connecter avec
S'enregistrer | Connectez-vous

Scrollbar et Flash

Dernière réponse : dans Programmation

Salut à tous, voilà j'ai réussi à mettre une scrollbar dans un site tout en flash mais le truc, c'est que je voudrais que la vitesse de défilment soit plus rapide...

Je vous laisse le code :
#initclip
_global.FUISmoothScrollbar = function() {
this.init();
};
FUISmoothScrollbar.prototype = new MovieClip();
Object.registerClass("FUISmoothScrollbar", FUISmoothScrollbar);
FUISmoothScrollbar.prototype.init = function() {
var c = this._parent[this._targetInstanceName];
this.w = Math.round(c._width);
this.h = Math.max(34, Math.round(this._height));
this._xscale = this._yscale=100;
c._y = this._y=Math.round(this._y);
this.x = this._x = Math.round(c._width+c._x);
c._x = Math.ceil(this._x-c._width);
this._height = Math.round(this._height);
var scrollH = (this.h-34)*((this.h-34)/c._height);
var s = this.attachMovie("scroll_asset", "scroll_bar", 1);
this.h<45 ? s.bar._visible=0 : s.bar._visible=1;
s.scrolltrack.useHandCursor = s.bas.useHandCursor=s.haut.useHandCursor=s.bar.useHandCursor=false;
s.scrolltrack._height = this.h-34;
s.bar.centre._height = scrollH-10;
s.bar.bas._y = s.bar.centre._y+s.bar.centre._height;
s.bar.basPos = s.bar.centre._y+s.bar.centre._height;
s.bar.bas._y = s.bar.basPos;
s.bas._y = this.h-17;
var m = this.createEmptyMovieClip("mask", 2);
m.lineStyle(0);
m.moveTo(0, 0);
m.beginFill(0x000000, 0);
m.lineTo(-this.w, 0);
m.lineTo(-this.w, this.h);
m.lineTo(0, this.h);
m.endFill();
c.setMask(m);
this.loadScroll();
};
FUISmoothScrollbar.prototype.loadScroll = function() {
var c = this._parent[this._targetInstanceName];
var m = this.mask;
var s = this.scroll_bar;
var factor = 0;
if (c._height<=m._height) {
s.bar._visible = 0;
} else {
var scrollMaxi = c._height-m._height;
s.bar.onPress = function() {
this.yDragPoint = this._y-_root._ymouse;
this.onEnterFrame = function() {
this.coorY = _root._ymouse+this.yDragPoint;
this._y += (this.coorY-this._y)/3;
if (this._y>(s.scrolltrack._y+s.scrolltrack._height)-s.bar._height) {
this._y = (s.scrolltrack._y+s.scrolltrack._height)-s.bar._height;
}
if (this._y<17) {
this._y = 17;
}
};
this._parent._parent.scroll();
};
s.bar.onRelease = s.bar.onReleaseOutside=function () {
this.onEnterFrame = function() {
this._y += (this.coorY-this._y)/3;
if (this._y>(s.scrolltrack._y+s.scrolltrack._height)-s.bar._height) {
this._y = (s.scrolltrack._y+s.scrolltrack._height)-s.bar._height;
delete this.onEnterFrame;
this._parent._parent.stopScroll();
}
if (this._y<17) {
this._y = 17;
delete this.onEnterFrame;
this._parent._parent.stopScroll();
}
if (Math.abs(this._y-this.coorY)<1.2) {
delete this.onEnterFrame;
this._parent._parent.stopScroll();
}
};
};
s.bas.onPress = function() {
this.onEnterFrame = function() {
factor += ((this._parent._parent.h/30)-factor)/3;
s.bar._y = Math.min(s.bar._y+factor, (s.scrolltrack._y+s.scrolltrack._height)-s.bar._height);
this._parent._parent.scroll();
};
};
s.bas.onRelease = s.bas.onReleaseOutside=function () {
this.onEnterFrame = function() {
factor += (0-factor)/3;
s.bar._y = Math.min(s.bar._y+factor, (s.scrolltrack._y+s.scrolltrack._height)-s.bar._height);
this._parent._parent.scroll();
if (Math.abs(factor)<1) {
factor = 0;
s.bar._y = Math.min(s.bar._y+factor, (s.scrolltrack._y+s.scrolltrack._height)-s.bar._height);
delete this.onEnterFrame;
this._parent._parent.stopScroll();
}
};
};
s.haut.onPress = function() {
this.onEnterFrame = function() {
factor += ((this._parent._parent.h/30)-factor)/3;
s.bar._y = Math.max(s.bar._y-factor, 17);
this._parent._parent.scroll();
};
};
s.haut.onRelease = s.haut.onReleaseOutside=function () {
this.onEnterFrame = function() {
factor += (0-factor)/3;
s.bar._y = Math.max(s.bar._y-factor, 17);
this._parent._parent.scroll();
if (Math.abs(factor)<1) {
factor = 0;
s.bar._y = Math.max(s.bar._y-factor, 17);
delete this.onEnterFrame;
this._parent._parent.stopScroll();
}
};
};
s.scrolltrack.onPress = function() {
if (s.bar._ymouse>(s.bar._y+s.bar._height)) {
this._parent._parent.scroll();
var newY = Math.min((this._parent._parent.h-17)-s.bar._height, s.bar._y+((s.scrollTrack._height/s.bar._height)*30));
s.bar.onEnterFrame = function() {
this._y += (newY-this._y)/3;
if (Math.abs(this._y-newY)<1.2) {
delete this.onEnterFrame;
this._parent._parent.stopScroll();
}
};
} else if (s.bar._y>s.bar._ymouse) {
this._parent._parent.scroll();
var newY = Math.max(17, s.bar._y-((s.scrollTrack._height/s.bar._height)*30));
s.bar.onEnterFrame = function() {
this._y += (newY-this._y)/3;
if (Math.abs(this._y-newY)<1.2) {
delete this.onEnterFrame;
this._parent._parent.stopScroll();
}
};
}
};
}
};
FUISmoothScrollbar.prototype.scroll = function() {
var c = this._parent[this._targetInstanceName];
var m = this.mask;
var s = this.scroll_bar.bar;
var y = this._y;
var scrollMaxi = (c._height)-(m._height);
var distScroll = (this.h-34)-(s._height);
this.onEnterFrame = function() {
var prc = -((s._y-17)*scrollMaxi)/distScroll;
c._y += Math.round(((prc+y)-c._y)/3);
};
};
FUISmoothScrollbar.prototype.stopScroll = function() {
var c = this._parent[this._targetInstanceName];
var m = this.mask;
var s = this.scroll_bar.bar;
var y = this._y;
var scrollMaxi = (c._height)-(m._height);
var distScroll = (this.h-34)-(s._height);
this.onEnterFrame = function() {
var prc = -((s._y-17)*scrollMaxi)/distScroll;
c._y += Math.round(((prc+y)-c._y)/3);
if (Math.abs(c._y-(prc+y))<1.2) {
c._y = Math.round(prc+y);
delete this.onEnterFrame;
}
};
};
#endinitclip
this.dead._visible = false;

Autres pages sur : scrollbar flash

Lassé par la pub ? Créez un compte

C'est possible d'avoir le lien pour regarder comment c fais au niveau graphique (utilisation de bouton...!?)

sinon je pense que c'est peut-etre ca :

this.onEnterFrame = function() {
this._y += (this.coorY-this._y)/3;


et/ou

s.bar.onEnterFrame = function() {
this._y += (newY-this._y)/3;


essaye d'augmenter le resultat (division par 2 par ex)

si c'est pas ca, regarde aux endroits comportant "onEnterFrame ", cela signifie que les actions sont toujours effectué/verifier....

le lien serait vraiment utile (je ne vois pas trop comment est le scroll avec ce code)

a+

Je viens d'aller voir (je ne pouvais pas avant) : je ne trouve pas que la barre est lente, je la trouve tres bien. Mais bon, si je trouve je te fais signe.

Ce qui change par rapport au barre classique c'est le petit decalage defilement-barre qui donnent un effet de glisse plutot sympa.

Sinon, c toi qui a fait le code ? (si oui, ca aurait été bien de mettre des commentaires pour mieux s'y retrouvais)

a+
Lassé par la pub ? Créez un compte
Tom's guide dans le monde