views:

228

answers:

2

I am currently building a Flash AS 3.0 application that allows a user to load images into a container, move and scale them and the outputs to a DB. Once the user has uploaded and scaled the images, they are directed to an album viewer which gets the photos out of the DB and puts them into heads. The issue i am having is that once the images go into the viewer, the scaling and positining is not working correctly. The images will scale larger but i cannot shrink them from thrie original size.

I am using the following code to scale the images in the viewer:

headToLoad.width = headWidth;
  headToLoad.scaleY > headToLoad.scaleX ? headToLoad.scaleX = headToLoad.scaleY : headToLoad.scaleY = headToLoad.scaleX;
  headToLoad.x = xPosition;
  headToLoad.y = yPosition;

Any assistance would be great.

Thanks Justin

+1  A: 

I'm not sure what you are trying to do with that 2nd line, but try with this:

headToLoad.width = headWidth;
headToLoad.scaleY = headToLoad.scaleX;
Cay
I made a change and am sending the height as a variable now, but it is still not giving me the same output. Could the issue be the overall size of the movie?
sorry, I don't understand your comment :S
Cay
It's working now, the issue was related to the movie being resized before the data finished loading. causing it to distort the images.
+1  A: 

The function does what it should do. If you want a something that would constrict the size of a loaded image to a maximum width and height, mantaining the ratio, you could use something like this.

import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;

var maxWidth = 200;
var maxHeight = 300;

var headToLoad:Loader = new Loader();
headToLoad.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadCompleted);
addChild(headToLoad);
headToLoad.load(new URLRequest("picture.jpg"));

function onLoadCompleted(evt:Event) {
    var head = evt.target.loader; // or evt.target.content
    head.width = maxWidth;
    head.scaleY = head.scaleX;
    if (head.height > maxHeight) {
     head.height = maxHeight;
     head.scaleX = head.scaleY;
    }

    head.x = 100;
    head.y = 100;
}
Virusescu