PDA

View Full Version : As3 Resize Background



baddot
July 20th, 2009, 01:11 PM
hi can i know how do i do this ?

http://artluvr.com/files/xml_based_background_image_rotator/RotatingBackground.html

my code is this it dun seems to work it out for me


stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.DisplayObject;
import flash.events.Event;

stage.addEventListener(Event.RESIZE, resizeHandler);

function setBackground() {
var reg2 = stage.stageWidth/2;
var reg1 = stage.stageHeight/2;
bg_mc.x = reg2;
bg_mc.y = reg1;
bg_mc.width = stage.stageWidth;
bg_mc.height = stage.stageHeight;
//bg_mc.scaleX <= bg_mc.scaleY ? (bg_mc.scaleX = bg_mc.scaleY) : (bg_mc.scaleY = bg_mc.scaleX);
}

setBackground();
function resizeHandler(event:Event):void {
setBackground();
}

test1
July 20th, 2009, 01:15 PM
I'm not really sure what part isn't working for you but if you're trying to center an object after the stage is resized you have to take into account that objects width as well as the stage width. For instance you have stage.stageWidth/2 for the x but it should really be (stage.stageWidth/2)-(bg_mc.width/2) as this takes into account the width of the object as well. Again, not sure what the issue is but hope that helps.

baddot
July 20th, 2009, 01:26 PM
what i mean i dont want the pictures to be reshapped till out of form as for the link the picture did not change its form

creatify
July 20th, 2009, 01:29 PM
I'm running out, but can post solution after a bit - but if anyone else wants to help, you're basically just looking to "constrain the proportions" of your image. And, you want it to always fill the entire browser window, without the image becoming too small width/height so the background appears....

baddot
July 20th, 2009, 01:30 PM
I'm running out, but can post solution after a bit - but if anyone else wants to help, you're basically just looking to "constrain the proportions" of your image. And, you want it to always fill the entire browser window, without the image becoming too small width/height so the background appears....

erm what should i have to do ?

creatify
July 20th, 2009, 01:41 PM
erm what should i have to do ?

see attached....

baddot
July 20th, 2009, 01:47 PM
see attached....


thank you !! but why are the codes totally different from it? i mean the one i posted ?

baddot
July 20th, 2009, 02:29 PM
hmm can i know how do i convert it to xml auto load ?

i have my script on this but i dun know how to implemend it in

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("bg.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);