Skip to main content
Participant
May 14, 2018
Answered

eval in animate cc

  • May 14, 2018
  • 5 replies
  • 689 views

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

    This topic has been closed for replies.
    Correct answer kglad

    there's no mcfont0 or mcfont2 or...

    use the trace function to debug.

    5 replies

    Legend
    May 14, 2018

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

    Colin Holgate
    Inspiring
    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.

    mohdijmalAuthor
    Participant
    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;

    }

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

    Colin Holgate
    Inspiring
    May 14, 2018

    If it AS3, make sure the font is embedded.

    mohdijmalAuthor
    Participant
    May 15, 2018

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

    Legend
    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);

    }

    Colin Holgate
    Inspiring
    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

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    May 14, 2018

    there's no mcfont0 or mcfont2 or...

    use the trace function to debug.

    mohdijmalAuthor
    Participant
    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!

    kglad
    Community Expert
    Community Expert
    May 15, 2018

    you're welcome.