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

defining as3 object keyword in createjs

Contributor ,
Mar 31, 2016 Mar 31, 2016

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

*/

TOPICS
ActionScript
568
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 ,
Mar 31, 2016 Mar 31, 2016

where's randomQ defined?

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
Contributor ,
Mar 31, 2016 Mar 31, 2016

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;

}

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 ,
Mar 31, 2016 Mar 31, 2016
LATEST

that's not javascript.

you should be showing the problematic code, not your as3.

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