How to create a new Window?

Good idea

private function onClick(evt:MouseEvent):Void
{
var secondWindow = new openfl.display.Window ();
secondWindow.width = 400;
secondWindow.height = 300;
secondWindow.x = 100;
secondWindow.y = 100;
secondWindow.resizable = true;
Lib.current.stage.application.addWindow (secondWindow);
//secondWindow.stage.addChild(_bgSprite);
secondWindow.renderer.onRender.add(winRenderer);
}

private function winRenderer(): Void
{
var secondWindow = new openfl.display.Window ();

  secondWindow.stage.addChild(_bgSprite);

}

I can not understand why openfl.display.Window() always crashed if i open new window than application stopped to work. How do i fix it? I really want secound window. :frowning:

I apologize, I was pointing in the wrong direction.

This is working for me:

package;


import openfl.display.Sprite;
import openfl.display.Window;
import openfl.events.MouseEvent;


class Main extends Sprite {
	
	
	public function new () {
		
		super ();
		
		var sprite = new Sprite ();
		sprite.graphics.beginFill (0xFF0000);
		sprite.graphics.drawRect (0, 0, 100, 100);
		addChild (sprite);
		
		sprite.addEventListener (MouseEvent.MOUSE_DOWN, function (_) {
			
			var window = new Window ();
			window.width = 400;
			window.height = 300;
			
			window.onCreate.add (function () {
				
				window.stage.color = Std.int (Math.random () * 0xFFFFFF);
				
			});
			
			stage.application.createWindow (window);
			
		});
		
	}
	
	
}
1 Like

Nice improved code but if i click second window and close secoud window again and i open again - than application crashed. Ow!

That is so close workingā€¦

I think you need fix lime framework and openfl doesnā€™t crash again if you open again secoud window than it happens

Youā€™re right ā€“ I just found out that the window.renderer was not getting removed on close, I just updated Lime and it appears to be stable, but let me know what happens on your side, thanks :slight_smile:

Hello @singmajesty,

I try debug version of build - now it found ā€œNull Object Referenceā€
If you open second window and application shows messagebox ā€œNull Object Referenceā€.

If i copy of your code for example:

class Main extends Sprite {

public function new () {

  super ();
  
  var sprite = new Sprite ();
  sprite.graphics.beginFill (0xFF0000);
  sprite.graphics.drawRect (0, 0, 100, 100);
  addChild (sprite);
  
  sprite.addEventListener (MouseEvent.MOUSE_DOWN, function (_) {
  	
  	var window = new Window ();
  	window.width = 400;
  	window.height = 300;
  	
  	window.renderer.onRender.add (function () {
  		
  		window.stage.color = Std.int (Math.random () * 0xFFFFFF);
  		
  	});
  	
  	stage.application.createWindow (window);
  	
  });

}

}

It means shows error message ā€œNull Object Referenceā€

I have tried fixed ā€œonCreateā€ in window.onCreate but it shows after opening second window and shows error message ā€œNull Object Referenceā€

private function onClick(evt:MouseEvent):Void
{
var window = new Window ();
window.width = 400;
window.height = 300;

  window.onCreate.add (function () {
  	
  	window.stage.color = Std.int (Math.random () * 0xFFFFFF);
  	//window.stage.addChild(_bgSprite);
  	
  });
  
  Lib.current.stage.application.createWindow (window);

}

Youā€™re right.

// Edit
Possible use with NME?? I donā€™t understand what do I with nme.app.Window

But it is hard to understand
For what beginRender and endRender???
nme.Lib.create(); sees like lime but it sees inFrameLoaded what is that?
It has onRender and onCreate but i can not get inFrameloaded:Dymanic.

Thanks!

If you import lime.app.Window, it will not have a stage property. openfl.display.Window extends lime.app.Window with automatic stage creation per window.

As for NME, I donā€™t really know ā€“ the Lime API is totally unrelated to the NME API, Iā€™m not sure what nme.app.Window does.

I am now - Thanks for working solution - your code was correct to 3.2.1 That is why you have fixed renderer.add ā€¦ I say thanks for fixedā€¦ I will work nowā€¦

// Edit:
Sadly no types like Adobe Air :frowning: types example standard, lightweight or utility and window should always front or back. Please add new features Windowā€™s featuresā€¦ Thanks!

PS: I found lime-gtk wow nice but I didnā€™t test it

If i use Haxe-UI Core example with windowing but it is possible because user clicks button and application opens window ( just use modalable mode like owned window or 2. window need to make complete than back to main window like creating application from Visual Studio XXXX )

I hope you have to prepare new features like Adobe Airā€™s NativeWindow features. Thanks for next release Lime 3.3 and Openfl 4.3??

My specs:

openFl : 8.3.0
lime: 6.4.0
:::::::::::::::::::::::::::::::::::::::::

@singmajesty

Hello Joshua,

I am sorry, to open this topic again. But I am not getting along with it. I am trying for two days in vainā€¦

I have done as you said (see above).

My problem is, that the displayObjects arenā€™t displayed and the event onRender is not thrown, so the renderCallBackFn() is not executed.

I have had to add

     var renderer : Renderer = new Renderer( window );

to your code example (otherwise the window.renderer.onRender.add () would throw a null-pointer exception).

I have noticed that by default the renderer is set to cairo. I have even got the renderer.type and the renderer.context from the Lib.current [ā€¦] and I have set in window.renderer accordingly.

It didnā€™t change anything.

I only get a white window with no displayObjects shown. But the displayObjects can be found in within the correct hierarchy at Lib.current.

I donā€™t know what to do else.

I am thankful for any suggestion.

Kind regards
Arnim

Can you try Lime 7.0?

Lime 6.x was more complicated for creating a new window, I think you need to at least call createWindow as well as addWindow, and additional wiring might be needed

Thanks for your reply.

Updating to Lime 7.0 still is a problem, as I havenā€™t got a reply of Eric Brishton, yet, concerning the issue with the hxcpp-debugger interference with the latest Lime/ OpenFl version.

Of cause, I could comment the critical line out, that starts the debugger out and set the OpenFl/ Lime version up and down, when ever I have to use the debugger or the second window. Using both at a time, would then be impossible.

Anyhow, I would prefer the most simple solution, even if it is only a workaround for the time being.

How would I use createWindow() then? Is it meant to be a solution for my constellation (Lime 6.4.0)?

I have tried to implement

       Lib.current.stage.application.createWindow( window );
       Lib.current.stage.application.addWindow( window );

like this. I have simply added addWindow() underneath createWindow() But regrettably itā€™s apparently not as simple as that.

Kind regards
Arnim

Actually, looking at sources, it looks like it works like this:

var window = new Window (windowConfig);
createWindow (window);

It might not work without a full window config (pre-Lime 7), though:

1 Like

Thank you for this solution.

Iā€™ll have to take a closer look tomorrow.

Anyhow, it did not work.

I do not want to waste your time, no more. I assume, that finding the perfect workaround, would take much more efforts. I will wait until the debugger will be fixed (which hopefully will be soon). Then I can update to the current Lime and OpenFl version without any disturbances.

At the moment the content of the second window is represented in a sprite. For the time being, this will be my workaround.

Thank you for your efforts anyway.

Kind regards
Arnim