Skip to main content
Inspiring
April 20, 2019
Answered

New NativeWindow with owner defined fails to display

  • April 20, 2019
  • 1 reply
  • 782 views

This seems like a no-brainer, but I'm stumped over the simplest thing. Am I misunderstanding the owner property?

I had an issue in my application creating a new NativeWindow with the owner defined. The window would not show up when activate() was invoked on it. So I created the simplest hello world application to ensure it wasn't something in my code and it still doesn't show. Can anyone help me figure out what I'm missing or explain the owner property as to why it's not working? If I comment out the line setting the owner on the NativeWindowInitOptions then the new window displays as expected.

package
{

   import flash.display.NativeWindow;
   import flash.display.NativeWindowInitOptions;
   import flash.display.Sprite;
   import flash.text.TextField;

   public class Main extends Sprite

   {
   public function Main()
  {
   var textField:TextField = new TextField();
   textField.text = "Hello, World";
   addChild(textField);

   var initOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
   initOptions.owner = stage.nativeWindow;

   new NativeWindow(initOptions).activate();
   }
  }
}

This topic has been closed for replies.
Correct answer el111

package {

import flash.display.NativeWindow;
import flash.display.NativeWindowInitOptions;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;

public class Main extends Sprite {
    public function Main() {
        var textField:TextField = new TextField();
        textField.text = "Hello, World";
        addChild(textField);
        this.addEventListener(Event.ADDED, onAdded)
    }

    private function onAdded(event:Event):void {
        stage.nativeWindow.activate(); //activate the stage window before setting as owner
        var initOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
        initOptions.owner = stage.nativeWindow;
        var newWindow:NativeWindow = new NativeWindow(initOptions);
        newWindow.width = 200;
        newWindow.height = 200;
        newWindow.activate();
    }
}
}

1 reply

el111Correct answer
Legend
April 21, 2019

package {

import flash.display.NativeWindow;
import flash.display.NativeWindowInitOptions;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;

public class Main extends Sprite {
    public function Main() {
        var textField:TextField = new TextField();
        textField.text = "Hello, World";
        addChild(textField);
        this.addEventListener(Event.ADDED, onAdded)
    }

    private function onAdded(event:Event):void {
        stage.nativeWindow.activate(); //activate the stage window before setting as owner
        var initOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
        initOptions.owner = stage.nativeWindow;
        var newWindow:NativeWindow = new NativeWindow(initOptions);
        newWindow.width = 200;
        newWindow.height = 200;
        newWindow.activate();
    }
}
}

kamckngAuthor
Inspiring
April 21, 2019

Thank you, that worked like a charm.

Is there any documentation anywhere that says this needs to be done? That's a pretty big oversight if not, but I'm not sure if I just wasn't seeing it or reading something right.

Thanks again for your help,

Kyle