How to stop SimpleButton animation when enabled=false


#1

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.


#2

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.


#3

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!


#4

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


#5

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?


#6

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?


#7

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?


#8

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


#9

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;
}

#10

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