Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6897413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:09:58+00:00 2026-05-27T07:09:58+00:00

I have a TextArea, a TextInput and a button. When text is entered into

  • 0

I have a TextArea, a TextInput and a button. When text is entered into the TextInput the TextArea is searched for the matching string, however it only highlights the first found instance of the string. How can I do a ‘find next’ type of operation.

protected function searchBtn_clickHandler():void
        {
            text = mainTextField.text;
            search_Str = searchTxt.text;

            var search_result:int = text.search(search_Str);
            trace(search_result);
            mainTextField.setFocus();
            mainTextField.selectRange(search_result,search_result+search_Str.length);
        }

EDIT

protected function searchBtn_clickHandler():void
        {
            text = mainTextField.text;
            search_Str = searchTxt.text;

            search_result = text.search(search_Str);
            trace(search_result);
            mainTextField.setFocus();
            mainTextField.selectRange(search_result,search_result+search_Str.length);
            oldSearch_result = search_result;
        }

        protected function findNextBtn_clickHandler():void
        {
            search_Str = searchTxt.text;

            // truncate the text using substring; this gives you everything in mainTextField after your previous search results
            var truncatedText:String = mainTextField.text.substring(oldSearch_result+search_Str.length);

            search_result = truncatedText.search(search_Str);
            mainTextField.setFocus();
            // when you select the range, you want to offset your result index w/ the characters your chopped off  
            mainTextField.selectRange(oldSearch_result+search_Str.length+search_result,search_result+search_Str.length);

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:09:58+00:00Added an answer on May 27, 2026 at 7:09 am

    When the user clicks “find next” button, just truncate the text based on the search_str.length and search_result–in memory–and perform the search again.

    protected function searchAgain_ClickHandler(event:Event):void{
      search_Str = searchTxt.text;
    
      // truncate the text using substring; this gives you everything in mainTextField after your previous search results
      var truncatedText = mainTextField.text.substring(oldSearchResult+search_Str.length);
    
      var search_result:int = truncatedText.search(search_Str);
      mainTextField.setFocus();
     // when you select the range, you want to offset your result index w/ the characters your chopped off  
    mainTextField.selectRange(oldSearchResult+search_Str.length+search_result,search_result+search_Str.length);
    
    }
    

    More info on substring


    Edit 12/7/2011

    Here is a full code sample showing this approach working:

    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                           xmlns:s="library://ns.adobe.com/flex/spark" 
                           xmlns:mx="library://ns.adobe.com/flex/mx">
    
        <fx:Script>
            <![CDATA[
                import mx.controls.Alert;
    
                import spark.layouts.HorizontalLayout;
    
                protected var oldSearchResult :int =0;
    
                protected function button1_clickHandler(event:MouseEvent):void
                {
                    var search_Str : String = searchTxt.text;
    
                    // truncate the text using substring; this gives you everything in mainTextField after your previous search results
                    var truncatedText : String;
                    truncatedText = mainTextField.text.substring(oldSearchResult);
    
                    var search_result:int = truncatedText.search(search_Str);
                    mainTextField.setFocus();
                    // when you select the range, you want to offset your result index w/ the characters your chopped off  
                    if(search_result != -1){
                        mainTextField.selectRange(oldSearchResult+search_result,oldSearchResult+search_result+search_Str.length);
                        oldSearchResult = oldSearchResult+search_result+search_Str.length;
                    } else {
                        Alert.show('no more results');
                    }
    
                }
            ]]>
        </fx:Script>
    
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
    
        <s:Form height="100%" width="100%">
            <s:FormItem label="Search Text" layout="{new HorizontalLayout()}" width="100%" >
                <s:TextInput id="searchTxt" text="the" />
                <s:Button label="Search Next" click="button1_clickHandler(event)" />
            </s:FormItem>
            <s:FormItem height="100%" width="100%">
                <s:TextArea  id="mainTextField">
                    <s:text>
                        The Quick Brown Fox Jumped Over The Lazy Dogs and Landed on the Other Side of the River, bouncing back and forth between two turtles in an attempt to escape the flying vulture.
                    </s:text>
                </s:TextArea>
            </s:FormItem>
        </s:Form>
    </s:WindowedApplication>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textarea within an HTML page into which my users paste content.
I have a textarea and a button on a form. The textarea may already
I have a screen with a few components (textInput, textArea, checkBox). I want to
I have a textarea and among free text input I insert some tags that
I have a TextArea on my website which I write the input into my
I have a TextArea that allows user input. I also have TextInput that the
I have a textarea. I need to update text in a div when a
I have a text input and a textarea and I'm passing the value from
I have a text input field like text box or text area. I want
I have textarea in my site(link shortening site) i want to user enter some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.