• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Animate CC HTML5 Canvas subscript

Community Beginner ,
Feb 11, 2021 Feb 11, 2021

Copy link to clipboard

Copied

Hi, 

 

I put together an interactive HTML5 canvas document. 

 

After a week of fighting multiple snags and learning curves, I finally have a working product! Just when I thought I was done, I am stumped once more after I received the content to update the text with. 

 

I am trying to put the word CO2 in there, but I need the 2 to be subscript.

 

var string1 = "how much CO";
var string2 = "2";
var substring = string2.sup();
var string3 = " is used?";


_this.inst_text.text = string1 + substring + string3;

 

It shows up as,

 

"How many <sub>2</sub> is used."

 

I need to stick with Dynamic text because I change it out later in code. 

 

Any suggestions?

 

Thanks!

Views

297

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 11, 2021 Feb 11, 2021

Hi.

 

You can use unicodes and the static method fromCharCode from the String class. Like this:

var root = this;

root.charfromUnicode = function(code)
{
	return String.fromCharCode(parseInt(code, 16));
};

console.log("CO" + root.charfromUnicode(2082));

 

I hope this helps.

 

Regards,

JC 

Votes

Translate

Translate
Community Expert ,
Feb 11, 2021 Feb 11, 2021

Copy link to clipboard

Copied

Hi.

 

You can use unicodes and the static method fromCharCode from the String class. Like this:

var root = this;

root.charfromUnicode = function(code)
{
	return String.fromCharCode(parseInt(code, 16));
};

console.log("CO" + root.charfromUnicode(2082));

 

I hope this helps.

 

Regards,

JC 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 11, 2021 Feb 11, 2021

Copy link to clipboard

Copied

You Rock!

 

That worked no problem. 

 

Thanks very much for the prompt reply.

 

Take care!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2021 Feb 11, 2021

Copy link to clipboard

Copied

LATEST

Excellent! You're welcome!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines