I want to add search icon inside the spark TextInput control. Is there a way by which I can extend the TextInput control and add a child to it.
Thanks
I want to add search icon inside the spark TextInput control. Is there a way by which I can extend the TextInput control and add a child to it.
Thanks
You shouldn't extend TextInput
itself. The main power of Spark architecture is skinning possibility. You can create your own skin based on standard TextInputSkin
and place icon there. I think there will not any problems.
I faced the same problem wanting to get a search icon in a spark TextInput. It was very simple to copy the existing spark skin and add the icon to it. Here's how:
The last section in the skin file is <!-- text -->
. AFTER this section, create a new section for <!-- search icon -->
that includes the following (note: this will be the last section in the skin):
<s:Image id="iconDisplay" source="@Embed('path/to/image/file/MY_SEARCH_IMAGE.png')"
mouseEnabled="false" mouseChildren="false"
visible.normal="false" visible.normalWithPrompt="true"/>
Modify the exclusions arrays that appear earlier in the file so it appears as follows (note: the following code already exists in the file, just add iconDisplay
to it as shown):
/* Define the skin elements that should not be colorized. */
static private const exclusions:Array = ["background", "textDisplay", "promptDisplay", "iconDisplay", "border"];
/* exclusions before Flex 4.5 for backwards-compatibility purposes */
static private const exclusions_4_0:Array = ["background", "textDisplay", "promptDisplay", "iconDisplay",];
Go your application code where you have the TextInput component, and link it to the skin using: <s:TextInput ... skinClass="path.to.skins.TextInputSkinWithPromptIcon" prompt=" "/>