Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-14-2007, 11:06 AM   #1
Registered User
Join Date: Nov 2006
Posts: 17
Default Senocular's free transform tool (or even senocular) question

I've been using Senocular's free transform tool: http://proto.layer51.com/d.aspx?f=636 in tandem with an image upload (using the fileReference class) so that users can upload an image and the transform it.

The free transform class has a function that allows you to restrict the scaling of the movieClip that you apply the free transform to, but it works on a 'scale' rather than specific height and width properties. My problem is, that I don't know what he dimensions of each uploaded image will be, so if it's restricted to a scale, some images will be allowed to be bigger than others....

Has anyone used this tool (or even written it... he he...) and worked out a way to restrict the scaling to a set width and height?

Any ideas will me most appreciated...


DrGonzo1208 is offline   Reply With Quote
Old 03-14-2007, 02:51 PM   #2
six eyes
senocular's Avatar
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular

Once the image is loaded you can determine the scale to use based on what you want the size to be and what the image currently is

senocular is offline   Reply With Quote
Old 11-19-2007, 06:28 PM   #3
Senior Member
Join Date: Nov 2007
Posts: 110
Default wrote a quick fix

The code is below, some of the functions have been added by me, some have been edited by me (originally written by senocular). Its mostly a fix, I didn't bother writing and get/set functions for portability since I thought I was just writing it for myself. Hope this helps (or at least gets you started)...

private var _minRectangle:Rectangle = new Rectangle(0, 0, 100, 75); //set constraints here
private var _horizConstraint:Number;
private var _vertConstraint:Number;

private function setConstraints():void {
// set new targetbounds
var cWidth:Number = Point.distance(_boundsBottomRight, _boundsBottomLeft);
var cHeight:Number = Point.distance(_boundsTopLeft, _boundsBottomLeft);

// maintain aspect ratio
var whRatio:Number = cWidth / cHeight;
_minRectangle.height = (_minRectangle.width * cHeight) / cWidth;

// boundaries determined by ration between _minRectange and current rectangle
_horizConstraint = (1 - (_minRectangle.width / cWidth)) * (-1);
_vertConstraint = (1 - (_minRectangle.height / cHeight)) * (-1);

private function constrainSmallScale(scaleType:String):Point {

// Code Edit by Kyle Brekke - Nov 4, 2007
// Based on the constrain code in scaleBothInteraction function

// mouse reference, may change from innerMouseLoc if constraining
var innerMouseRef:Point = innerMouseLoc.clone();

// how much the mouse has moved from starting the interaction
var moved:Point = innerMouseLoc.subtract(innerInteractionStart);

// the relationship of the start location to the registration point
var regOffset:Point = innerInteractionStart.subtract(innerRegistration);

// find the ratios between movement and the registration offset
var ratioH = regOffset.x ? moved.x/regOffset.x : 0;
var ratioV = regOffset.y ? moved.y/regOffset.y : 0;

if (ratioV < _vertConstraint) { //flipped vert
innerMouseRef.y = innerInteractionStart.y + regOffset.y * _vertConstraint;
if (ratioH < _horizConstraint) { //flipped horiz
innerMouseRef.x = innerInteractionStart.x + regOffset.x * _horizConstraint;

var distortV:Point = distortOffset(new Point(innerInteractionStart.x, innerMouseRef.y), innerInteractionStart.y - innerRegistration.y);
var distortH:Point = distortOffset(new Point(innerMouseRef.x, innerInteractionStart.y), innerInteractionStart.x - innerRegistration.x);

if (scaleType == "horizontal") {
return distortH;
} else {
return distortV;

// THIS IS THE SAME CODE FOR scaleYInteraction, just change "horizontal" to "vertical"
public function scaleXInteraction():void {

// Code Edit by Kyle Brekke Nov 9, 2007

// get distortion offset horizontal movement
//var distortH:Point = distortOffset(new Point(innerMouseLoc.x, innerInteractionStart.y), innerInteractionStart.x - innerRegistration.x);
var distortH:Point = constrainSmallScale("horizontal"); // edited Kyle Brekke - Nov 4, 2007

// update the matrix for vertical scale
_toolMatrix.a += distortH.x;
_toolMatrix.b += distortH.y;

INSIDE scaleBothInteraction FUNCTION:
// have the larger of the movement distances brought down
// based on the lowest ratio to fit the registration offset
if (ratioH > ratioV && (ratioV > _vertConstraint) && (ratioH > _horizConstraint)) { // "&&..." added by Kyle Brekke Nov 5, 2007
innerMouseRef.x = innerInteractionStart.x + regOffset.x * ratioV;
}else if (ratioV > ratioH && (ratioV > _vertConstraint) && (ratioH > _horizConstraint)){ // "&&..." added by Kyle Brekke Nov 5, 2007
innerMouseRef.y = innerInteractionStart.y + regOffset.y * ratioH;

// constrain the scale so pictures don't flip - editted Kyle Brekke Nov 4
if (ratioV < _vertConstraint || ratioH < _horizConstraint) { //flipped vert
innerMouseRef.y = innerInteractionStart.y + regOffset.y * _vertConstraint;
innerMouseRef.x = innerInteractionStart.x + regOffset.x * _horizConstraint;
pelkin000 is offline   Reply With Quote
Old 05-06-2010, 12:32 AM   #4
Registered User
Join Date: Dec 2009
Posts: 2

thankyou for your code pelkin000, this is driving me mad.

I put the setConstraints in the endInteractionHandler and removed

//if (ratioH > ratioV) {
//innerMouseRef.x = innerInteractionStart.x + regOffset.x * ratioV;
//innerMouseRef.y = innerInteractionStart.y + regOffset.y * ratioH;

does something wierd, seems to work fine now, cheers again!

Last edited by impaler; 05-06-2010 at 03:47 AM.
impaler is offline   Reply With Quote
Old 12-30-2010, 04:19 PM   #5
Senior Member
Join Date: Nov 2007
Posts: 110

I know this is delayed, but the code in my previous post should take care of what you want to do. The "private var minRectangle" is the absolute minimum you want an image to be. That way, no matter the size of photo uploaded (though you could also handle this in PHP, etc), it will never scale smaller than your minRectangle.
pelkin000 is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stupid noob question about free transform kep1 Flash 8 General Questions 3 09-25-2006 05:01 PM
Question about Pencil Tool properties Crimson Flash 8 General Questions 2 07-18-2006 09:19 PM
Development Tool Question TGad Flash Remoting 1 12-13-2004 05:20 PM
[AS1] Swapdepth using txt files and dynamic content for game. superbnerb Gaming and Game Development 3 09-22-2004 07:27 PM
Simple question ( The Line Tool ) Paul Ferrie Simple Stuff (Newbies) 8 09-06-2002 09:36 PM

All times are GMT. The time now is 09:15 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.