/ Published in: ActionScript
methods : getGridPositions, zoomFromPoint
Expand |
Embed | Plain Text
class com.orazal.tools.PositionUtils { /** * Returns x and y positions for a grid * * @param amount The total amount of items * @param limit The row or column limit before line break * @param width The item's with * @param height The item's height * @param direction Horizontal or Vertical * @returns An array with a position object with the x and y properties */ public static function getGridPositions(amount:Number, limit:Number, width:Number, height:Number, direction:String):Array { // Set direction as horizontal if none is found if (!direction) { direction = "horizontal"; } var pos_ar:Array = new Array(); for (var i:Number = 0; i<20; i++) { switch (direction) { case "horizontal" : var column:Number = i%limit; var row:Number = Math.floor(i/limit); break; case "vertical" : var row:Number = i%limit; var column:Number = Math.floor(i/limit); break; } var xPos = column*width; var yPos = row*height; pos_ar.push({x:xPos, y:yPos}); } return pos_ar; } /** * Calculates a clip's final size and position from a provided registration point * *@param clip The movieclip to zoom *@param percent The amount to zoom *@param xOffset The percentage (in decimals) to offset horizontally from clip's center *@param yOffset The percentage (in decimals) to offset vertically from clip's center *@returns An object with the final width, height, x and y positions */ public static function zoomFromPoint(clip:MovieClip, percent:Number, xOffset:Number, yOffset:Number):Object { // Convert zoom percent to decimals percent /= 100; // Get original width and height var originalW = clip._width/(clip._xscale/100); var originalH = clip._height/(clip._yscale/100); // Center register position if not provided if (!xOffset) { var xOffset:Number = 0.5; } if (!yOffset) { var yOffset:Number = 0.5; } // Determine x and y positions var centerX = clip._x+(clip._width*xOffset); var centerY = clip._y+(clip._height*yOffset); // Determine final positions var final:Object = new Object(); final.width = originalW*percent; final.height = originalH*percent; final.x = centerX-(final.width*xOffset); final.y = centerY-(final.height*yOffset); return final; } }
You need to login to post a comment.
