I need to be able to trigger an event on change, but only when user focus out of the input text.
Is there any one event I can use?
I guess I can use a combination of both, by finding out which of them triggers last, and only use that, if the other has been called, but that introduces some complexity and clutters the code.
There's no single event that combines both of these concepts. You'll need to write some custom logic to do what you're describing.
Using the mx.managers.FocusManager getFocus() method you can find the component that currently has focus. In the change handler on the TextInput you can check if this TextInput currently is the component with focus. If not, you can go about your business.
Related
Question/Issue
I tried reimplementing the event method in a custom delegate to handle clicks. The delegate is used to render table cells in a table view. However, I do not get any events for the delegate (the method is never called according to the debuger). Is there anything special I need to do so my delegate can track events (in particular mouse entering/exiting, clicks)?
Context
I would like to create my own data representation for table cells. The functionality should be close to a button, but slightly different. I read that the two options for implementing buttons in table are either setting a cell widget which supposedly has a high performance cost (I did not quite understand why) or using a delegate.
Since I want different behaviour than that of a button, and for the speed myth I decided to go with a delegate.
Mouse events are send to the QAbstractItemDelegate::editorEvent() method, even if they don't start editing of the item.
See: http://doc.qt.io/qt-5/qabstractitemdelegate.html#editorEvent
Is there any shortcut way to add an eventListener to something like a select event for NavigatorContent.
I am aware I can add a listener for a change event on the ViewStack and identify the selected NavigatorContent through that handler.
The ViewStack component dispatch a CREATION_COMPLETE event on the new selectedChild
As2 has shortcuts for what you want, im afraid as3 doesnt as AS3 wants to know exactly whats needed to care for at what time.
an update /enterframe function can reduce some code but apply more load on the swf over all as its waitng for a call.
throw some code up in your question so we all know exactly what your talking about.
I've a little problem, I don't really understand if I can use addEventListener more than one time on the same object (and same callback function) if this case can I have a problem of overflow, or simple flex is so smart to not add again in the same stack same function
for examples:
var t:CServiceObj = _rModel.userGetBoardJoined();
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
As you say, Flex is "smart" and even if you subscribe to an event more than once on the same instance, then the handler will be called Just once (no matter how many addEventListener you pass).
I tried a quick test on Button and it doesn't matter if the addEventListener is added multiple times to the same function -- it gets dispatched once.
However, you could set up something like this
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk2);
where onDataOk2 calls onDataOk with the event parameter.
Interesting Note
A different test, I added a click handler in the mxml tag, and a click handler in the AS, both pointed to the same function. When the button was clicked, both handlers dispatched, so Flex did something behind the scenes to accomodate this functionality.
I have a List component from which I'd like to be able to remove items using drag & drop, but without having a specific target. If you use the mac, the behaviour I'm looking for is something like what the Dock uses; when you drag something out of the bounds of the control it should get an icon that indicates that it'll be deleted (OSX uses a cloud or something?) and then if you release it it will be removed from the list.
How can I do this?
(If I need to provide a more clear description, please comment; I'll fill in what I can)
In my experience with drag/drop in Flex, you cannot simply drag something out and handle that. There is no dragOut event (unfortunately), so that would leave you up to the task of writing dragOver and dragDrop listeners on all the containers surrounding your dragInitiator and handling the process accordingly.
It's more time consuming and can become complicated if any of these controls already have specific dragOver and dragDrop event handlers.
Hope this helps.
Having no Flex experience all I can offer is some psuedo code which resembles how I implemented a similar effect in JavaScript, but hopefully it will get you started.
Essentially what you'll want to do is during your drag event measure the current coordinates of the object you're dragging to see if they intersect the original container and when they fall outside of its bounds call the logic to update the icon in order to indicate it will be removed. Then, on the drop event, check the coordinates once more and delete the item if needed.
I'm new to Flex, although not new to programming. I want to write a generic event handler that will be called by all my textinput boxes when they receive focus. When they have focus, I want to change the colour of the textinput box. When they lose focus, I want to restore the "inactive" color profile. I could write an ActionScript event handler for each textinput box, but we all know that's lame. :o) What I need, then, is a way to access the object which is calling the event handler.
In Delphi, I'd have written a function which passes in the Sender object, allowing me to access the calling object's properties. I'm guessing ActionScript/Flex has a completely different architecture, which is why I'm having difficulty doing this.
Thanks in anticipation!
You should subclass TextInput and handle the focus events in there. I think this would be the simplest way to achieve what you are looking for without having any complex code.
I hope I'm understanding what you're asking for... are you talking about event delegation?
This worked for me:
// 'focusOut' for blur
stage.addEventListener('focusIn', function(e:Event):void {
// The focused control is e.target
});
If you want to change the look of the focused input box, you can do this by setting the focusSkin property. If you want this to happen globally, you can put a style declaration in your CSS file.
In this CSS example I'm replacing the default focusSkin (mx.skins.halo.HaloFocusRect) with an embedded PNG file.
TextInput {
focusSkin: Embed(source="focus.png");
}
TextInput has a few properties for altering the look of the focus, like changing the opacity of the focus skin (focusAlpha property). Check the TextInput documentation for more info.