Skip to main content
Inspiring
Apr 20, 2019 10:41 PM UTC
Answered

New NativeWindow with owner defined fails to display

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 is closed to new replies. Start a new post to keep the conversation going.
el111Correct answer
Legend
Apr 21, 2019 12:36 PM UTC

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

2 replies

el111Correct answer
Legend
Apr 21, 2019 12:36 PM UTC

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

Translate
kamckngAuthor
Inspiring
Apr 21, 2019 12:48 PM UTC

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

Translate