Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
RapsFan
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
Accepted Solution

selectRange() not working for TextArea

Hello everyone. I have a TextArea (mainTextField in the following example) and a TextInput I use as a search field to search for a string in the TextArea. Below is my clickhandler. It traces the correct values, but the string doesn't get highlighted. I must be missing a step.

 

			protected function searchBtn_clickHandler(event:MouseEvent):void
			{
				text = mainTextField.text;
				search_Str = searchTxt.text;
				
				var search_result:int = text.search(search_Str);
				
				mainTextField.selectRange(search_result,search_result+search_Str.length);
			}

 

Retired
rmasroor
Posts: 172
Registered: ‎06-07-2010
My Device: BlackBerry 8520

Re: selectRange() not working for TextArea

Hello RapsFan,

 

How are you doing? I hope all is well.

 

In order highlight your text via 

mainTextField.selectRange(search_result, search_result+search_Str.length), you will first need to bring focus over your TextArea.

 

In short, 

mainTextField.setFocus();
mainTextField.selectRange(search_result,search_result+search_Str.length);

 will highlight your text. 

 

Let me know if you have any questions.

Raihan Masroor
BlackBerry Development Advisor
Developer
RapsFan
Posts: 442
Registered: ‎08-02-2010
My Device: Z10

Re: selectRange() not working for TextArea

Hi  but I already tried this.

Retired
rmasroor
Posts: 172
Registered: ‎06-07-2010
My Device: BlackBerry 8520

Re: selectRange() not working for TextArea

Hello RapsFan,

 

I tried this below and I'm able to highlight text.

 

<?xml version="1.0" encoding="utf-8"?>
<components:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
				 xmlns:s="library://ns.adobe.com/flex/spark" xmlns:components="spark.components.*" title="HomeView">
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			private function highlight(event:MouseEvent):void{
				ta.selectable = true;
				ta.setFocus();
				ta.selectRange(0,10);
			}
		]]>
	</fx:Script>
	
	<s:VGroup width="100%" height="100">
		<s:TextArea id="ta" width="100%" height="50" text = "The quick red fox jumped over the lazy brown dog."/>
		<s:Button label="Highlight" click="highlight(event)"/>
	</s:VGroup>
</components:View>

Can you provide me a snippet of code with more detail into your implementation. 

 

Looking forward to your reply.

Raihan Masroor
BlackBerry Development Advisor
Developer
RapsFan
Posts: 442
Registered: ‎08-02-2010
My Device: Z10

Re: selectRange() not working for TextArea

[ Edited ]

Thanks ! I was using getFocus() :smileyhappy: duh.

Retired
rmasroor
Posts: 172
Registered: ‎06-07-2010
My Device: BlackBerry 8520

Re: selectRange() not working for TextArea

Hey RapsFan,

 

It's awesome you got your implementation working. :smileyhappy:

 

Sincerely,

Raihan Masroor
BlackBerry Development Advisor