views:

2400

answers:

4

Hello, I have a TextInput control which has a search functionality for the people in the system. It works fine. All I need is to style it in such a way that, it will be having search image on the right, which when clicked, will search. Its actually for look and feel part of the application, which will make the search box look much better.

It is exactly similar behavior implemented in search box embedded in Firefox.

Any solution to this?

Thanks :)

+1  A: 

Hello,

<mx:HBox>
    <mx:TextInput id     = "txtSearch"/>
    <mx:Image source     = "yourSearchIcon.png" 
              click      = "doSearch()" 
              buttonMode = "true"/>
</mx:HBox>

That's all!


Adrian Online Timesheet Software

Adrian Pirvulescu
This is what I have right now...I need the image embedded/included in the search textInput itself, and need to get rid of the search button
online19
Then just do the following <mx:HBox horizontalGap="{-imageId.width}">..
Adrian Pirvulescu
'll try thatBut, can't we render the textinput control to add an image at certain position in the text box?
online19
@online19 - You'll need to subclass the TextInput object and 1) include and position the image in the UITextField of your TextInput subclass; 2) include code to keep it in the correct place. If I have some time tomorrow morning, I'll see if I can come up with a postable answer.
Ross Henderson
@rhtx - Have you by any chance tried this? I am yet to try that. 've been busy through the week. 'll try this and post it if it works
online19
A: 

You could write a subclass of TextInput Class which has as an image for "yourSearchIcon" image such as:

[Embed(source='../../libs/graphic_elements.swf#search_ico')]
private var searchIcon:Class;
private var searchImg:Image = new Image();

private function onCreationComplete(event:Event) : void {
 searchImg.source = searchIcon;
 searchImg.x = this.width - 40;
 this.addChild(searchImg);
 this.addEventListener(ResizeEvent.RESIZE, onResize);
}

// ovviously you have to handle the resize event private function onResize(event:ResizeEvent) : void { searchImg.x = event.currentTarget.width - 40;

}

That's your custom component

looks good! Let me try this.
online19
+2  A: 

Ack, avoid subclassing. Think outside the Box, as it were, and use a Canvas:

<mx:Canvas>
    <mx:TextInput change="doSearchFor(event.currentTarget.text)" />
    <mx:Image source="search_icon.png" verticalCenter="0" right="5" />
</mx:Canvas>

Then make that a component itself if you want to make it neater. Favour composition over inheritance, in MXML as elsewhere.

Charles Dale
A: 

//hope this code will help you, this code add search icon to the left of the TextIput

public class SearchInputBox extends TextInput {

[Embed(source='../../../../assets/images/icons/searchIcon.png')]
private var searchIcon:Class; 
private var searchImg:Image;       

override protected function createChildren():void
{
     super.createChildren();
  searchImg = new Image();
  searchImg.source = searchIcon;
  searchImg.width=15;
  searchImg.height=15;
  searchImg.x = 2;
  searchImg.y = 3;

  setStyle("paddingLeft",searchImg.width+2);
  addChild(searchImg);

}

}

Thanks Arun. 'll try that
online19