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

  • Home
  • SEARCH
  • 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 884449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:45:10+00:00 2026-05-15T12:45:10+00:00

I’m making a text editor using Text Area. Which user can change font size,

  • 0

I’m making a text editor using Text Area. Which user can change font size, family and etc.
This is my code on as:

    private function ChangeFont(event: Event):void
       {
        var mySelectedTextRange:TextRange = new TextRange(thistxtarea,true,
                                                thistxtarea.selectionBeginIndex,
                                                thistxtarea.selectionEndIndex);
        mySelectedTextRange.fontSize = int(cmbbxFntSze.text);
        thistxtarea.setFocus();
       }

i have this combo box to enter desired font size:

<mx:ComboBox x="78" y="8" width="114" id="cmbbxFntFam"  close="ChangeFont(event)"></mx:ComboBox>

How do I change font properties if the text inside is not highlight? For example I position the mouse pointer on last index of text inside my Text Area and I select on my combo box the desired font size. The following font size of letter that inputed in Text Area should be the selected font size on combo box. The code that I post works only if I highlight the desired text.

  • 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-15T12:45:10+00:00Added an answer on May 15, 2026 at 12:45 pm

    This is to set the style

    private function setTextStyles(type:String, value:Object = null):void
            {
                if(thisindex != -1)
                {
                    var tf:TextFormat;
    
                    var beginIndex:int = textArea.getTextField().selectionBeginIndex;
                    var endIndex:int = textArea.getTextField().selectionEndIndex;
    
                    textArea.getTextField().alwaysShowSelection = true;
    
                    if (beginIndex == endIndex)
                    {
                        tf = previousTextFormat;
                    }
                    else    
                        tf = new TextFormat();
    
    
                    if (type == "bold" || type == "italic" || type == "underline")
                    {
                        tf[type] = value;
                    }
                    else if (type == "align")
                    {
                        if (beginIndex == endIndex)
                        {
                            tf = new TextFormat();
                        }
    
                        // Apply the paragraph styles to the whole paragraph instead of just 
                        // the selected text
                        beginIndex = textArea.getTextField().getFirstCharInParagraph(beginIndex) - 1;
                        beginIndex = Math.max(0, beginIndex);
                        endIndex = textArea.getTextField().getFirstCharInParagraph(endIndex) +
                            textArea.getTextField().getParagraphLength(endIndex) - 1;
                        tf[type] = value;
                        previousTextFormat[type] = value;
                        if (!endIndex)
                            textArea.getTextField().defaultTextFormat = tf;
                    }
                    else if (type == "font")
                    {
                        tf[type] = cmbbxFntFam.text;
                    }
                    else if (type == "size")
                    {
                        var fontSize:uint = uint(cmbbxFntSze.text);
                        if (fontSize > 0)
                            tf[type] = fontSize;
                    }
                    else if (type == "color")
                    {
                        tf[type] = uint(clrpckerFontColor.selectedColor);
                    }
    
    
                    textFormatChanged = true;
    
                    if (beginIndex == endIndex)
                    {                       
                        previousTextFormat = tf;
                    }
                    else
                    {
                        textArea.getTextField().setTextFormat(tf,beginIndex,endIndex);//textArea.setTextFormat(tf,beginIndex,endIndex);
                    }
    
                    dispatchEvent(new Event("change"));
    
                    var caretIndex:int = textArea.getTextField().caretIndex;
                    var lineIndex:int = textArea.getTextField().getLineIndexOfChar(caretIndex);
    
                    textArea.invalidateDisplayList();
                    textArea.validateDisplayList();
                    textArea.validateNow();
    
                    // Scroll to make the line containing the caret under viewable area
                    while (lineIndex >= textArea.getTextField().bottomScrollV)
                    {
                        textArea.verticalScrollPosition++;
                    }
    
                    callLater(textArea.setFocus);
    
                }
            }
    

    This code is use for getting the style from the textArea

     private function getTextStyles():void
            {               
    
                if (!textArea)
                    return;
    
                var tf:TextFormat;
    
                var beginIndex:int = textArea.getTextField().selectionBeginIndex;
                var endIndex:int = textArea.getTextField().selectionEndIndex;
    
                if (textFormatChanged)
                    previousTextFormat = null;
    
                if (beginIndex == endIndex)
                {
                    tf = textArea.getTextField().defaultTextFormat;
                    if (tf.url != "")
                    {
                        var carIndex:int = textArea.getTextField().caretIndex;
                        if (carIndex < textArea.getTextField().length)
                        {
                            var tfNext:TextFormat=textArea.getTextField().getTextFormat(carIndex, carIndex + 1);
    
                            if (!tfNext.url || tfNext.url == "")
                                tf.url = tf.target = "";
                        }
                        else
                            tf.url = tf.target = ""; 
                    }
                }
                else
                    tf = textArea.getTextField().getTextFormat(beginIndex,endIndex);                
    
    
                if (cmbbxFntSze.text != tf.font)
                    setComboSelection(cmbbxFntFam, tf.font);
                if (int(cmbbxFntSze.text) != tf.size)
                    setComboSelection(cmbbxFntSze,String(tf.size));
                if (clrpckerFontColor.selectedColor != tf.color)
                    clrpckerFontColor.selectedColor = Number(tf.color);
    
                if (btnBold.selected != tf.bold)
                    btnBold.selected = tf.bold;//Alert.show("bold");
                if (btnItalic.selected != tf.italic)
                    btnItalic.selected = tf.italic;
                if (btnUnderline.selected != tf.underline)
                    btnUnderline.selected = tf.underline;
    
    
                if (tf.align == "left")
                    alignButtons.selectedIndex = 0;
                else if (tf.align == "center")
                    alignButtons.selectedIndex = 1;
                else if (tf.align == "right")
                    alignButtons.selectedIndex = 2;
                else if (tf.align == "justify")
                    alignButtons.selectedIndex = 3;
    
    
    
                if (textArea.getTextField().defaultTextFormat != tf)
                    textArea.getTextField().defaultTextFormat = tf;
                previousTextFormat = tf;
                textFormatChanged = false;
    
                lastCaretIndex = textArea.getTextField().caretIndex;                
                thishtmltxt = textArea.htmlText;
                textArea.validateNow();
            }
    

    Please check for minor errors, coz when i code this i have some commented traces

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 471k
  • Answers 471k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Not sure what you really want. You can't put your… May 16, 2026 at 3:28 am
  • Editorial Team
    Editorial Team added an answer Try this in the .htaccess file in your document root:… May 16, 2026 at 3:28 am
  • Editorial Team
    Editorial Team added an answer The mappings look fine. The symptoms at least indicate that… May 16, 2026 at 3:28 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.