How to stop SimpleButton animation when enabled=false

According to the documentation, when a SimpleButton “is disabled (the enabled property is set to false), the button is visible but cannot be clicked. …Note: To prevent mouseClicks on a button, set both the enabled and mouseEnabled properties to false.”

In Flash, when the enabled and mouseEnabled properties are set to false, the button is truly not clickable. There is no animation, the hover state doesn’t display on a MouseOver and down state is not displayed on a MouseDown. And no event is dispatched on a MouseClick.

In OpenFl, the button is still clickable visually, and if any event listeners are not removed, a user action will cause an event to be dispatched.

I can prevent my code from responding to a click by removing the listener. What I need to know is how do I prevent the down state from being displayed when the user clicks a SimpleButton.

1 Like

I think the simplest solution is to write your own “AdvancedButton” class.
Its just 2 Sprite and a changing state based on mouseOver and after that you have full control/freedom.

I do have my own AdvancedButton class but the problem is I’m converting a bunch of old Flash projects where the buttons were made inside Flash as SimpleButtons so that is a lot of extra work to rectify a problem that shouldn’t exist.

The documentarians says "To prevent mouseClicks on a button, set both the enabled and mouseEnabled properties to false.” That’s what should happen. As far as I can see, doing those two things does nothing!

I think this fixes it:

It looks like enabled toggles whether the simple button state and hand cursor apply, but mouse events (such as MouseEvent.CLICK) still trigger. mouseEnabled toggles whether the mouse events fire, which does not fire to custom event handlers, nor does it trigger the button states either, since those rely on mouse events to trigger.

Give it a try and let me know. When something like this does not behave like Flash, lets fix it, if possible! No need to work around an issue like this

I found the file SimpleButton.hx in haxelib/openfl/7,0,0/src/openfl/display. I tried making this change:

private function __this_onMouseDown (event:MouseEvent):Void {
	if (enabled)
		_currentState = downState;
	else __currentState = upState;

But I didn’t see any changes in the behavior. In fact I tried making some other changes just to try to get some effect and nothing I did seemed to make any changes. What am I missing?

Try writing deliberate errors (like junk text) to ne sure this file is used when compiling. It might also be necessary to make more than one change. Have you tried the latest?

I was not trying to create errors. I was trying to make changes in visual behavior, like displaying a downstate when it should be displaying an upstate.

So why doesn’t the change shown above keep the downState from being displayed?

Have I tried the latest what? And how do I incorporate that into my project?

Sorry, I was writing on a mobile phone.

Before being sure that your changes aren’t working, try adding some junk text, like “982374982374982380-1230asdfoijp;l’;lasdjfl;k” into the file, save and test again. If you get a compile error, then you know that you have the right file. If you get no compile error, then your build is not touching the file you expected.

Then when you are really sure that the file you are editing is the one used during the build, then try and leverage the enabled boolean value in a few more places, on the mouse up, mouse move, mouse down and cursor methods

Finally had time to play with this some more and found the correct SimpleButton.hx file and made the change show again below because there was a typo in a previous post. This fixed the problem.

Any way incorporate this change in future versions of OpenFL?

@:noCompletion private function __this_onMouseDown (event:MouseEvent):Void {
	if (enabled)
		__currentState = downState;
	else __currentState = upState;

I tested my changes quite a lot, between enabled, mouseEnabled, Flash and other targets.

Have you had a chance to try the edits I made?

I don’t have my test project around right now, so I’m a little nervous of making a blind change, but if you tried my changes and this edit your have is needed on top of it, I’d like to dig into it

This does not do the job for me. I am a platform architect and I have to recommend this solution as a platform rendering engine. I cant send company mail to 250 developers and 50 managers

  • Please recompile the third party SimpleButton

Plus I am working in TypeScript and npm will not support such actions . Future more npm clear cache is no longer supported by NPM.

Will this be fixed in current versions ?

I have found the source of the problem. Your TypeScript port is not valid … There is no problem in HAXE. A fortunate event for me, because I am still in evaluation process. That means I can suggest HAXE over TypeScript.


I believe the changes listed above (in this thread) are already a part of the core OpenFL library. If there was a problem in the future, making (and testing) changes locally could be very helpful for identifying and resolving the issue, then we can integrate the fix and release it officially for everyone.

It is true, most developers currently use Haxe over TypeScript, but we would be very happy to look into any issues you are currently seeing, using TypeScript. Is there example code we can use to reproduce the problem you had?

Thank you for evaluating OpenFL, please let me know (or visit our Discord server) with any questions or concerns. Thanks :slight_smile:

Sorry I have just seen this message. Will look up for the code on monday.