Skip to main content
Participant
September 20, 2018
Answered

Apply height of one movie clip to other movie clip in HTML5

  • September 20, 2018
  • 1 reply
  • 623 views

Hi,

can somebody help me? I have multiline dynamic text field and I need to copy height of text field and apply to movie clip (box under textfield) height.

thank you 😉

    This topic has been closed for replies.
    Correct answer ClayUUID

    The HTML5 canvas element has no direct means to get the height of rendered text, so the best the CreateJS API can do is estimate it from the current font size. The API function getMeasuredHeight() does this.

    Also, the CreateJS API has no means to directly set the width/height of a symbol. All you can do is set the scale factor. So to resize a symbol to specific dimensions you have to do some math and scale it based on a percentage of its default size, which is stored in its nominalBounds property.

    So to kind-of set a symbol to the height of a text object, you'd do something like:

    this.mySymbol.scaleY = this.myText.getMeasuredHeight() / this.mySymbol.nominalBounds.height;

    (not tested, may fail horribly)

    1 reply

    Joseph Labrecque
    Community Expert
    Community Expert
    September 20, 2018

    You mean dynamically read and write height or via the Animate UI?

    PlamicAuthor
    Participant
    September 20, 2018

    Dynamically read and write

    ClayUUIDCorrect answer
    Legend
    September 20, 2018

    The HTML5 canvas element has no direct means to get the height of rendered text, so the best the CreateJS API can do is estimate it from the current font size. The API function getMeasuredHeight() does this.

    Also, the CreateJS API has no means to directly set the width/height of a symbol. All you can do is set the scale factor. So to resize a symbol to specific dimensions you have to do some math and scale it based on a percentage of its default size, which is stored in its nominalBounds property.

    So to kind-of set a symbol to the height of a text object, you'd do something like:

    this.mySymbol.scaleY = this.myText.getMeasuredHeight() / this.mySymbol.nominalBounds.height;

    (not tested, may fail horribly)