How do you prevent a CheckBox or ToggleButtonBase from changing? - apache-flex

I have a Spark CheckBox and I'm trying to prevent it from changing when clicked. In most Flex components there is a CHANGING event and you can prevent default. I've only found a CHANGE event and if I listen for that event and then set checkbox.selected = !checkbox.selected; it just dispatches changed again and the check box is reselected.

You can just disable any mouse events for this checkbox and would still be able to change the selection programmatically with selected=true:
<s:CheckBox id="myCheckbox"
mouseChildren="false"
mouseEnabled="false"/>

I've added an event listener for a mouse click event and this seems to work but there is a flicker where you can see it was selected for an instant.
IEventDispatcher(checkbox).addEventListener(MouseEvent.CLICK, function(e:Event):void {
trace("click");
ToggleButtonBase(target).selected = !ToggleButtonBase(target).selected;
e.stopImmediatePropagation();
e.preventDefault();
});
Using this, if I trace the events, it's:
change
change
click
Not ideal but it seems to be working.

Related

How to disable the dojo button with click event

I need to disable the dojo button with click event, But my dojo button disable color only button now also click event working properly, how to restrict this? In j query when we use the disable attribute the click vent also change to the disable mode. How its in dojo?
My code:
dom.byId("somID").setAttribute("disabled", "disabled");
You need to work with the widget and not the dom node.
require(['dijit/registry'], function(registry) {
registry.byId('somId').set('disabled', true);
});

flex button event handler

I have some buttons in a BorderContainer and I would like to execute the attached event when the user click on the buttons. But, the parent has a click event too.
I would like to execute the action A when the user click on the button A, the action B with the button B and the action C if the user click on the background.
Actually, if I add the eventHandler to the bordercontainer, the buttons don't work anymore. No mouse cursor, no mousehover effect, and if you click on it, it's the action C which is launched.
My bordercontainer:
useHandCursor = true;
mouseChildren = false;
buttonMode = true;
In both buttons and bordercontainer I use the MouseEvent.Click event and both call the same function "click" which will execute different actions depending the properties of the event.target.
My bad. Thank to Timofei.
Both the bordercontainer and the click function were wrong.
In the bordercontainer, mouseChildren had to be set at true, which will let the children get the event too.
And in my click function, using event.target was a bad idea. It tried to get the properties from the bordercontainreskin. I had to use event.currentTarget instead. Finally I added a event.stopPropagation() to prevent the bordercontainer to catch the event too when the user click on a button. And now, everything is working well now.
Thank you

Flex focusOut event on TextInput and pop-up does not remove focus?

I have a flex app with several fields and one text field with a focusOut event:
<mx:FormItem label="Last" x="226" y="1">
<s:TextInput id="lastNameClientTextInput" text="#{_currentEditClient.lastName}" change="textFieldChangeCapitalize(event)" focusOut="lastNameClientTextInput_focusOutHandler(event)"/>
</mx:FormItem>
As expected, when I tab or click out of the field after typing a value it executes my "lastNameClientTextInput_focusOutHandler" method which simply pops-up a new window:
protected function lastNameClientTextInput_focusOutHandler(event:FocusEvent):void
{
clientSearchPopUp = new ClientListWindow();
PopUpManager.addPopUp(clientSearchPopUp, this, true);
PopUpManager.centerPopUp(clientSearchPopUp);
}
That window will do a "PopUpManager.removePopUp(this);" when the user clicks the close button.
However, the problem is when the window closes, the focus is back on the lastNameClientTextInput! I am unable to click or tab out of the field!
When I tab out I do initially see the ibeam cursor move from the last name field to the next field in tab order (address) and then my window pops-up. When I close the window it moves BACK to the last name field and highlights the value.
It is as if I need to do something to validate the focusOut event?
You might want to try using valueCommit rather than focusOut. You could also listen for the popup being removed and set focus manually.
HTH;
Amy
Late I know, but Flex may be referring to the FocusManager.lastFocus property to resume focus from the last time the component was active. When triggering the pop up, try calling:
(focusManager as FocusManager).mx_internal::lastFocus = null;

Flex 4: How to override the default button functionality in a skin class?

I have a videoplayer with a custom skin class. I want to override the functionality of the fullscreen button. When I add an click event, the player still goes into fullscreen mode. How can I prevent the fullscreen event from firing?
It turns out that if you change the id of the button to anything other than the default then you regain full control over the button.
I changed fullScreenButton to customFullScreenButton (below):
<s:Button id="customFullScreenButton" label="Fullscreen"
click="handleFullscreenButtonClicked(event);"
skinClass="FullScreenButtonSkin"/>
Have you tried calling stopImmediatePropagation on the event when your event listener gets called? That should stop it from bubbling, but I'm not sure if your listener will get it first. It's worth a shot though. Hope that helps.

Flex Combobox: Cancel Select

I've made an itemrenderer for the combobox control that shows a button next to the label.
If a user clicks this button, the item gets removed from the dataprovider. Works so far.
When he selects an item, the combobox closes, that's ok. But I don't want it to close when he removes an item.
So is there a way to cancel the change event?
I have tried several things, but to no avail.
I have to use the combobox for layout reasons, don't have enough space to use listboxes...
Thanks for your help.
In your custom itemrenderer , on mouse down handler stop Immediate Propogation
event.stopImmediatePropogation();
In your custom item renderer, try canceling the event in your button's click handler.
event.stopImmediatePropogation()

Resources