Default Dynamic Text auto scale font, input from input text first

Hi guys,

I have an issue with font scaling of a dynamic text box.

Currently i have one input box named input_1 with a variable attached to it named “choc_1”.

Also, i have a dynamic text box named dynamic_1 with variable “choc_1”.

When the user types something on the input box then the dynamic box changes instantly and displays what the user has written.

I’ve googled a lot, but i can’t find a solution to auto scale-size the fonts to a smaller size if the user types many letters.

The input_1 box has a 13 character limit. My initial font size is 200, i want to scale down so when the user types 10 letters they fit the box and they don’t go out of screen. I want to use one line, so wrap or multiline is not possible.

here’s a code that i’m trying to fix but i can’t get the dynamic box to change:

AS2:

     this.dynamic_1.antiAliasType = AntiAliasType.ADVANCED;
            this.dynamic_1.gridFitType = GridFitType.SUBPIXEL;
            this.dynamic_1.autoSize = TextFieldAutoSize.LEFT;
            this.dynamic_1.y = -20;
            this.txtFormat = new TextFormat();
            this.txtFormat.rightMargin = 4;
            this.txtFormat.size = 10;
            this.txtFormat.letterSpacing = -8;
            this.dynamic_1.defaultTextFormat = this.txtFormat;
            this.input_1.addEventListener(Event.CHANGE,this.updateWhileTyping);
            var maxTextWidth = 450;
            var maxTextHeight = 100;
 function convertCharacters()
        {
            var loc_1 = "";
            loc_1 = this.inputText.text.toString();
            this.dynamic_1.text = "";
            var loc_2 = 0;
            while (loc_2 < this.input_1.length)
            {
                
                this.dynamic_1.appendText(this.convertchar(loc_1.charAt(loc_2)));
                loc_2++;
            }
            this.inptut_1.text = this.textOnPackage.text;
            this.input_1.setSelection(this.input_1.length, this.input_1.length);
            return;
        }// end function

        function updateWhileTyping()
        {
            this.convertCharacters();
            var loc_3 = this.dynamic_1.getTextFormat();
            while (this.dynamic_1.textWidth > this.maxTextWidth || this.dynamic_1.textHeight > this.maxTextHeight)
            {
                
                loc_3.size = int(loc_3.size) - 1;
                this.dynamic_1.setTextFormat(loc_3);
            }
            this.size = loc_3.size;
            this.dynamic_1.y = this.dynamic_1.y == 46 ? (-20) : (Math.ceil(this.height * 0.5 - this.dynamic_1.height * 0.5) - 60);
            return;
        }// end function}