我的应用程序的舞台大小为1000×500,2推出。本机窗口有系统镶边,这将永远是一个高一点几个像素。
怎么可能只允许本机窗口,以便始终保持2比例调整:舞台1宽高比
我希望以下code不工作:
包
{
//进口
进口flash.display.NativeWindow在;
进口flash.display.Sprite;
进口flash.display.StageAlign;
进口flash.display.StageScaleMode;
进口对象类型:flash.events.Event;
进口flash.events.NativeWindowBoundsEvent;
//类
[SWF(宽度=1000,高度=500,帧率=60的backgroundColor =#000000)
公共类WindowTest扩展Sprite
{
//常量
私有静态常量ASPECT_RATIO:数= 2.0; // 2:1宽高比
//构造函数
公共职能WindowTest()
{
在里面();
}
//初始化
私有函数的init():无效
{
在Stage.scaleMode = StageScaleMode.NO_SCALE时;
stage.align = StageAlign.TOP_LEFT;
stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZE,windowResizeEventHandler);
}
//窗口resize事件处理函数
私有函数windowResizeEventHandler(EVT:NativeWindowBoundsEvent):无效
{
evt.currentTarget.width = stage.stageHeight * ASPECT_RATIO;
}
}
}
解决方案
prevent默认事件,并手动调整窗口大小: 编辑:看来,使空气计算奇怪的是宽度,所以prevent闪烁在一开始设置窗口大小为1050x500的SWF标签
包{
进口flash.display.Sprite;
进口flash.display.StageAlign;
进口flash.display.StageScaleMode;
进口对象类型:flash.events.Event;
进口flash.events.NativeWindowBoundsEvent;
//类
[SWF(宽度=1000,高度=500,帧率=60的backgroundColor =#000000)
公共类airtest扩展Sprite
{
//常量
私有静态常量ASPECT_RATIO:数= 2.0; // 2:1宽高比
//构造函数
公共职能airtest()
{
在里面();
}
//初始化
私有函数的init():无效
{
在Stage.scaleMode = StageScaleMode.NO_SCALE时;
stage.align = StageAlign.TOP_LEFT;
stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZING,windowResizeEventHandler);
}
私有函数windowResizeEventHandler(EVT:NativeWindowBoundsEvent):无效
{
EVT。preventDefault()
如果(evt.beforeBounds.width!= evt.afterBounds.width){//用户调整宽度
evt.currentTarget.width = evt.afterBounds.width
evt.currentTarget.height = evt.afterBounds.width / ASPECT_RATIO;
}否则,如果(evt.beforeBounds.height!= evt.afterBounds.height){
evt.currentTarget.height = evt.afterBounds.height
evt.currentTarget.width = evt.afterBounds.height * ASPECT_RATIO;
}
}
}
}
my application launches with the stage size of 1000 x 500, 2:1 aspect ratio. the native window has system chrome, which will always be a little taller by a few pixels.
how is it possible to only permit a native window to resize proportionately in order to always maintain the 2:1 aspect ratio of the stage?
the following code doesn't work as i expect:
package
{
//Imports
import flash.display.NativeWindow;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.NativeWindowBoundsEvent;
//Class
[SWF(width="1000", height="500", frameRate="60", backgroundColor="#000000")]
public class WindowTest extends Sprite
{
//Constants
private static const ASPECT_RATIO:Number = 2.0; //2:1 Aspect Ratio
//Constructor
public function WindowTest()
{
init();
}
//Initialization
private function init():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZE, windowResizeEventHandler);
}
//Window Resize Event Handler
private function windowResizeEventHandler(evt:NativeWindowBoundsEvent):void
{
evt.currentTarget.width = stage.stageHeight * ASPECT_RATIO;
}
}
}
解决方案
prevent the default event, and resize the window manually: EDIT: it seems, that air is calculating the width in a weird way, so to prevent flickering in the beginning set the window size to 1050x500 in the SWF tag.
package{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.NativeWindowBoundsEvent;
//Class
[SWF(width="1000", height="500", frameRate="60", backgroundColor="#000000")]
public class airtest extends Sprite
{
//Constants
private static const ASPECT_RATIO:Number = 2.0; //2:1 Aspect Ratio
//Constructor
public function airtest()
{
init();
}
//Initialization
private function init():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZING, windowResizeEventHandler);
}
private function windowResizeEventHandler(evt:NativeWindowBoundsEvent):void
{
evt.preventDefault()
if (evt.beforeBounds.width != evt.afterBounds.width){//user resizes width
evt.currentTarget.width = evt.afterBounds.width
evt.currentTarget.height = evt.afterBounds.width/ASPECT_RATIO;
} else if (evt.beforeBounds.height != evt.afterBounds.height){
evt.currentTarget.height = evt.afterBounds.height
evt.currentTarget.width = evt.afterBounds.height*ASPECT_RATIO;
}
}
}
}