dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 33

Thread: post for ram_son

  1. #1
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176

    post for ram_son

    ref: your private message -- for the good of all, please keep posts on the forum.

    ref: your question on randomising the content of your xml file -

    PHP Code:
    arr = []; // array to hold the xml data

    _xml = new XML();
    _xml.ignoreWhite = true;
    _xml.load("test.xml");

    _xml.onLoad = function(){
    cNodes = this.firstChild.childNodes;
    len = cNodes.length;
    for(var n=0;n!=len;n++){
    obj = {}; // create an object
    obj.theWord = cNodes[n].attributes['theWord'];
    obj.theSynonym = cNodes[n].attributes['theSynonym'];
    arr.push(obj); // add the object to the array
    }
    randArray();
    };

    function randArray(){
    arr.sort(function(){return Math.floor(Math.random()*3)-1}); // randomise the array
    for(var n=0;n!=arr.length;n++){
    trace("arr["+n+"].theWord = "+arr[n].theWord);
    trace("arr["+n+"].theSynonym = "+arr[n].theSynonym+newline);
    }
    };

    /* - in test.xml -

    <?xml version="1.0" encoding="UTF-8"?> 
    <rNode>
    <cNode theWord="A" theSynonym="a" /> 
    <cNode theWord="B" theSynonym="b" />
    <cNode theWord="C" theSynonym="c" />
    <cNode theWord="D" theSynonym="d" />
    <cNode theWord="E" theSynonym="e" /> 
    </rNode>

    */

  2. #2
    Member
    Join Date
    Aug 2009
    Posts
    44
    Thanks for replying so quickly. However, this does not seem to do what I had in mind. This gave me an output like this:

    arr[0].theWord = D
    arr[0].theSynonym = d

    arr[1].theWord = E
    arr[1].theSynonym = e

    and so on.. But what I was looking for is more of a MC quiz where one label displays a "Word" and the four other labels display four choices of "Synonyms" with the correct answer showing up in different labels every time. Then when the user click on the correct answer he'll get credit and when he doesn't get it right he'll get a message.
    I hope I made things clearer this time.
    Thanks

  3. #3
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    so the xml you provided for me to work on is not the correct format ?

    should it be more like this -

    <cNode theWord="A" answer1="a" answer2="b" answer3="c" answer4="d" />

    have a look at this link (uses .txt input, you can modify to xml)

  4. #4
    Member
    Join Date
    Aug 2009
    Posts
    44
    You don't think I can have 3 wrong synonyms and one correct one chosen from the xml file in its present format.

  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    in this format -
    <cNode theWord="A" theSynonym="a" />

    how would you select the 3 wrong synonyms ? the one correct is "a" ?

  6. #6
    Member
    Join Date
    Aug 2009
    Posts
    44
    It was done in vb6 by randomly choosing 3 other synonyms from a text file that similarly had only two "columns" in addition to the correct answer. I can post that code if you are familiar with vb6 or if it will help develop a different approach. I am trying to avoid redoing the xml file as it is kind of long. Aother idea is to choose 4 wrong answers and then replace one label with the correct answer.

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    is this approach more suitable ?
    (trace only, needs outputting to textfields/radiobuttons as per your project)

    PHP Code:
    arr = [];
    id = 0;

    _xml = new XML();
    _xml.ignoreWhite = true;
    _xml.load("test.xml");

    _xml.onLoad = function(){
    cNodes = this.firstChild.childNodes;
    len = cNodes.length;
    for(var n=0;n!=len;n++){
    obj = {};
    obj.theWord = cNodes[n].attributes['theWord'];
    obj.theSynonym = cNodes[n].attributes['theSynonym'];
    arr.push(obj);
    }
    randArray();
    };

    function randArray(){
    arr.sort(function(){return Math.floor(Math.random()*3)-1});
    for(var n=0;n!=arr.length;n++){
    trace("arr["+n+"].theWord = "+arr[n].theWord);
    trace("arr["+n+"].theSynonym = "+arr[n].theSynonym+newline);
    }
    askQuestion(id);
    };

    function askQuestion(id){ 
    trace("question "+(id+1)+" = "+arr[id].theWord);
    trace("correct answer = "+arr[id].theSynonym);
    for(var n=0;n!=4;n++){
    if(arr[n].theSynonym != arr[id].theSynonym){
    trace("incorrect answers = "+arr[n].theSynonym);
    }
    }
    trace(" - - - - ");
    };

    nextBtn.onRelease = function(){
    id++;
    if(id > arr.length-1){
    id = 0;
    randArray();
    trace(" * * * *");
    }
    askQuestion(id);
    };

    /* - in test.xml -

    <?xml version="1.0" encoding="UTF-8"?> 
    <rNode>
    <cNode theWord="A" theSynonym="a" /> 
    <cNode theWord="B" theSynonym="b" />
    <cNode theWord="C" theSynonym="c" />
    <cNode theWord="D" theSynonym="d" />
    <cNode theWord="E" theSynonym="e" /> 
    </rNode>

    */

  8. #8
    Member
    Join Date
    Aug 2009
    Posts
    44
    Great ! That's the idea a_modified_dog! That's exactly what I meant. But how do I randomise the assignment to labels named text2 through text5?

  9. #9
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    with textfields on stage with instance names - text2 through text5
    and original _y postions of 20, 40, 60, 80

    use 2 arrays, randomise the position array (arrX), and loop through setting
    textfield (arrTxt) to its _y position.

    PHP Code:
    arrTxt = [text2,text3,text4,text5];
    arrX = [20,40,60,80];

    arrX.sort(function(){return Math.floor(Math.random()*3)-1});

    for(var 
    p=0;p!=arrTxt.length;p++){
    arrTxt[p]._y arrX[p];


  10. #10
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    the askQuestion would need to be changed to -

    PHP Code:
    arrTxt = [text2,text3,text4,text5];
    arrX = [20,40,60,80];

    function 
    askQuestion(id){ 
    arrX.sort(function(){return Math.floor(Math.random()*3)-1});
    correctAnsw arr[id].theSynonym;
    arrTxt[0].text correctAnsw// correct answer

    for(var p=0;p!=4;p++){
    arrTxt[p]._y arrX[p]; 
    if(
    arr[p].theSynonym != correctAnsw){
    arrTxt[p].text arr[p+1].theSynonym// incorrect answers
    }

    text1.text arr[id].theWord// question
    }; 

  11. #11
    Member
    Join Date
    Aug 2009
    Posts
    44
    I cannot get the text displayed in the labels so far... I have 5 textfields on stage with instance names - text1through text5. Text1 is supposed to display the word or question and the rest text2 through text5 to show the synonym choices randomising in which textfield the correct answer will appear. I haven't had any success yet. Is this what this last bit of code supposed to do?
    I also noticed in the output window that after I hit the nextBtn 4 times I start getting f4 incorrect answers intead of three.

  12. #12
    Member
    Join Date
    Aug 2009
    Posts
    44
    After I changed the askQuestion routine, the textfields are populated with choices but there is something wrong because the correcrt answer is not appearing in the choices. Maybe it has something to do with the incorrect answers choices increasing from three to four after hitting the next button a few times.

  13. #13
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    here is my test file
    can you upload your fla and xml for me to look at.
    Attached Files Attached Files
    Last edited by a_modified_dog; 10-15-2009 at 05:16 PM.

  14. #14
    Member
    Join Date
    Aug 2009
    Posts
    44
    I tried your fla with the attached test.xml file and it does the same thing where the choices of wrong answer turn into 4 instead of three and the correct answer is no longer part of the displayed choices. I wanted to try an xml that had more words and that's when the problem started. See please take alook and see what's wrong.
    Attached Files Attached Files

  15. #15
    Member
    Join Date
    Aug 2009
    Posts
    44
    I made an xml with more words which demonstrates the problem more clearly. Just watch the output window when hitting the next button and you will notice that the incorrect choices no longer change. Only the question and the correct answer change.

  16. #16
    Member
    Join Date
    Aug 2009
    Posts
    44
    sorry didn't attach file!
    Attached Files Attached Files

  17. #17
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    OK, i see the problem here
    replace the askQuestion function with this.

    PHP Code:
    function askQuestion(id){

    tmp = []; // temp array for all wrong answers
    for(var n=0;n!=arr.length;n++){
    if(
    arr[n].theSynonym != arr[id].theSynonym){
    tmp.push(arr[n].theSynonym);
    }
    }
    tmp.sort(function(){return Math.floor(Math.random()*3)-1}); // shuffle 'em

    arrTxt = [text2,text3,text4,text5];
    arrX = [20,40,60,80]; 
    arrX.sort(function(){return Math.floor(Math.random()*3)-1});

    for(var 
    p=0;p!=4;p++){
    arrTxt[p]._y arrX[p];
    arrTxt[p].text tmp[p]; // incorrect answers
    }

    correctAnsw arr[id].theSynonym
    arrTxt[0].text correctAnsw// correct answer
    arrTxt[0].textColor 0xFF0000;  // red text for testing purposes

    text1.text arr[id].theWord// question
    }; 
    seems to work fine here. can you thoroughly test

  18. #18
    Member
    Join Date
    Aug 2009
    Posts
    44
    That seem to have done it!! I will test it more thorougly with the complete xml db file. One more question if possible. Would I be able to add buttons to specify that the testing to be done only on part of the db instead of the whole thing at once. In other words, be able to add a button that specifies testing from word #1 through 100 and another to go from 101 through 200 and so on.. Is it possible to achieve such a result with this setup?

  19. #19
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    yes it's possible

    the variable id is what increments you through the questions.
    you would need an if(condition) statement to detect when id==100;
    when id is 100, stop the quiz and start a new quiz where id is set to 101.

  20. #20
    Member
    Join Date
    Aug 2009
    Posts
    44
    When I expanded the xml to100 words and tested it seems that the randomisation moves up the list gradually. It does not go from say word #6 to word #55 and then back to #10 and up to #78 and so on...instead it goes from say #5 to 7,11,15,20 and so on up the liast. It would be better if it skips around more. Attached is the expanded file.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center