Solved

Liquid Scaling Problem

Posted on 2011-03-06
6
321 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
  • 4
  • 2
6 Comments
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
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 what frame rate is, how to control it and what effect it has on the video.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now