无法调整内容大小以适应AIR中的新NativeWindow

时间:2010-12-20 13:08:28

标签: actionscript-3 air stage nativewindow

我正在尝试创建一个弹出窗口类,它将获取一个内容DisaplyObject,并弹出并显示它本身,但我正在开始将内容的大小与窗口相匹配,反之亦然。我想也许窗口可能不显示所有的舞台或什么东西?!

内容太大了......并且超出界限。

这是代码:

public class SubWindow extends NativeWindow{

 public function SubWindow() 
  {

   var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
     windowOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
     windowOptions.type = NativeWindowType.UTILITY;
   windowOptions.resizable = false;
   super(windowOptions);
   this.stage.align = StageAlign.TOP_LEFT;
     width = 400;
     height = 400;
     title = "Are you sure?";
   alwaysInFront = true;
   activate();
   visible = false;
   addEventListener(Event.CLOSING, closeWindow, false, 0, true); 
  }

  public function closeWindow(e:Event)
  {
   e.stopImmediatePropagation();
         e.stopPropagation();
         e.preventDefault();
   visible = false;
  }

  public function setContent(cont:DisplayObject)
  {
   visible = true;
   //this.width = stage.stageWidth;
   //this.height = stage.stageHeight;
   trace(cont.getBounds(stage), width, height, stage.stageWidth,stage.stageHeight);


   cont.height = stage.stageHeight;
   cont.width = stage.stageWidth;
   cont.x = cont.y = 0;
   this.stage.addChild(cont);
   trace(cont.width, width, height, stage.stageWidth,stage.stageHeight);
  }
 }

谢谢, MIK

2 个答案:

答案 0 :(得分:0)

现在我觉得我已经解决了!

首先创建您的内容:

var myContent:MyCustomContentClass = new MyCustomContentClass();

然后创建窗口并设置大小和位置

var myWindow:NativeWindow = new NativeWindow();
myWindow.stage.align = StageAlign.TOP_LEFT;
myWindow.width = myContent.width;
myWindow.height = myContent.height

并将比例模式设置为无比例:

myWindow.stage.scaleMode = StageScaleMode.NO_SCALE;

然后添加内容

myWindow.stage.addChild(myContent); 
myWindow.activate();

在osX上运行时我还有一些小问题,但我认为这与系统chrome的大小有关。

答案 1 :(得分:0)

也许因为原生的Windows chrome尺寸不同。试试这个:

http://tedpatrick.com/2009/12/23/sizing-air-nativewindow-to-stage/