2010-11-04 33 views
0

我尝试保持物体在屏幕上的某一位置时,没有(与阶段)保持物体位置调整阶段

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); 
} 

我的舞台是在调整都可以过调整其大小(保持宽高比)和即时尝试添加一个导航img将保持在我调整浏览器屏幕大小相同的位置

我该怎么做?

+0

你想保持对象在相同的地方?如果您拥有绝对布局,并且指定组件的x和y坐标以及宽度和高度属性,则它将保留在那里,并通过任意大小的调整大小保持该大小。我不明白你的问题。 – Robusto 2010-11-04 18:45:07

回答

2

听阶段事件Event.RESIZE与

stage.addEventListener(flash.events.Event.RESIZE, resizeHandler); 

当用户调整阶段,它的派出,以任何方式(在浏览器缩放,在

在事件处理程序调整,运行代码片段你给我们。


另外,不要忘记使用

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

或者内容将被调整大小。

享受。

1

这里是一个例子。斑点精灵是保持初始位置(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%