Skip to main content
Participating Frequently
April 17, 2007
Answered

Scale/Fit to Window code

  • April 17, 2007
  • 2 replies
  • 354 views
1. I have a viewable area of 400 x 400.
2. A movie clip's width and height dynamically change.
3. I need an equation that gives me the scale percentage (up or down, and proportionally) to fit the movieclip within the viewable area.

Pretty simple, but I'm terrible at math. Can someone please help?

Thanks in advance!
This topic has been closed for replies.
Correct answer Greg Dove
I had a situation where I had something similar.

Quick description:
Loading a clip into another movieclip called imageHolder.
Inside imageHolder is another clip (which would be the equivalent of your 400x400 area. This clip is called imageBackdrop. In my scenario this could change size and shape at different times.

I load other images/clips into imageHolder. In the onLoadInit handler, I have code like this:

imageLoadListener.onLoadInit = function(target_mc:MovieClip){

...etc:

2 replies

Inspiring
April 17, 2007
Or the quick and easy way to do it... is to use a Loader component with scaleContent = true.
Greg DoveCorrect answer
Inspiring
April 17, 2007
I had a situation where I had something similar.

Quick description:
Loading a clip into another movieclip called imageHolder.
Inside imageHolder is another clip (which would be the equivalent of your 400x400 area. This clip is called imageBackdrop. In my scenario this could change size and shape at different times.

I load other images/clips into imageHolder. In the onLoadInit handler, I have code like this:

imageLoadListener.onLoadInit = function(target_mc:MovieClip){

...etc:
jencarnacAuthor
Participating Frequently
April 17, 2007
Perfect! I prefer the first way because I added animation to the scaling using the tween class. Thanks GWD!
Inspiring
April 17, 2007
You're welcome.