encontrar el último carácter que se muestra en una etiqueta de chispa flexible

Among all the options of the spark label, there is none that tells me the last character shown when the text is truncated, is there any way to accomplish this?

preguntado el 31 de enero de 12 a las 16:01

2 Respuestas

For spark Label you can capture the textLines property after updateDisplayList drew the control.

package frm.ria.signoff.views.components
    import flash.text.engine.TextLine;

    import spark.components.Label;

    import mx.core.mx_internal;

    public class LastShownCharLabel extends Label
        public var lastChar:String;

        protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
                var charsInfirstLine:int = TextLine(mx_internal::textLines[0]).rawTextLength;
                if(text) lastChar = text.charAt(charsInfirstLine-1);

Respondido el 29 de junio de 12 a las 16:06

here is the mxml file for that. please execute the following code.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

        public function onClick():void
            lbl.text = StringUtil.trim(lbl.text);
            output.text = lbl.text.charAt(lbl.text.length -1);

    <mx:Label id="lbl" text="Sagar    "/>
    <mx:Button click="{onClick();}" label="Click" />
    <mx:TextInput id="output" />


Respondido 09 Feb 12, 08:02

that returns the last character in the text property of a label regardless if it is visible or not, I would like to know the character before the "..." that appears at the end when it gets truncated. - Gustavo Parrado

I have edited the code.. and just add a single line that trims the text in textinput... now you will get the correct answer. - Sagar Rawal

still the same result, have in mind that I'm asking about the spark label, not the mx textinput. - Gustavo Parrado

Now is it ok? I have changed the textinput to Label..... and sorry for that because FLEX 4 is not installed in my PC so i can't give you the result of spark label.. but i am sure that similar method is used for that. - Sagar Rawal

well, I did test it on label, the result was as I said, the last character in the whole text property, not the last one shown. Maybe it is one of those things taken out when migrated to spark. - Gustavo Parrado

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.