Skip to main content
dmdbro21
Participant
August 18, 2011
Question

Please help! How do I resize external images loaded into uiLoader?

  • August 18, 2011
  • 1 reply
  • 2308 views

Please help I've been researching this topic for like 2 days straight and it is driving me insane because I can't seem to find a specific answer for what I'm trying to achieve and I know it can be done because I've seen end results on the web. Here is what I'm doing:

1. I created a simple museum gallery with 3 portraits hanging on the wall

2. Inside the museum portraits I created 3 different uiLoaders with a black background

3. I gave all 3 uiLoaders their own unique movieClip names

3. Inside each uiLoader will be a loaded external image via a URL

4. I DO NOT want to resize the uiLoaders - I want to scale the external images proportionately to fit inside the entire contents of the uiLoaders and still remain centered

Here is a sample screenshot of what is currently happening - http://jaegerandroar.com/gallery/flashExample.png

Here is a screenshot of what I want to happen - http://jaegerandroar.com/gallery/desiredResult.png

Here is a screenshot in Flash before the code is executed - http://jaegerandroar.com/gallery/screenshot.png

As you can see currently the 3 random external images are loaded perfectly inside the uiLoaders but you see black background and I want the photos to fit the entire contents of the uiLoaders yet still remain proportionate.

Here is the complete code I have so far:

var myImage:String = "http://a6.sphotos.ak.fbcdn.net/hphotos-ak-snc6/206793_10150223778295255_528440254_8997851_1941858_n.jpg";
var request:URLRequest = new URLRequest(myImage);
uiLoader.scaleContent = true;
uiLoader.load(request);

var myImageOne:String = "http://jaegerandroar.com/roses/ChryslerImperial_051711.jpg";
var request1:URLRequest = new URLRequest(myImageOne);
uiLoaderOne.scaleContent = true;
uiLoaderOne.load(request1);

var myImageTwo:String = "http://jaegerandroar.com/fullsail/tank_03.jpg";
var request2:URLRequest = new URLRequest(myImageTwo);
uiLoaderTwo.scaleContent = true;
uiLoaderTwo.load(request2);

Any suggestions to make this code work would be most appreciated. Thanks

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
August 18, 2011

You need to wait until the image is loaded before you can attempt to adjust its size.  Also, you need to set the scaleContent to false if you want to gain control of setting the loaded content size.  Here's and example that changes the size of the image to match the size of the loader, though you might want something else based on what you explained...

var myImageOne:String = "http://jaegerandroar.com/roses/ChryslerImperial_051711.jpg";
var request1:URLRequest = new URLRequest(myImageOne);
uiLoaderOne.scaleContent = false;
uiLoaderOne.addEventListener(Event.COMPLETE, resizeIt);
uiLoaderOne.load(request1);

function resizeIt(evt:Event):void {
var ldr:UILoader = UILoader(evt.target);
var image:Bitmap = Bitmap(ldr.content);
image.width = ldr.width;
image.height = ldr.height;
}

The resizeIt function can be shared by all three UILoaders since it handles the objects generically.

Note: I tried looking at the first example you linked and my browser brought up a warning regarding trying to access a hostile site.  It was not the site named in the link, but in any case, I had no desire to test the rest.

dmdbro21
dmdbro21Author
Participant
August 18, 2011

Ned thank you for replying!

When I tried your code it ended up stretching the photos to fit the entire contents of the uiLoader which is not the end result I'm shooting for .

It ended up looking like this - http://jaegerandroar.com/graphics/undesiredStretch.png

I'm trying to get the photos to scale proportionately inside the uiLoaders and look more like this - http://jaegerandroar.com/graphics/desiredResult.png

Sorry about the warning on the links - I can assure you that the links are 100% safe. I'm hosting the images directly from my portfolio website. I went ahead and removed the Facebook url image in my Flash code so here is the simplified code again  -

var myImage:String = "http://jaegerandroar.com/graphics/April.jpg";
var request:URLRequest = new URLRequest(myImage);
uiLoader.scaleContent = true;
uiLoader.load(request);

var myImageOne:String = "http://jaegerandroar.com/roses/ChryslerImperial_051711.jpg";
var request1:URLRequest = new URLRequest(myImageOne);
uiLoaderOne.scaleContent = true;
uiLoaderOne.load(request1);

var myImageTwo:String = "http://jaegerandroar.com/fullsail/tank_03.jpg";
var request2:URLRequest = new URLRequest(myImageTwo);
uiLoaderTwo.scaleContent = true;
uiLoaderTwo.load(request2);

Does anyone know how to get this to work? I wanna throw my computer out the window

Ned Murphy
Legend
August 18, 2011

I told you it would not be what you want, but it did answer your question of what you need to do to resize an image inside a UILoader.  You will have to rework the math to try to get what you are after, though I don't know that a UILoader defines boundaries for what it contains, so you may need to mask the UILoader as well so that the overflow doesn't show.