samedi 8 avril 2017

How can I automatically update a TextFieldFormat in AS3?

Everytime I change the text value of a dynamic textfield I have to immediately also assign a value to the TextFormat, or else the text doesn't display anything at all. It's fine, but annoying and easy to forget. So my first question is simply if there is something I'm doing wrong with my TextField that the field requires an immediate call to its TextFormat setter (even if it's already been previously set). If I'm doing everything correctly then my second question is regarding my simple custom class I've made to bypass the repetitive functions. My method was to override the text setter function so that every time I assign a new text value, it also assigns the textFormat value again. I've only ever overridden maybe 1 or 2 other functions before, so I think that is probably where I'm going wrong.

public class DynamicDisplayText extends TextField 
    private var textFilter:GradientGlowFilter = new GradientGlowFilter(4,90,[0xFE23C1, 0xFC9625, 0xFCFFBF], [0, .5, 1], [0, 125, 250],15,15,2,2,"outer",true);
    private var _format:TextFormat;

    public function DynamicDisplayText(format:TextFormat, filtersArray:Array, txt:String):void 
        text = txt;
        _format = format;
        selectable = false;
        mouseEnabled = false;
        embedFonts = true;
        autoSize = TextFieldAutoSize.LEFT;
        filters = filtersArray

    override public function get text():String { return super.text }
    override public function set text(text:String):void {
        super.text = text 
        super.setTextFormat(_format);   // This seems to be the root of the problem



If I remove the super.setTextFormat(_format); and call the setTextFormat function from the Main doc. class, then all works fine. I get error #2007 parameter value must be non null.

Thanks for any tips!

Aucun commentaire:

Enregistrer un commentaire