Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Liquid Scaling Problem

Posted on 2011-03-06
6
Medium Priority
?
359 Views
Last Modified: 2012-05-11
I have a website that design in Flash using Actionscipt 2.0 and I'm trying to use liquid (dynamic) scaling for the background. It almost works perfectly, except that depending on how you stretching the window size, the height won't always scale 100% - it will just have a large margin on the top and bottom all of a sudden.

This is driving me nuts, it's the only thing I can't quite get to work right on the site.

This is what I have in flash, "background" being my background layer.

 
Stage.scaleMode = "noscale";
Stage.align = "C";

//----- Background Scale --------
var StageWidth = 950;
var StageHeight = 576;
function scaleBackground()
{
   if (Stage.width > Stage.height) {
      background._width = Stage.width;
      background._yscale = background._xscale;
   } else {
      background._height = Stage.height;
      background._xscale = background._yscale;
   }
   background._x = (StageWidth - background._width) / 2;
   background._y = (StageHeight - background._height) / 2;
}
Stage.addListener(this);
this.onResize = scaleBackground;
scaleBackground();

Open in new window


This is what I have in HTML body.
 
<body bgcolor="#000000" scroll="no" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bottommargin="0" rightmargin="0" >

Open in new window


You can see an example of what I'm working with here. It's important to note that the background in the website can swap colors like this test and that I need all the elements in my stage to stage in a fixed location to one another (notice the spacing between the plus and minus doesn't change, and the stage is centered in the browser):
http://colorrot.com/test.html

Try messing with it by scaling the browser window left to right and you'll see the clipping.

Is this even possible using actionscript? I'm considering looking into using javascript to make the swf hover over an html background like a lot of those pop-up ads. However that has its own challenges due to my dynamic background and I'm avoiding it if possible.

I've also attached the test fla file test.fla and it's html file test.html
0
Comment
Question by:colorrot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 2000 total points
ID: 35056447
Well the problem is that you are scalling while preserving the aspect-ratio of your image. This means if your image is twice as high then it's twice as wide.

You can think of your algorithm being the following .... take your image and scale it so it fills the height or the width exactly with as little wasted area as possible. This wasted area is what's driving you mad.

In order to resolve this, you would have to allow your image being scaled independently which could result in ugly results.
Another solution would be to fill up the wasted area with something looking the same way as your image. In your case you would draw a 50% black and 50 white rectangle behind the image and place the image in front of this.
0
 

Author Comment

by:colorrot
ID: 35142893
Drawing my background larger does not change anything. I more than doubled it, but when it's exported flash cuts its edges at the stage size. This might work if I was exporting it as a standalone presentation, but not for a website.

What I was hoping to have was the background layer(which is just the split black and white image) independently scale. That is what the action-script is suppose to do, which would work flawlessly as is if the stage was aligned to the top-left or the top-right, not centered in the page.

The question is, how do I get the height-wasted-space to be filled? Is there no way to just have one layer/image stretch to the size of browser?
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35146055
I was talking of the background of your stage, not the background of the page that is embedding the swf.
But when I have a look at your page, it seems you figgured it out. Is your issue resolved now?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:colorrot
ID: 35153039
Ahh I got it working! I was using an old algorithm code in my actual website. Yes yes yes. Thank you, you  win the big prize that has taken me months to figure out.

I'm attaching the proper code and file for anyone who's interest for future reference.

 test.fla
0
 

Author Comment

by:colorrot
ID: 35153053
Here's the necessary action script 2.0 code:
 
Stage.scaleMode = "noscale";
Stage.align = "C";

//modified function that works if you extended you background layer beyond your stage. I recommend using 2000x2000 or larger.
   if (Stage.width > Stage.height) {
      background.left_bg._width = Stage.width;
      background.left_bg._yscale = background.left_bg._xscale;
	  background.right_bg._width = Stage.width;
      background.right_bg._yscale = background.right_bg._xscale;
   } else { 
      background.left_bg._height = Stage.height;
	  background.left_bg._xscale = background.left_bg._yscale;
	  background.right_bg._height = Stage.height;
      background.right_bg._xscale = background.right_bg._yscale;
   }
   	  background.left_bg._x = (StageWidth - background.left._width) / 2;
	  background.left_bg._y = (StageHeight - background.left._height) / 2;
      background.right_bg._x = (StageWidth - background.right._width) / 2;
      background.right_bg._y = (StageHeight - background.right._height) / 2;
}


Stage.addListener(this);
this.onResize = scaleBackground;
scaleBackground();

Open in new window

0
 

Author Closing Comment

by:colorrot
ID: 35153056
Worked!
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Viewers will learn how to use Macros for greater control over Rack parameters in Ableton Live. Group devices into a Rack by selecting them and pressing Command-G (Ctrl-G on PC): Control-click (Right Click on PC) a parameter to access pop-up menu, …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question