all groups > flash actionscript > may 2006 >
You're in the

flash actionscript

group:

matching quiz


matching quiz michaelcummings
5/9/2006 8:57:28 PM
flash actionscript:
:confused;

Ok, this may not be that big of a problem, but i've wasted away several hours
trying to fix my problem here....
Im trying to make a sort of matching game, with questions and a wordbank. A
user should be able to drag the words from the word bank into the boxes and
then a check will be done on the drop on wether or not it is in the correct
box.
The catch here is that it is all dynamic movie clips. I dont know how many
questions and answers they are because they are changed and loaded from an XML
file.

I dont know if it is going to work but I was hoping to just declare an id for
each one of the clips as i created them, but i still dont know how to match
them up...

I desperatly need help getting the checking part of this working, as right now
I cannot even figure out the logic behind it. I cant hard code in any drop
zone boundaries, because I dont know how many questions and answers, or what
box, and after I get this working I have to be able to randomize the wordbank.

Any help is going to be greatly appreciated.


//---------CODE-----------------------------------------------------------------
-

import mx.xpath.XPathAPI;

var rssfeed_xml:XML = new XML();
rssfeed_xml.ignoreWhite = true;
rssfeed_xml.load("q&a.xml");

var titlePath:String = "/root/items/item/answer";
var title_array:Array;
var quesPath:String = "/root/items/item/question";
var ques_array:Array;

rssfeed_xml.onLoad = function(success:Boolean)
{
if (success)
{

title_array = XPathAPI.selectNodeList(this.firstChild, titlePath);
ques_array = XPathAPI.selectNodeList(this.firstChild, quesPath);

for (var i = 0; i<title_array.length; i++)
{
trace(title_array[i].firstChild.nodeValue);
}

for (var k = 0; k < ques_array.length; k++)
{
trace(ques_array[k].firstChild.nodeValue);
}

buildQuestionList();
buildAnswerList();
buildAnswerBoxes();



trace("Square " + square_mc0.id)

}
else
{
trace("error loading XML");
}

};

function buildAnswerBoxes()
{

var spacing:Number = 85;
var iconY:Number = 120;
var iconX:Number = 70+250;

for (var k = 0; k < ques_array.length; k++)
{
var newName:String = "square_mc" + k;
var clip_square:MovieClip = _root.square_mc.duplicateMovieClip(newName, 300
+ k);
clip_square.id = k;

trace(newName);
trace(clip_square.id);

clip_square._x = iconX;
clip_square._y = iconY + k * spacing;
clip_square.homeX = clip_square._x;
clip_square.homeY = clip_square._y;
}

}



function buildQuestionList()
{
var spacing:Number = 85;
var iconY:Number = 120;
var iconX:Number = 70;

for (var i = 0; i < ques_array.length; i++)
{
var newName:String = "ques_mc" + i;
var clip:MovieClip = _root.ques_mc.duplicateMovieClip(newName, 500 + i);
clip.id = i;

trace(newName);
trace(clip.id);

clip._x = iconX;
clip._y = iconY + i * spacing;
clip.homeX = clip._x;
clip.homeY = clip._y;

var myString1a:String = ques_array[i].firstChild.nodeValue;
//clip.ans_mc.theChoice.text = myString1a;
clip.theQuestion.text = myString1a;
trace(myString1a);
}



}


function buildAnswerList()
{
var spacing:Number = 85;
var iconY:Number = 120;
var iconX:Number = 70;

for (var i = 0; i<title_array.length; i++)
{
var newName:String = "ans_mc" + i;
var clip:MovieClip = _root.ans_mc.duplicateMovieClip(newName, 1000+i);
clip.id = i;

clip._x = iconX + i * spacing;
clip._y = iconY;
clip.homeX = clip._x;
clip.homeY = clip._y;

var myString1a:String = title_array[i].firstChild.nodeValue;
//clip.ans_mc.theChoice.text = myString1a;
clip.theChoice.text = myString1a;

clip.onPress = function()
{
startDrag(this, false);
};
clip.onRelease = function()
{
stopDrag();
};



}

}
Re: matching quiz TimSymons
5/10/2006 7:39:36 PM
I wrote a simliar engine for a dynamic quiz generator. This is really close.
You should add code to your clip.onRelease event to call a function that will
check to see if 2 movieclips "id" properties are the same.

clip.onRelease = functio() {
stopDrag();
compareID(this, eval(this._droptarget));
};

Then somewhere outside your buildAnswerList function define your compareID
function (or whatever you would like to name it).

function compareID(m1:MovieClip, m2:MovieClip) {
if (m1.id == m2.id) {
// they match!
} else {
// they don't!
}

}

This is just the basic idea but should get you started.

Tim
AddThis Social Bookmark Button