I've created a custom Label field, in which I dynamically apply a 
styleSheet, and then highlight a particular word or phrase in the 
text of the Label.  I had to extend the Label class to do this, 
because the internal TextField obj is protected, and I needed access 
to that obj in order to apply the styleSheet object.

My problem is that once the style is successfully applied (which 
includes making the font bigger and changing its color) the text at 
the end or the bottom of the Label is cut off.  I suppose this is 
because the CSS is applied, and then the entire Label component is 
not resized to properly fit the larger text.

I tried to call invalidateSize(), invalidateDisplayList(), and 
invalidateProperties() but neither one of them fixed the issue.

Any ideas how to fix this?

I put the below custom Label on a Canvas and inside of a function I 
call myCustomLabel.setHtmlTextAndHighlightKeyword() when I want to 
add text to the label that needs to be specially formatted
here is the code:
======================================================================
import flash.text.StyleSheet;   
import mx.controls.Label;
        /*******
         * A custom Label component to allow app to apply special 
formatting to a special
         * keyword that is highlighted
         * ****/
        public class EPLabel extends Label
        {
                public function EPLabel()
                {
                        super();
                }
                

                //highlights a keyword in the text for a label  
        
                public function setHtmlTextAndHighlightKeyword
(keyword:String, text:String, style:StyleSheet, 
styleClassName:String):void{

                        //set the style sheet for the internal 
TextField
                        this.textField.styleSheet = style;
                        
                        
                        var wordToHighlight:String = text.substr(0, 
keyword.length);
                        var restOfText:String = text.substr
(keyword.length + 1);
                        
                        this.htmlText =  '<span class="' + 
styleClassName + '">' + wordToHighlight + '</span> ' + restOfText;
                }
                
                
        }
====================================================================

Reply via email to