Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 Textbox Change Event Not Firing

I built a quiz game with a cartoon question bubble. The bubble is re sized to the length of the question. I want to a change event on the dynamic textbox to call a function that changes the size of the question bubble.

However, the change event is never called when my textbox value is modified dynamically from code.

 question_txt.addEventListener(Event.CHANGE, setTextBubbleSize);

 function setTextBubbleSize(event:Event):void
    {
        trace("QUESTION TEXT CHANGED");
        textBubble_mc.height = 30 + question_txt.text.length * 1.2;
        if (textBubble_mc.height > 170) textBubble_mc.height = 170;
        question_txt.y = textBubble_mc.y - textBubble_mc.height / 6 + 10;
    }

I want to use the change event because there are several places in my code that question_txt can be set. How can I get the textbox to fire the change event?

Also, is there a way to count the number of lines in question_txt to more accurately set the height of textBubble_mc?

like image 590
Bryan Avatar asked Dec 10 '22 20:12

Bryan


1 Answers

I don't think the CHANGE event is fired when you change the textbox's properly with as3. But you can always raise the event by:

dispatchEvent(new Event(Event.CHANGE, true));

For the number of lines in the textbox, you can use the numLines properly of the TextField

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html#numLines

like image 50
David Avatar answered Dec 21 '22 18:12

David