调整大小阶段时保持对象位置

时间:2010-11-04 18:37:31

标签: flash actionscript-3 resize

我试图将一个物体保持在屏幕的某个位置,而不是调整它(使用舞台)

function Resize(e:Event = null):void
{
    if ((stage.stageWidth)/(stage.stageHeight) > fundos.width/fundos.height)
    {
        fundos.width = stage.stageWidth;
        fundos.scaleY = fundos.scaleX;
    }
    else
    {
        fundos.height = stage.stageHeight;
        fundos.scaleX = fundos.scaleY;
    }
    fundos.x = (stage.stageWidth - fundos.width) /2;
    fundos.y = (stage.stageHeight - fundos.height) /2;  

    setas.x = (stage.stageWidth - setas.width + 505) /2;
    setas.y = (stage.stageHeight - setas.height);   
}

我的舞台正在调整所有ok(保持宽高比)并且我试图添加一个nav img,它将保持与我调整浏览器屏幕大小相同的位置

我该怎么做?

2 个答案:

答案 0 :(得分:2)

使用

收听舞台活动Event.RESIZE
stage.addEventListener(flash.events.Event.RESIZE, resizeHandler);

当用户以任何方式调整舞台大小时调度它(放大浏览器,调整大小

在事件处理程序中,运行您提供给我们的代码段。


另外,不要忘记使用

stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;

或者内容将调整大小。

享受。

答案 1 :(得分:1)

这是一个例子。 Blob精灵是保持初始位置(50,50)的对象

package {
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.display.Sprite;

[SWF(backgroundColor="#00FF00", frameRate="31")]
public class Application extends Sprite {

    private var blob:Sprite;


    public function Application() {
        if(stage) {
            init();
        } else {
            addEventListener(Event.ADDED_TO_STAGE, init);
        }
    }

    private function init() : void {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;
        addEventListener(Event.RESIZE, resize);

        blob = new Sprite();
        blob.graphics.beginFill(0x000000);
        blob.graphics.drawRect(50, 50, 200, 100);
        blob.graphics.endFill();
        addChild(blob);
    }

    private function resize(event : Event) : void {
        // Do nothing on blob's Object
    }

}

}

舞台调整好(比例),但即使你设置(在你的嵌入中)swf宽度和高度为100%

,blob也会保持位置
相关问题