Haxe/openfl giving blank screens ad output

i have this haxe code but whatever i do in haxe and openfl, the output is always a window with a white screen. i use the latest versions of haxe, openfl and lime. i tried html5 and windows building but both of them just doesn’t work.

import openfl.display.Sprite;
import openfl.text.TextField;
import openfl.text.TextFormat;
import openfl.events.MouseEvent;

class Main extends Sprite {
    
    private var textField:TextField;
    
    public function new() {
        super();
        
        // Create a text field
        textField = new TextField();
        textField.text = "Click a button!";
        textField.width = 200;
        textField.height = 40;
        
        // Create a text format (optional)
        var textFormat = new TextFormat("Arial", 20, 0x000000);
        textField.defaultTextFormat = textFormat;
        
        // Position the text field
        textField.x = 50;
        textField.y = 50;
        
        // Add the text field to the stage
        addChild(textField);
        
        // Create buttons
        var button1 = createButton("Button 1", 50, 100);
        var button2 = createButton("Button 2", 50, 150);
        
        // Add event listeners to buttons
        button1.addEventListener(MouseEvent.CLICK, onClickButton1);
        button2.addEventListener(MouseEvent.CLICK, onClickButton2);
    }
    
    private function createButton(label:String, x:Int, y:Int):Sprite {
        var button = new Sprite();
        
        // Draw button background
        button.graphics.beginFill(0xCCCCCC);
        button.graphics.drawRect(0, 0, 100, 40);
        button.graphics.endFill();
        
        // Create button label
        var buttonLabel = new TextField();
        buttonLabel.text = label;
        buttonLabel.width = 100;
        buttonLabel.height = 40;
        buttonLabel.selectable = false;
        buttonLabel.mouseEnabled = false;
        
        // Position button label
        buttonLabel.x = 0;
        buttonLabel.y = 0;
        
        // Add button label to button
        button.addChild(buttonLabel);
        
        // Position button
        button.x = x;
        button.y = y;
        
        // Add button to the stage
        addChild(button);
        
        return button;
    }
    
    private function onClickButton1(event:MouseEvent):Void {
        textField.text = "Button 1 clicked!";
    }
    
    private function onClickButton2(event:MouseEvent):Void {
        textField.text = "Button 2 clicked!";
    }
    
    public static function main() {
        new Main();
    }
}

Remove the static main() function. OpenFL projects don’t need a static main() function because it will be generated for you automatically.

However, if you’d like to keep your own custom static main() function, you actually can. You just need to add the display object to the stage after you create it. The following code would also fix your issue:

public static function main() {
	Lib.current.addChild(new Main());
}
1 Like

That fixed it. thanks!

1 Like