Groups | Blog | Home
all groups > flash actionscript > june 2005 >

flash actionscript : snap to pic within a scroller


Hunnie
6/1/2005 9:06:24 PM
Hello, I have created a scroller with images contained within and would like to
know if its possible that when scrolled if it couldl snap to the next pic
within the scoller? The scoller has an ease on it and still would like for it
to scroll smoothly, but also to snap.
kglad
6/1/2005 9:20:05 PM
Hunnie
6/1/2005 9:54:06 PM
Hello Klad,
Could you assist me in making this script happen?
The code is provided below:

//Actions for the scroller

fscommand("allowscale", "false");
bar.useHandCursor = dragger.useHandCursor=false;
space = 5;
friction = 0.9;
speed = 4;
y = dragger._y;
top = main._y;
bottom = main._y+mask_mc._height-main._height-space;
dragger.onPress = function() {
drag = true;
this.startDrag(false, this._x, this._parent.y, this._x,
this._parent.y+this._parent.bar._height-this._height);
dragger.scrollEase();
};
dragger.onMouseUp = function() {
this.stopDrag();
drag = false;
};
bar.onPress = function() {
drag = true;
if (this._parent._ymouse>this._y+this._height-this._parent.dragger._height) {
this._parent.dragger._y = this._parent._ymouse;
this._parent.dragger._y = this._y+this._height-this._parent.dragger._height;
} else {
this._parent.dragger._y = this._parent._ymouse;
}
dragger.scrollEase();
};
bar.onMouseUp = function() {
drag = false;
};
moveDragger = function (d) {
if ((dragger._y>=y+bar._height-dragger._height && d == 1) || (dragger._y<=y
&& d == -1)) {
clearInterval(myInterval);
} else {
dragger._y += d;
dragger.scrollEase();
updateAfterEvent();
}
};
up_btn.onPress = function() {
myInterval = setInterval(moveDragger, 18, -1);
};
down_btn.onPress = function() {
myInterval = setInterval(moveDragger, 18, 1);
};
up_btn.onMouseUp = down_btn.onMouseUp=function () {
clearInterval(myInterval);
};
MovieClip.prototype.scrollEase = function() {
this.onEnterFrame = function() {
if (Math.abs(dy) == 0 && drag == false) {
delete this.onEnterFrame;
}
r = (this._y-y)/(bar._height-this._height);
dy = Math.round((((top-(top-bottom)*r)-main._y)/speed)*friction);
main._y += dy;
};
};

kglad
6/1/2005 11:51:50 PM
kglad
6/2/2005 12:00:00 AM
the code you posted is relevent to product gallery only and it's not obvious
what pic your want to lock to what position in product gallery. specificially,
there are always 2 pics fully visible and part of a third and sometimes a
fourth. what logic do you want to employ to decide which pic to lock to which
position?

it's really in the other galleries that pic lock is needed and has an obvious
choice of pic to lock because the viewable window is so small that, at most,
parts of two pics are visible. it's easy enough to select one (say the one
with least _y property) to lock in the window's center.

are those other galleries that you want to employ a scroll to lock position?
Hunnie
6/2/2005 12:00:00 AM
Hello, I apologize for not explaining. But yes, the 'stones' and the 'colors'
more specifically will need to lock to center so that only one image can be
viewed at a time, not the Product Gallery. Thanks for your help.
kglad
6/2/2005 12:00:00 AM
kglad
6/2/2005 6:30:51 AM
see what you think:

Hunnie
6/2/2005 11:27:35 AM
AddThis Social Bookmark Button