Skip to main content
Participant
May 22, 2023
Question

Change size of movie clip based on dynamic text box

  • May 22, 2023
  • 1 reply
  • 137 views

Hello,

I  have a map of the US with each state being a movie clip. When the user rolls over a state a pop movie clip appears with some text. (for example:  this.popup.myText.text = "blah blah") The text dynamically changes based on what state it is (all the text is stored in an object array).  Some states have only one sentence while others could be a whole paragraph.  Is there a way to dynamically resize the popup movie clip based on how long the dynamic text box is? Right now its a set height and when the text is really long it flows out of the popup.  I can't seem to find the new height of the text box to then play around with scaling the popup.   thanks!

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    May 22, 2023

    Hi.

     

    Supposing that your pop-up is a MovieClip instance and it is called popUp and that it contains two more children called tf (TextField) and rec (MovieClip).

     

    The code to resize the rectangle inside of it could be something like this:

    var metrics = this.popUp.tf.getMetrics();
    
    this.popUp.rec.scaleX = metrics.width / this.popUp.rec.nominalBounds.width;
    this.popUp.rec.scaleY = metrics.height / this.popUp.rec.nominalBounds.height;

     

    I hope it helps.

     

    Regards,

    JC