Can't resize content to fit a new NativeWindow in AIR

1.5k Views Asked by At

I'm trying to make a popup window class which will get a content DisaplyObject, and popup and display it in itself, but I'm cracking my head with matching the size of the content to the window or vise versa... I think that maybe the window is not display all of the stage or something ?!

The content get way too big..and goes out of bounds.

here is the code :

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

Thanks, Mik

2

There are 2 best solutions below

0
On

Now I've solved it i think!

First create your content:

var myContent:MyCustomContentClass = new MyCustomContentClass();

Then create your window and set size and position

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

And set scale mode to no scale:

myWindow.stage.scaleMode = StageScaleMode.NO_SCALE;

And then add the content

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

I still have some minor ssues when running on osX, but I think is has to do with the size of the system chrome.

0
On

Maybe beacause native windows chrome dimension is different. Try this way:

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