Getting mouse events on non-Sprites


I’ve had a little bit of trouble with a couple of things, which I think I used to do in Flash, but don’t seem to be replicated in openFL.

It may be that the answer to this question is: “you can’t do that in openFL”, but I thought I’d check in case I’m doing something wrong.

In order to make simple buttons for debug, I was trying to add a mouse click listener on a text field, I could only get this to actually do what I wanted by wrapping the TextField in a Sprite.

I was also trying to do a similar thing with Bitmaps, but same issue…

Is it possible? Or can I only have MouseEvent.Click on a Sprite?


This seems to work:


import openfl.display.Sprite;
import openfl.text.TextField;

class Main extends Sprite {
	public function new () {
		super ();
		var textField = new TextField ();
		textField.text = "Hello";
		textField.addEventListener ("click", function (_) {
			textField.alpha = 0.5;
		addChild (textField);

Bitmap won’t work because it doesn’t inherit from InteractiveObject, so you do need to wrap Bitmap objects inside a Sprite for them to work.

Use the openfl test flash target to validate things that you think should work in Flash, and please let us know if you hit something that’s isn’t behaving as you expect!


Thanks for the clarification on Bitmaps, I’ll try again with textfields.