Copy link to clipboard
Copied
does createjs support as3 "object" keyword. while converting to createjs i am getting error q undefined . the error was coming from this line var question:String = randomQ.q;
anyhow i guess . createjs could not convert qaObject as object . thats why dot operator variable qaObject.q was undefined. and undefined variable error was coming from randomQ.q;
for(var i:Number=0; i<questions.length; i++) {
var qaObject:Object = {};
qaObject.q = questions[i];
qaObject.a = answers[i];
qaArray.push(qaObject); //Add object to qaArray
}
var question:String = randomQ.q;
ok. i converted this like below : just removed the object keyword and put toString(); after q.
/* js
for(var i=0; i<questions.length; i++) {
var qaObject = {};
qaObject.q = questions;
qaObject.a = answers;
qaArray.push(qaObject); //Add object to qaArray
}
var question = randomQ.q.toString();
*/
Copy link to clipboard
Copied
where's randomQ defined?
Copy link to clipboard
Copied
ok. here it is : var randomQ = qaArray[Math.floor((Math.random() * qaArray.length))];
//Assign each question and answer to an object property and add each object to the qaArray
function populateQaArray() {
qaArray = []; // empty array
for(var i:Number=0; i<questions.length; i++) {
var qaObject:Object = {};
qaObject.q = questions;
qaObject.a = answers;
qaArray.push(qaObject); //Add object to qaArray
}
}
//Randomize question
function randomQuestion() {
var randomQ = qaArray[Math.floor((Math.random() * qaArray.length))];
var question:String = randomQ.q;
correctAnswer = randomQ.a;
var qIndex:Number = qaArray.indexOf(randomQ);
//trace(question + " = " + answer);
//trace(qIndex);
qaArray.splice(qIndex, 1); // Remove random question from qaArray if already used once
//trace("current count: " + qaArray.length);
question_txt.htmlText = "<b>TRUE OR FALSE:</b><br>" + question;
true_btn.visible = true;
false_btn.visible = true;
}
Copy link to clipboard
Copied
that's not javascript.
you should be showing the problematic code, not your as3.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now