flash cs5.5 AS3中的背景图像自动调整大小/缩放问题

时间:2012-01-28 17:02:17

标签: flash actionscript-3 flash-cs5

背景图片影片剪辑元件的名称为bg_main。这里的问题是img是在极右下方的浏览器窗口外对齐而不是居中。 这是截图链接:http://i40.tinypic.com/29cklds.jpg
这是下面的代码:

//set stage for FBF
stage.align = "TL";
stage.scaleMode = "noScale";

//define dynamic aspect ratios
var bg_mainHeight = bg_main.height / bg_main.width;
var bg_mainWidth = bg_main.width / bg_main.height;

//add event listener to the stage
stage.addEventListener(Event.RESIZE, sizeListener);

//conditional statement to account for various initial browswer sizes and proportions
function scaleProportional():void {
    if ((stage.stageHeight / stage.stageWidth) < bg_mainHeight) {
        bg_main.width = stage.stageWidth;
        bg_main.height = bg_mainHeight * bg_main.width;
    } else {
        bg_main.height = stage.stageHeight;
        bg_main.width = bg_mainWidth * bg_main.height;
    };  
}

//center bg_mainture on stage
function centerbg_main():void {
    bg_main.x = stage.stageWidth / 2;
    bg_main.y = stage.stageHeight / 2;
}

// make listener change bg_mainture size and center bg_mainture on browser resize
function sizeListener(e:Event):void {
    scaleProportional();
    centerbg_main();
}

//run initial locations and size
scaleProportional();
centerbg_main();

1 个答案:

答案 0 :(得分:1)

你看过动画片段的锚点在哪里吗?这可能是你的问题...