/ Published in: ActionScript
When user clicks one one item it makes that item bigger while adjusting the other items size & position without each item having to check it's neighbors position onEnterFrame. Code still in need of refactoring.
Expand |
Embed | Plain Text
stop(); import flash.geom.Matrix; import com.orazal.oralib2.transitions.MultiTweener; import com.robertpenner.easing.*; var totalItems:Number = 5; var itemWidth:Number = 330; var totalWidth:Number = 875; var thumbSpacing:Number = 2; var adjustedWidth:Number = totalWidth - (thumbSpacing * (totalItems-1)); var thumbWidth:Number = adjustedWidth /totalItems; var smallThumbWidth:Number = (adjustedWidth-itemWidth)/4; var itemList:Array = [item0, item1, item2, item3, item4]; var activeItem:MovieClip = null; // Init placeThumbs(); function placeThumbs(){ // Go through itemList for(var i:Number=0; i<itemList.length; i++) { var item:MovieClip = itemList[i]; // Original size & position item.originalMatrix = item.transform.matrix; item.originalMatrix.tx = (smallThumbWidth*i) + (thumbSpacing*i); // Small thumb size item.smallThumbMatrix = item.transform.matrix; item.smallThumbMatrix.a = item.smallThumbMatrix.d = smallThumbWidth/itemWidth; // Thumb size & position item.thumbMatrix = item.transform.matrix; item.thumbMatrix.a = item.thumbMatrix.d = thumbWidth/itemWidth; item.thumbMatrix.tx = (thumbWidth*i) + (thumbSpacing*i); item.transform.matrix = item.thumbMatrix; item.onRelease = function() { itemReleaseHandler(this); } } } function itemReleaseHandler(item:MovieClip) { // If it's already selected if(activeItem == item) { activeItem = null; // close all for(var i:Number=0; i<itemList.length; i++) { var clip:MovieClip = itemList[i]; tweenToThumb(clip); } return; } // If none or another one is selected if(activeItem != this) { activeItem = item; tweenToOriginal(item); var position:Number = Number(item._name.substr(4)); for(var i:Number=0; i<itemList.length; i++) { var clip:MovieClip = itemList[i]; // Left of active if(i < position) { clip.smallThumbMatrix.tx = (smallThumbWidth*i) + (thumbSpacing*i); tweenToSmallThumb(clip); } // Right of active if(i > position) { clip.smallThumbMatrix.tx = (smallThumbWidth*(i-1)) + (thumbSpacing*i); clip.smallThumbMatrix.tx += itemWidth; tweenToSmallThumb(clip); } } return; } } function tweenToOriginal(item:MovieClip) { item.tween.stop(); var startMatrix:Matrix = item.transform.matrix; var endMatrix:Matrix = item.originalMatrix; item.tween = new MultiTweener(startMatrix, endMatrix, Circ.easeOut, 0.5, true); item.tween.onMotionChanged = function(mt:MultiTweener) { item.transform.matrix = startMatrix; } } function tweenToThumb(item:MovieClip) { item.tween.stop(); var startMatrix:Matrix = item.transform.matrix; var endMatrix:Matrix = item.thumbMatrix; item.tween = new MultiTweener(startMatrix, endMatrix, Circ.easeOut, 0.5, true); item.tween.onMotionChanged = function(mt:MultiTweener) { item.transform.matrix = startMatrix; } } function tweenToSmallThumb(item:MovieClip) { item.tween.stop(); var startMatrix:Matrix = item.transform.matrix; var endMatrix:Matrix = item.smallThumbMatrix; item.tween = new MultiTweener(startMatrix, endMatrix, Circ.easeOut, 0.5, true); item.tween.onMotionChanged = function(mt:MultiTweener) { item.transform.matrix = startMatrix; } }
You need to login to post a comment.
