Skip to main content
avid_body16B8
Legend
June 15, 2018
Answered

Why is this not working?

  • June 15, 2018
  • 1 reply
  • 733 views

Coming from Edge Animate, I am baffled on how Animate CC works. In EA, I write all my code in Stage/compositionReady. So I thought that I could do that in Animate CC as well but things do not seem to work all the time.

Could someone tell me why on load, I do not get a random question with code below on frame 1 since it is working with the click event?  (see file)

this.questions.gotoAndStop(questionbank[questionNum].question);

Adobe Creative Cloud

    This topic has been closed for replies.
    Correct answer ClayUUID

    A less generic thread title would be helpful.

    It's not working because that line of code is in the first frame the questions clip exists, so it hasn't initialized yet. You need to delay execution somehow. Replacing the above line of code with this seems to work:

    stage.on("drawstart", function(){this.questions.gotoAndStop(questionbank[questionNum].question)}, this, true);

    BTW, I noticed this in your code:

    {'question': 15, 'correctAnswer' : 'translation' && 'rotation', 'twoanswers' : true},

    You cannot AND strings together in JavaScript. && is a Boolean operator. What are you trying to do here?

    Also, there's no need to put quotes around the key names in object literals. This is just as valid:

    { question: 0, correctAnswer:'rotation', twoanswers: false },

    1 reply

    ClayUUIDCorrect answer
    Legend
    June 15, 2018

    A less generic thread title would be helpful.

    It's not working because that line of code is in the first frame the questions clip exists, so it hasn't initialized yet. You need to delay execution somehow. Replacing the above line of code with this seems to work:

    stage.on("drawstart", function(){this.questions.gotoAndStop(questionbank[questionNum].question)}, this, true);

    BTW, I noticed this in your code:

    {'question': 15, 'correctAnswer' : 'translation' && 'rotation', 'twoanswers' : true},

    You cannot AND strings together in JavaScript. && is a Boolean operator. What are you trying to do here?

    Also, there's no need to put quotes around the key names in object literals. This is just as valid:

    { question: 0, correctAnswer:'rotation', twoanswers: false },

    avid_body16B8
    Legend
    June 15, 2018

    I was wondering about that but when I put the line in a subsequent frame it returns this.questions undefined.

    {'question': 15, 'correctAnswer' : 'translation' && 'rotation', 'twoanswers' : true},

    Well I was not sure about that. I had used || in an array and it worked fine so I was going to try &&.

    I have 3 buttons for choosing an answer - sometimes the student needs to click 2 buttons to get the correct answer. I suppose I could push answers in an array and then compare that.

    Legend
    June 15, 2018

    resdesign  wrote

    I was wondering about that but when I put the line in a subsequent frame it returns this.questions undefined.

    Are you sure you weren't getting questionBank is undefined? That's what would happen, since your question bank is defined with var, meaning it's only accessible to the current frame.

    It doesn't matter if it's || or &&, you can't use Boolean operators on strings and expect sensible results, because strings are not Boolean data. You can't combine two strings together like some sort of Brundlefly. So yes, an array would be the way to go. Something like:

    { question : 5, answers : ["ref"] },

    { question : 19, answers : ["trans", "rot"] },

    Shortening the strings for each answer type is recommended because the less typing, the less chance of typos. Me, I'd just assign a number to each type of answer and keep a reference sheet handy.