•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Graphics and Multimedia section within the Web Development category of DaniWeb, a massive community of 402,053 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,466 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Graphics and Multimedia advertiser: Programming Forums
Views: 396 | Replies: 1
![]() |
•
•
Join Date: Feb 2006
Location: Leeds innit
Posts: 29
Reputation:
Rep Power: 3
Solved Threads: 0
Hi, i've been trying to figure this out all morning with no luck, i'm trying to create a site that can dynamically resize elements depending on the size of the browser, or if someone drags and resizes the window displaying the page.
The problem i'm having right now though is getting a background image to resize while keeping it's aspect ratio, here is my code:
I've used google to try find an answer and got pretty close, however all that happens is that when the window is dragged down the photo squashes upwards and when the window is dragged up the photo stretches down past the end of the window
Does anyone know what i am doing wrong?
The problem i'm having right now though is getting a background image to resize while keeping it's aspect ratio, here is my code:
Stage.align = "TL";
Stage.scaleMode = "noScale";
//Site content
stretch_bar._width = Stage.width;
//Define the role of the listener
sizeListener = new Object();
sizeListener.onResize = function(){
//Get the new dimensions of the stage:
var stageWidth:Number = Math.round(Stage.width);
var stageHeight:Number = Math.round(Stage.height);
trace ("stage size is now " + Stage.width + " px by " + Stage.height + " px");
//This is what is giving me the trouble, but i don't know what i'm doing wrong
var aspectratio = Stage.width/Stage.height;
photo_01._yscale = aspectratio * photo_01._xscale;
stretch_bar._width = Stage.width;
}
Stage.addListener(sizeListener);I've used google to try find an answer and got pretty close, however all that happens is that when the window is dragged down the photo squashes upwards and when the window is dragged up the photo stretches down past the end of the window

Does anyone know what i am doing wrong?
![]() |
•
•
•
•
•
•
•
•
DaniWeb Graphics and Multimedia Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: CS3 Madness
- Next Thread: Flash8-webcam motion detection



Linear Mode