PDA

View Full Version : Sliding thumbnails with throttle acceleration V0.7 (with zip)


dinardo01
07-20-2005, 09:06 PM
I'm excited - I have been working on this for a while and it is starting to behave as I intended. AND since you all have been so helpful by posting and commenting on this website, I would like to share this with all of you! What do you think? Please post comments (good and bad). See attached file.

Features
This is a sliding thumbnail viewer that is supposed to mimic the cool transition effects found on websites.

Two 'throttling' areas at either end (sizes changable)
Mouse controlled speed - as the mouse reaches the ends of 'throttle' areas, the thumbs will speed up to a percentage of the MAX_SPEED (defined as TARGET_SPEED)
Thumbnails will accelerate upon entering viewer
Thumbnails will decelerate upon exiting viewer



Wish list. I wish..

..thumbnails would automatically detect when they are reaching the boundaries of the mask and decelerate to their "exact" respective left and right boundary.
..the thumbnails would 'snap' decelerate so that the thumbnails are never cut off.


Please feel free to post code that will help with the wish list !


Concerns

I think this code is not a clean as it can be. Does anyone agree? I guess the best thing to do is to make this a class file, but I am not very confident in doing that.
The code is not using Penner easing or any other easing, I just winged it. Should I use Penner easing? If so, how do I implement?



The code


/*
this mc reads the mouse location and accelerates the thumbnail movie called
(ThumbMaker_mc) movie left or right depending on the mouse location on the mask
Rob DiNardo - http://www.robdinardo.com
*/

//make some thumbnails
for(i=0;i<30;i++){
ThumbMaker_mc.attachMovie("ThumbImg_mc",["ThumbImg_mc"+i],i);
ThumbMaker_mc["ThumbImg_mc"+i]._x = i * 135;
ThumbMaker_mc["ThumbImg_mc"+i].count_txt.text = i; //not working ????
}


var boundL:Number = 300; //left bounding area: 0 to boundL
var boundR:Number = 360; //right bounding area: boundR to 660
var CURRENT_SPEED:Number = 0; //variable for current speed
var TARGET_SPEED:Number; //variable for desired speed
var MAX_SPEED:Number = 15; //maximum possible speed
var ACCELERATION:Number = 0.25; //ratio of acceleration (also used to declerate)
var DIRECTION:String = "L"; //variable for the direction of the motion
var THUMB_WIDTH:Number = ThumbMaker_mc._width; //width of all thumbnails
var MASK_WIDTH:Number = mask_mc._width; //width of mask
var SCROLL_WIDTH:Number = MASK_WIDTH-THUMB_WIDTH; //


this.onEnterFrame = function(){

// if the mouse pointer enters thumb viewer
if(mask_mc.hitTest(_root._xmouse, _root._ymouse, false)){

MOUSE_LOC = Math.round(this._xmouse); //mouse location

//if the mouse is in the left part of the navigation
if(MOUSE_LOC < boundL){
if(ThumbMaker_mc._x > -50) {
DecelerateThumbs()
} else {
THROTTLE = (boundL-MOUSE_LOC)/(boundL-0); //percent
TARGET_SPEED = Math.round(THROTTLE * MAX_SPEED,2); //desired speed
DIRECTION = "R"; //direction to move thumbs
AccelerateThumbs(TARGET_SPEED); //move thumbs right
}
}


//if the mouse is in the right part of the navigation
if (MOUSE_LOC > boundR) {
if(ThumbMaker_mc._x < SCROLL_WIDTH + 50) {
DecelerateThumbs()
} else {
THROTTLE =(MOUSE_LOC-boundR)/(MASK_WIDTH-boundR); //percent of speed
TARGET_SPEED = Math.round(THROTTLE * MAX_SPEED,2); //desired speed
DIRECTION = "L"; //direction to move thumbs
AccelerateThumbs(TARGET_SPEED); //move thumbs left
}
}


} else {
DecelerateThumbs();
}

};


function AccelerateThumbs(ts:Number){
if (DIRECTION == "L"){ j = -1; } else { j = 1; } //set direction
if(CURRENT_SPEED <= ts){ //check current speed
ThumbMaker_mc._x += j*CURRENT_SPEED; //move the thumbnails to the left
CURRENT_SPEED += ACCELERATION; //increment current speed
} else { //if target speed reached
ThumbMaker_mc._x += j*ts; //contiue moving at target speed
CURRENT_SPEED = ts;
}
}


function DecelerateThumbs(){
if (DIRECTION == "L"){ j = -1; } else { j = 1; } //set direction
if(CURRENT_SPEED > 0){ //if in motion
ThumbMaker_mc._x += j*CURRENT_SPEED; // move the thumbnails to the left
CURRENT_SPEED -= ACCELERATION*3; //decrease speed
}
}

dinardo01
07-21-2005, 11:50 AM
I see there are some votes. Great! I would love to see some comments. I would like to make this module more robust and easier to use. Hopefully one day it will be a class file.

I see there has been some downloads of the file - has anyone figured out how to "snap" and / or decelerate the thumbnails to their left and right boundaries respectively?

carlos_abreu198
07-21-2005, 02:16 PM
hey men how could i do for make it to work on external file.
loaded on a movie clip container, sorry
its'n working i need your help for fix it.

godogo
02-10-2007, 06:55 PM
Finally! For days I have been looking for a solution to have a sliding scroller like this, where the mouse position actions are contained only within the clip.
Now, as you posted, dinardo01, I only need to figure out how to get the slider to position properly on the ends (maybe it does this part already and I don't know how to configure?) and snaps into full position when the slider rests.
Did you improve on this script? If so, I would like to see it. Otherwise, I'll see if I can modify it myself.
Thanks a lot for your great work!

godogo
02-11-2007, 04:33 AM
I did some playing around with this script and managed to come up with a solution that both loops the clip. I added the following code:

panel.onRollOver = panelOver;

function panelOver() {
this.onEnterFrame = scrollPanel;
delete this.onRollOver;
}

function scrollPanel() {
if(_xmouse<b.xMin || _xmouse>b.xMax || _ymouse<b.yMin || _ymouse>b.yMax) {
this.onRollOver = panelOver;
delete this.onEnterFrame;
}

if(panel._x >= -121) {
panel._x = -1825;
}

if(panel._x <= -1847) {
panel._x = -140;
}

Replace "panel" with name of slider.

This added code takes the position of the slider clip when it reaches it's outer positions and then replaces it in a new position so it will loop. I am still having to adjust the numbers for mine so it is completely seamless. Also, some of the code might be redundant. I'm not fluent enough to really know if it can be simplified to work better with the previous code, but at least my test works the way I want it to.