flash actionscript:
I've searched and searched everywhere for help on this problem, but no luck so
far. :confused:
Here goes,
I have a VERY robust scorm quiz that has Multiple Choice, True-False, Fill in
the Blank, Matching, Multiple Response, etc. The questions are imported from a
XML file and the user then answers the questions (just like a quiz, duh). If
the user answers correctly it says correct and goes to the next question, it
the user answers incorrectly it tells you the correct answer and then goes on
to the next question.
The problem is with the Fill in the blank.
<query type="FIB" image="" restriction="">
<question><![CDATA[blah _____ blah]]></question>
<feedback><![CDATA[The correct answer is, blah]]></feedback>
<answers>
<answer data="blha,bla,blaw,blah"><![CDATA[blah]]></answer>
</answers>
</query>
It pulls the question, the <![CDATA[blah]]> is the real correct answer, then
in the <answer data="blah"> is possible answers the user can use to get the
answer correct. When the possible answers are more than one character long, it
works perfectly. However when there is one like this:
<query type="FIB" image="" restriction="">
<question><![CDATA[filler words]]></question>
<feedback><![CDATA[The correct answer is, the]]></feedback>
<answers>
<answer data="a,of,the,umm"><![CDATA[the]]></answer>
</answers>
</query>
it only reads the first possible answer "a" and not the others, so if the user
types in "of" or "the" the answer is incorrect, and it should be correct.
Any suggestions on fixing this problem.
i.e.
here is the Fill in the blank actionscript file.
import com.folder.cbt.exam.view.questions.*;
import mx.controls.*;
dynamic class com.folder.cbt.exam.view.questions.FIB extends QuestionCore
implements QuestionType {
private var question:Object;
private var answered:Array = null;
private var restriction:String = null;
private var userAnswers:Array = null;
function FIB() {}
public function init(question:Object):Void {
this.question = question;
this.userAnswers = new Array();
if(question.restrictions != undefined){
this.restriction = question.restrictions;
}else{
this.restriction = "";
}
this.createQuestion(question.answers);
}
function createQuestion(answers:Array):Void{
var n:Number = answers.length;
for(var i:Number = 0; i < n; i++){
var z:String = "fLabel" + i;
this.createClassObject(Label,"fLabel" + i, 100 + i,{autoSize:"left"});
this[z].text = "YOUR ANSWER:" ;
this[z].setStyle("embedFonts",true);
this[z].setStyle("fontFamily","sans");
this[z].setStyle("fontSize",12);
this[z].setStyle("fontWeight","bold");
this[z].setStyle("color","0x666666");
this[z]._x = 10;
this[z]._y = 5 + (i * 24);
this.createClassObject(TextInput,"answer" + i, 200 + i);
var name:String = "answer" + i;
this[name]._x = 120;
this[name]._y = 3 + (i * 24);
this[name].setSize(797,22);
this[name].data = answers.data;
this[name].restrict = restriction;
}
this.answer0.setFocus();
}
public function destroyQuestion():Void {
this.removeMovieClip();
}
public function destroyAnswers():Void{
var len:Number = this.question.answers.length;
for(var i:Number = 0; i < len; i++){
this.destroyObject("fLabel" + i);
this.destroyObject("answer" + i);
}
}
public function disableAnswers():Void{
var len:Number = this.question.answers.length;
for(var i:Number = 0; i < len; i++){
this["answer" + i].enabled = false;
}
}
public function enableAnswers():Void{
var len:Number = this.question.answers.length;
for(var i:Number = 0; i < len; i++){
this["answer" + i].enabled = true;
}
}
public function verifyAnswered():Boolean{
var len:Number = this.question.answers.length;
for(var i:Number = 0; i < len; i++){
var name:String = "answer" +i;
if(this[name].text == (undefined || "")){
return false;
}
}
return true;
}
public function collectAnswers():Array{
var len:Number = this.question.answers.length;
answered = new Array();
for(var i:Number = 0; i < len; i++){
var name:String = "answer" + i;
answered = this[name].text;
if(i < (len-1)){
userAnswers = answered + ",";
}else{
userAnswers = answered;
}
}
return answered;
}
public function clearAnswers():Void{
var len:Number = this.question.answers.length;
for(var i:Number = 0; i < len; i++){
var name:String = "answer" + i;
this[name].text = "";
}
}
public function restoreAnswers(val:Array):Void{
var temp:Array = new Array();
if(val == undefined){
temp = answered;
}else{
temp = val;
}
var len:Number = this.question.answers.length;
for(var i:Number = 0; i < len; i++){
var name:String = "answer" + i;
this[name].text = temp;
}
}
public function gradeQuestion():Boolean{
var len:Number = this.question.answers.length;
for(var i:Number = 0; i < len; i++){
var name:String = "answer" + i;
var dataArr:Array = this.question.answers.data.split(",");
var len2:Number = dataArr.length;
var correct:Number = 0;
for(var j:Number = 0; j < len2; j++){
if(this[name].text == dataArr[j]){
correct++;
}
}
if(correct == 0){
return false;
}
}
return true;
}
public function correctAnswers():String{
var correct:String = "";
var len:Number = this.question.answers.length;
for(var i:Number = -1; i < len; i++){
var dataArr:Array = this.question.answers.data.split(",");
correct += dataArr[0] + ", ";
}
return correct.substr(0,correct.length - 2);
}
public function userSelection():String{
var len:Number = userAnswers.length;
var tans:String = "";
for(var i:Number = 0; i < len; i++){
tans += userAnswers;
}
return tans;
}
public function sendLMSData(val:Number,id:Number,s:Boolean):Void {
}
}
any help would be helpful. Thank you.