Hello, I am trying to create a custom button by creating a sprite and adding a eventlistener to check if its clicked but when I run my program it gives me these errors:
src/Main.hx:26: characters 39-44 : Void -> Void should be Dynamic -> Void src/Main.hx:26: characters 39-44 : For function argument 'listener'
When I remove the listener the errors are gone
My main class:
`package;
import openfl.display.Sprite;
import openfl.events.MouseEvent;
import openfl.display.SimpleButton;
class Main extends Sprite {
private var button:SimpleButton;
private var s:Spritetest;
public function new () {
super ();
this.mouseChildren = false;
this.buttonMode = true;
init();
}
public function init() {
fillBackGround(0xff00ff, 640, 960);
s = new Spritetest();
s.addEventListener(MouseEvent.CLICK, click);
addChild(s);
}
public function fillBackGround(color:Int, w:Int, h:Int) {
this.graphics.beginFill(color);
this.graphics.drawRect(0, 0, w, h);
this.graphics.endFill();
}
public function click() {
trace("test");
}
}`
my button class
`package;
import openfl.display.Sprite;
class Spritetest extends Sprite {
public function new() {
super();
this.graphics.beginFill(0xffffff);
this.graphics.drawRect(20 , 20, 40, 40);
this.graphics.endFill();
}
}`
Sorry for bad english