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

eval in animate cc

Community Beginner ,
May 14, 2018 May 14, 2018

hi, i'm looking for an answer why the static code is working, not dynamically as below.

this.mcfont1.txt.text  ===> there's a dynamic text inside a movieclip

///////////

var arr = ["A", "R", "U", "S", "E", "L", "E", "K", "T", "R", "I", "K", r(), r(), r()];

function r() {

var chars = "ABCDEFGHIJKLMNOPQURSTUVWXYZ";

return chars.substr(Math.floor(Math.random() * 62), 1);

}

for (var i = 0; i < arr.length; i++) {

//this["mcfont" + i].txt.text = arr;  <-----not working

this.mcfont1.txt.text = arr; <-----working

}

////////////////////////

thank you in advance

591
Translate
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 , May 14, 2018 May 14, 2018

there's no mcfont0 or mcfont2 or...

use the trace function to debug.

Translate
Community Expert ,
May 14, 2018 May 14, 2018

there's no mcfont0 or mcfont2 or...

use the trace function to debug.

Translate
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 ,
May 15, 2018 May 15, 2018

hahaha thanks alot ...

forgot there's no mcfont0

this["mcfont" + (i+1)].txt.text = arr;<----this worked

alert(arr);

hahahaha...

ABCDEFGHIJKLMNOPQURSTUVWXYZ<----also been corrected

thanks alot everyone!

Translate
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 ,
May 15, 2018 May 15, 2018
LATEST

you're welcome.

Translate
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
LEGEND ,
May 14, 2018 May 14, 2018

The <----- parts would break the code, but I imagine you don't really have those in there. It mostly seems to work, though I've never used function calls inside an array before.

Could it be your dyslexic code? What happens in you use * 26 instead of * 62? Also, the alphabet is wrong:

ABCDEFGHIJKLMNOPQURSTUVWXYZ

instead of:

ABCDEFGHIJKLMNOPQRSTUVWXYZ

Translate
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
LEGEND ,
May 14, 2018 May 14, 2018

Your thread title mentions "eval". There is no "eval" anywhere in your code. So I don't know what you're asking.

But, your r() function includes "U" twice, and attempts to select characters up to position 62, even though the string only has 27 characters. Assuming you just want to return random uppercase letters, the entire thing can be replaced with:

function r() {

    return String.fromCharCode(65 + Math.random() * 26);

}

Translate
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
LEGEND ,
May 14, 2018 May 14, 2018

If it AS3, make sure the font is embedded.

Translate
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 ,
May 15, 2018 May 15, 2018

by the way i'm testing this on html canvas animate cc

Translate
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
LEGEND ,
May 14, 2018 May 14, 2018

Wait... surely he's aware that his not-working code is attempting to assign to this.mcfont0.

Translate
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
LEGEND ,
May 14, 2018 May 14, 2018

That's an assumption on our part. His example of mcfont1 working does suggest that possibility, but maybe he does have an mcfont0 on his stage.

Translate
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 ,
May 15, 2018 May 15, 2018

this seems running fine

////////////////////////////////

function r() {

    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    return chars.substr(Math.floor(Math.random() * 26), 1);

    //return String.chars(65 + Math.random() * 26);

}

var arr = ["A", "R", "U", "S", "E", "L", "E", "K", "T", "R", "I", "K", r(), r(), r()];

alert("this is shit" + arr);

//alert(arr.length)

for (var i = 0; i < arr.length; i++) {

    this["mcfont" + (i+1)].txt.text = arr;

    alert(arr);

    //this.mcfont1.txt.text = arr;

}

/////////////

Translate
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