Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6379809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:11:09+00:00 2026-05-25T02:11:09+00:00

I have a UIComponent and inside it I put a loader (which loads an

  • 0

I have a UIComponent and inside it I put a loader (which loads an image file).

THE PROBLEM:
Even though I resize the UIComponent(to a square), it will still follow the size of the image in the loader. But when I resize the image in the loader, it will become stretched. What I want to do is have a container(UIComponent) that has a fixed square size and after the image has been loaded it will just fit in the dimention of the container without being stretched. Can anyone help me how to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:11:10+00:00Added an answer on May 25, 2026 at 2:11 am

    I’ve long been using this function to resize an image while preserving the aspect ratio:

    public function constraintResize(iSourceWidth:*, iSourceHeight:*, iTargetWidth:*, iTargetHeight:*, iFitSmallerDimension:*):* {
      if (iFitSmallerDimension == undefined) iFitSmallerDimension = false;
      if (iTargetWidth == 0 || iTargetHeight == 0) return;
      if (iSourceWidth == 0 || iSourceHeight == 0) return;
    
      var newWidth:*;
      var newHeight:*;
      var targetRatio:*;
      var sourceRatio:*;
    
      var output:* = { width:iSourceWidth, height:iSourceHeight };
    
      if (iSourceWidth <= iTargetWidth && iSourceHeight <= iTargetHeight) {
        if (iFitSmallerDimension) {
          targetRatio = iTargetWidth / iTargetHeight;
          sourceRatio = iSourceWidth / iSourceHeight;
          if (sourceRatio < targetRatio) {
            newHeight = iTargetHeight;
            newWidth = newHeight * sourceRatio;
          } else {
            newWidth = iTargetWidth;
            newHeight = newWidth / sourceRatio;
          } 
          output.width = newWidth
          output.height = newHeight
        }
    
        } else {
    
        targetRatio = iTargetWidth / iTargetHeight
        sourceRatio = iSourceWidth / iSourceHeight
        if (sourceRatio < targetRatio) {
          newHeight = iTargetHeight
          newWidth = newHeight * sourceRatio
        } else {
          newWidth = iTargetWidth
          newHeight = newWidth / sourceRatio
        }
    
        output.width = newWidth
        output.height = newHeight
      }
    
      return output
    }       
    

    The function will give you the ideal dimensions to fit source within target. So, in your case, you can use it that way:

    var s:* = constraintResize(loader.contentWidth, loader.contentHeight, yourSquare.width, yourSquare.height);
    loader.width = s.width;
    loader.height = s.height;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a graph component in AS3 which extends UIComponent. I created an
I have a Canvas in a Flex application which has items inside it that
I have a custom UIComponent , which renders ok when called directly from the
I have a UIComponent that sits on top of a grid visually, which is
I have a tag class which extends UIComponent and UIOutput. In this class I
I have a class which extends UIComponent and draws directly onto a Sprite contained
I have a NumericStepper declared as a UIComponent: <![CDATA[ private var component:UIComponent; component =
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have something like this: private var myVideo:Video; public var videoDisplay:UIComponent; ... videoDisplay.addChild(myVideo); ...
I have jsf application in which I have to use a facelet custom component

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.