Flex custom component FadingInjector
Apply the fading background color effect available in my Flex FadingTextInput in any UIComponent by injecting it using FadingInjector (post updated following a comment from João).
Check the first section below for a demonstration of the FadingInjector and access to its source code.
But, if you want more details and a follow-up of my learning journey, read also the second section!
FadingInjector Flex custom component
Here is an application demonstrating the FadingInjector behavior (right click to view source code):
Click to download the FadingInjector class.
Use the first ColorPicker to change the controls background color or the second ColorPicker to change the editing color.
Use the “Highlight on Focus” check box to choose between the two available behaviors:
- When checked, the injector changes the control background color into the editing color as soon as the control takes the focus. It then changes it back into the initial control background color on focus out. The change into the initial background color is immediate if the value wasn’t changed; it is done through a fading effect if the value has been changed.
- When unchecked, the control background color is changed into the editing color on focus out, and only if the value has changed.
As usual, if you have any question on this component, please leave a comment.
FadingTextInput or FadingInjector?
As I was explaining in my FadingTextInput article, I would have liked my FadingTextInput custom component to support additional features such as a prompt string or a clear button.
I consider that there are already very good implementations of such goodies. Let’s just take two examples:
- The
PromptingTextInputcomponent available in flexlib library - The Clearable
TextInputavailable in Justin W. Opitz’s library
So, instead of extracting these features and incorporating them in my FadingTextInput, I decided to do “the opposite”: extracting my fading behavior and “incorporating” it in these existing components.
Of course, I cannot modify the flexlib or Justin components so why not injecting my behavior in their classes?
The FadingInjector is just an extract from my FadingTextInput component (the part managing and triggering the fading effect) that now applies the fading effect on an external control instead on itself. In other words, you can attach “any” existing control to my FadingInjector and this will add the fading behavior to the control.
I quoted any because my FadingInjector relies on two mandatory elements to be able to monitor a control. The control must support a backgroundColor style and a String property providing its “value” (that can be configured using the valuePropertyName property of FadingInjector). As long as a control has these two elements, the FadingInjector can inject the fading color behavior into the control. As, by default, the value property is defined as “text”, injecting the fading behavior to a TextInput/TextArea (or any subclass of TextInput/TextArea) just requires writing:
<blogagic:FadingInjector id="myInjector" control="{myTextInput}">
So, what’s better compared to my initial FadingTextInput is that I can now easily add my fading logic to any existing customized text input component.
That seems great but… there’s still something bothering me… without really thinking about it, I put my FadingInjector in my com.blogagic.control directory. I don’t think that it’s really a control… so what? You’ll know it by reading my next article!
Note:
Following João’s comment, I added an option to change the background color of the monitored control as soon as it gets the focus.
You should anyway note that this leads to a minor issue when using the ClearableTextInput. Indeed, when tabulating to exit the control, the focus is moved to its internal clear button. So, if you want the fading effect to happen, don’t leave the field using tab, but click on any other control.
By the way, implementing João’s suggestion, I had to modify Darron Schall’s AnimateColor class such that it correctly sets the target values when being interrupted: one less bug, great; thanks again João!



Nice work – but just a side note: I think the effect would look more “usable” if the fading color is set when the user selects the control, fading to the original color when the control looses focus. The user would get a more clear perception of what’s happening. But this is just my opinion…
@João Saleiro
Thanks for your feedback João.
Check my next article when available and you’ll see that I completely agree with your point!
My FadingInjector was just one more experiment before reaching, hopefully, the “best” approach and being able to deliver something really usable
@João Saleiro
João, you made me feel bad (and lazy)
So I updated my component to implement your suggestion!
Thanks again for giving me enough motivation to do this improvement
Well done!
Great job
2 remarks:
1) You forgot to include listing of “com.blogagic.core.IDisposable” (may be this interface is not really needed)
2) FadingInjector does not work with Flex 4 SDK yet
@JabbyPanda
1) Do you know how to include source code of a class that is part of a library project? (IDisposable is part of my “blogagic library”)
Anyway, this interface just defines the dispose method; this is something I try to incorporate in all my classes but you can get rid of it without any issue!
2)
I’m not using Flex 4 SDK yet; it seems that as soon as I’ll do, I’ll have some updates waiting for me!
Thanks Jabby for the SDK 4 experiment!
@JYC
Turns out it is not that simple to include source code of a class that is a part of a library.
Have a look at https://bugs.adobe.com/jira/browse/FB-9055.
There is 4 step workaround for this task mentioned in the comments, that it supposed to be working for Flex Builder 3.
Does not really work for Flash Builder 4
@JabbyPanda
Wow, thanks Jabby!
Not sure I’ll do all this just for the IDisposable interface but this is good to know
By the way, here’s the interface:
public interface IDisposable { function dispose():void; }FadingInjector Flex custom component is really amazing thanks for sharing as i was getting some error in it. Thanks
Nice effect with Flex custom component FadingInjector looking cool will sure use it in next project