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

Why is this not working?

LEGEND ,
Jun 15, 2018 Jun 15, 2018

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

633
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

LEGEND , Jun 15, 2018 Jun 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

...
Translate
LEGEND ,
Jun 15, 2018 Jun 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 },

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 ,
Jun 15, 2018 Jun 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.

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 ,
Jun 15, 2018 Jun 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.

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 ,
Jun 15, 2018 Jun 15, 2018

Interesting. I'll try that! Thanks for your input.

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

You are right on both points. Everything works if I do not use var and add the code in another frame.

Anyway your first line also worked so I am leaving is that way since I like everything in the same place. I do not like to have to go multiple places to find code especially if there are lots of things going on.

I was thinking there was a scope issue but I got use to have things work in EA in compositionReady where everything was in the same scope so I thought I could do the same with the first frame. Good lesson to learn.

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 ,
Jun 15, 2018 Jun 15, 2018

Sorry about the title. I should know better!

About the array, quotes were necessary in Edge Animate.  (sorry about the edits )

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 ,
Jun 15, 2018 Jun 15, 2018

Actually you are right. I just removed the quotation marks in EA and it worked fine. EA was a little strange sometimes and needed quotes. Oh well...

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