6 Replies Latest reply on Aug 24, 2007 1:02 AM by Script_In_Action

    how to split text according to the textfield size

    Script_In_Action
      Hi, its very urgent if anybody can help me out..... i am working on an e-learning course where all the text is coming through XML. Client is very specific about not to use scrollbar. They want to use more and back buttons to show the rest of the text (they dont want the text to be scrolled either). For that I created a function to part the text according to the textfield height in an array. (one important point is that user can change font type, font size anytime in between the course). Here is a bit of code



      This code is working fine, but it gives undesired output if we use html tags in helpText

      please help me out..... please
        • 1. Re: how to split text according to the textfield size
          FlashTastic Level 1
          What kind of undesired output are you getting when you use HTML tags? I would assume that your array would contain entries such as:

          helpText [0] = "<font"
          helpText[1] = "color='red'"
          helpText[2] = ">"

          etc.

          It's possible that you won't be able to split your array using String.split(" "). You'll probably have to create a function to manually split your string, I've posted an example below. It's just a starting point for you to fiddle around with, It may not work depending on how your XML is formed, etc... but at least you have an idea.

          Cheers,
          FlashTastic
          • 2. Re: how to split text according to the textfield size
            Script_In_Action Level 1
            Thanks FlashTastic,

            I am sorry for not being able to convey my problem.... actually problem is not that code is not recognizing the tags but the problem is.... let me explain, suppose there is a tag <b> and </b> in xml..... code split the text so it split <b> and </b> too and stored it in an array.... then it adds the text i.e. This is a <b> sample </b> text..... til the textheight of the textfield is less than the ._height of hte textfield and finally i have a string that fits in the textfield perfectly and when the parted text is assigned to the textfield it recognize the tag and make that bunch of words or sentence bold and that creates the problem.... i hope that this time it is more clearer....

            Thanks again.....
            • 3. how to split text according to the textfield size
              FlashTastic Level 1
              So if I understand properly, you don't want the textfield to render the HTML? As in the example you just posted, you don't want the word sample to be bold? Or is it that the bold text comes along and messes up the width of your string that fits perfectly?


              If you don't want the textfield to render the html tags, then simply add those conditions to your TextFormat object.

              var my_fmt:TextFormat = new TextFormat();
              my_fmt.bold = false;
              my_fmt.italic = false;
              my_fmt.underline = false;

              Then your textfield will not show text effects or the html tags.

              If the problem is that the width is messed up because of the bold text, send me the dimensions of your textfield so I can test it properly.

              Cheers,
              FlashTastic
              • 4. Re: how to split text according to the textfield size
                Script_In_Action Level 1
                Exactly, the width messes up because of bold text, or because different font type..... regarding dimensions of the textfield

                width = 525;
                height = 185;

                Thanks again FlashTastic..... problem could be solved in another way also....

                Actually why I am doing this is just because of the accessibility for screen reader.... as soon as focus get to the textfield, screen reader reads all the text in the textfield..... mind it all the text (visible and invisible text both) and then it conflicts the more button concept...... so if you could suggest a better approach to solve this problem that would be greatly appreciated
                • 5. Re: how to split text according to the textfield size
                  FlashTastic Level 1
                  As far as I know, there's no way that you can target the width of the individual characters in the textfield. It looks like you only have two options.

                  1. Modify your code to restrict text to 1/5 less than the height of the textfield, to account for bold text being there. You could create a function that runs only if it detects bold text in the string it's putting into the textField.
                  or
                  2. Remove bold/italic formatting, and let your client know it's a limitation.

                  I'm sorry I don't have another solution for you, I wish I did.

                  Cheers,
                  FlashTastic

                  • 6. Re: how to split text according to the textfield size
                    Script_In_Action Level 1
                    I guess you are right FlashTastic

                    Thank you very much for your valuable comments.