Created
May 20, 2012 03:39
-
-
Save joelhooks/2741312 to your computer and use it in GitHub Desktop.
ever scrolling thumbnails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @private | |
*/ | |
protected function mouseClickHandler(event:MouseEvent):void | |
{ | |
selectedItem=item.data; | |
moveSelectedThumbToCenter(); | |
} | |
/** | |
* Moves the selected NavItem to the center of the navigation container. | |
* @private | |
*/ | |
protected function moveSelectedThumbToCenter():void | |
{ | |
if (!selectedThumb) | |
return; | |
addEventListener(Event.ENTER_FRAME, handleEnterFrame); | |
thumbsNeedPositioning=false; | |
currentlyAnimating=true; | |
} | |
/** | |
* @private | |
*/ | |
private function handleEnterFrame(event:Event):void | |
{ | |
setPositions(); | |
} | |
/** | |
* Set the positions of the item renderers | |
* @param e | |
* @private | |
*/ | |
private function setPositions(animated:Boolean=true):void | |
{ | |
var selectedThumbnail:DisplayObject=selectedThumb as DisplayObject; | |
var firstThumb:DisplayObject=thumbRenderers[0] as DisplayObject; | |
var thisX:Number; | |
var deltaX:Number; | |
if (!selectedThumbnail || !firstThumb) | |
{ | |
removeEventListener(Event.ENTER_FRAME, handleEnterFrame); | |
return; | |
} | |
thisX=selectedThumbnail.x + thumbWidth; | |
deltaX=thisX - (selectedThumbTargetPositionX + thumbWidth / 2); | |
if (animated) | |
firstThumb.x-=deltaX / _damping; | |
else | |
firstThumb.x-=deltaX; | |
alignThumbnails(); | |
repositionThumbsAtLimits(); | |
if (Math.abs(deltaX) < 1) | |
{ | |
removeEventListener(Event.ENTER_FRAME, handleEnterFrame); | |
currentlyAnimating=false; | |
} | |
} | |
/** | |
* Make sure all of the NavItems stay aligned while they are swapped | |
* @private | |
*/ | |
private function alignThumbnails():void | |
{ | |
for (var i:int=1; i < thumbRenderers.length; i++) | |
{ | |
thumbRenderers[i].x=thumbRenderers[i - 1].x + thumbWidth; | |
} | |
} | |
/** | |
* Shifts the images to keep the continuous scroll continuous | |
* @private | |
*/ | |
private function repositionThumbsAtLimits():void | |
{ | |
var left:DisplayObject=thumbRenderers[0]; | |
var right:DisplayObject=thumbRenderers[thumbRenderers.length - 1]; | |
for (var i:int=0; i < thumbRenderers.length; i++) | |
{ | |
if (left.x < 0 - thumbWidth / 4 ) | |
{ | |
// moves clips from first to last | |
thumbRenderers.push(thumbRenderers.shift()); | |
left.x=right.x + thumbWidth; | |
} | |
if (right.x > thumbWidth * thumbRenderers.length - thumbWidth / 8 ) | |
{ | |
// moves clips from last to first | |
thumbRenderers.unshift(thumbRenderers.pop()); | |
right.x=left.x - thumbWidth; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment