Skip to main content
Inspiring
March 25, 2019
Answered

Font size for TextInput component in Animate CC HTML5 Canvas

  • March 25, 2019
  • 2 replies
  • 3502 views

I'm converting Flash animations to HTML5 Canvas in Animate CC. How do I change the font size and font for a TextInput component?

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

Here is one way of doing it:

- You use a setTimeout method to make sure the component it's ready to be referenced in the beginning;

- Access the div element called dom_overlay_container created by Animate CC that holds all DOM based components (e.g.: TextInput and CheckBox).

- Then use bracket notation to reference the instance name of your component in the children property;

- Finally, you can set any valid CSS property through the JavaScript style property.

Like this:

var textInput;

setTimeout(function()

{

    // dom_overlay_container is a global reference to a div element created by Animate CC. "txt" is the instance name of your component

    textInput = dom_overlay_container.children["txt"];

    textInput.style.fontSize = "28px";

    textInput.style.fontFamily = "'Comic Sans MS', cursive, sans-serif";

}, 0);

Regards,

JC

2 replies

Dr. Ayman Raafat Ph.D
Inspiring
March 25, 2019

Also try to check this form answers

vFont/Text looks pixelated HTML5 Canvas output. Any way to fix this?

it may be helpful for you .

Ayman

avid_body16B8
Legend
March 26, 2019

since jquery loads when you add a component, I use CSS to set the text input component like this:

$("#answer1").css({

        "color": "teal",

        "font-size": 18,

        "text-align": "center"

    });

answer1 is the instance name of the component.

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
March 25, 2019

Hi.

Here is one way of doing it:

- You use a setTimeout method to make sure the component it's ready to be referenced in the beginning;

- Access the div element called dom_overlay_container created by Animate CC that holds all DOM based components (e.g.: TextInput and CheckBox).

- Then use bracket notation to reference the instance name of your component in the children property;

- Finally, you can set any valid CSS property through the JavaScript style property.

Like this:

var textInput;

setTimeout(function()

{

    // dom_overlay_container is a global reference to a div element created by Animate CC. "txt" is the instance name of your component

    textInput = dom_overlay_container.children["txt"];

    textInput.style.fontSize = "28px";

    textInput.style.fontFamily = "'Comic Sans MS', cursive, sans-serif";

}, 0);

Regards,

JC

Inspiring
March 26, 2019

Thanks for the help, but I'm sorry it didn't work. I still get the tiny font size I was getting without your code.

JoãoCésar17023019
Community Expert
Community Expert
March 26, 2019

Are you getting any error in the browser console?