Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jrennard

Resizing the Handles to fit a Loaded Image... [SOLVED]

Recommended Posts

Hello!

 

I am attempting to create an application that takes an uploaded image and pops it into the Transform Manager. Currently, the upload is working and it loads the image into the Transform Manager.

 

However, I think I may be doing this the wrong way...I currently have it listen for completion of the upload and then, when it is uploaded, the following:

 

test_mc.mcImage.loadMovie("/root/uploads/" + file.name);

 

First - this is working, but should I use the addItem() instead? If so, how do I use that?

 

It pops it into the transformable bounding box, however the bounding box doesn't fit to the size of the image. It holds the size that the original/placeholder image was. Any ideas?

Link to comment
Share on other sites

Just an update...I have tried using all the examples I've found on the site and cannot get it to resize the handles to fit the shape of the new movie clip. Even using update() and reset() don't do anything. I tried to destroy() the entire TransformManager_obj and recreate it from scratch and that didn't seem to do much either. Here is my code...As it is, it doesn't try to resize the handles to the size of the uploaded clip. Any suggestions? Thanks!

 

System.security.allowDomain("http://www.domain.com/");
import gs.TransformManager;
import flash.net.FileReference;

var manager_obj = new TransformManager({targetObjects:[test_mc], bounds:{xMin:0, xMax:650, yMin:0, yMax:400}, forceSelectionToFront:false, eventHandler:onAnyEvent});
manager_obj.addEventListener("move", onMove);

function onAnyEvent(event_obj:Object):Void {
trace("Action: "+event_obj.action+", MovieClip or TextField: "+event_obj.targetObject+", transformed?: "+event_obj.transformed);
}

function onMove(event_obj:Object):Void {
trace("Moved mc: "+event_obj.targetObject);
}

//Start Upload Scripting
var allTypes:Array = new Array();

var imageTypes:Object = new Object();
imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";

allTypes.push(imageTypes);

var listener:Object = new Object(); 

listener.onSelect = function(file:FileReference):Void {
log.addItem("File selected for upload");
filename_txt.text = file.name;
size.text = file.size;
type.text = file.type;
name.text = file.name;
datem.text = file.modificationDate;
datec.text = file.creationDate;
}

listener.onCancel = function(file:FileReference):Void {
   log.addItem("File upload/download cancelled by user");
}

listener.onOpen = function(file:FileReference):Void {
   log.addItem("onOpen: " + file.name);
}

listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
progress.mode = "manual";
progress.setProgress(bytesLoaded, bytesTotal);
log.addItem("bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
}

listener.onComplete = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
progress._visible = false;
log.addItem("File is uploaded");
loadMovie("/root/uploads/" + file.name, test_mc.mcImage);
}

listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
   log.addItem("HTTP Error :" + httpError);
   // Write code here to do corrective actions
}


listener.onIOError = function(file:FileReference):Void {
   log.addItem("An IO Error occured");
}

listener.onSecurityError = function(file:FileReference, errorString:String):Void {
  log.addItem("SecurityError: " + file.name + " ErrorString: " + errorString, "Error");
}

var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);

browse.onRelease = function()
{
upload.enabled = true;
fileRef.browse([{description: "Image files", extension: "*.jpg;*.gif;*.png", macType: "JPEG;jp2_;GIFF"}]);
}

upload.onRelease = function()
{
this.enabled = false;
/*** Change the URL here to point to the location where your upload.aspx resides **/
fileRef.upload("upload.aspx");
}

Link to comment
Share on other sites

This is almost always caused by the fact that the image hasn't fully instantiated when you call the update() or addItem(). Even when Flash fires the onLoadInit, sometimes it STILL doesn't accurately report the width/height which is essential for TransformManager. I'd recommend using a setTimeout() or TweenLite.delayedCall() to wait at least a few milliseconds AFTER the onLoadInit is called to call update() or addItem(). Try using trace() at that time to see if your image's width/height are reporting accurately.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×