Flash Matching Question
Hello,
I have a flash matching exercise that allows users to drag and drop words into 2 locations: adjective and noun. However, right now I am only ever able to drop one word on adjective and one on noun. If I try to drop others on adjective or noun they don't register in the ActionScript.
Link to file (try dropping both on adjective for instance and notice you don't always get the feedback):
http://distance.uaf.edu/projects/flash-tutors/jensmatching.html
Here's the script I'm currently using:
var dict = new Dictionary ();
// =================== Edit =====================
dict[box_a] = cloudy;
dict[box_n] = artichoke;
// ===================== END ====================
var hits = 0; // counts succesful hits
var max = 0; // used to compute dictionary length
// For each item in the dictionary we add event listeners
// "for each" will loop through the values ... not the keys
for each (var item in dict)
{
item.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
item.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
max = max + 1;
item.buttonMode = true; //needed for the hand cursor
}
// Define a mouse down handler (user is dragging)
function mouseDownHandler(evt:MouseEvent):void {
var object = evt.target;
// we should limit dragging to the area inside the canvas
object.useHandCursor = true;
object.startDrag();
}
function mouseUpHandler(evt:MouseEvent):void {
var obj = evt.target;
// obj.dropTarget will give us the reference to the shape of
// the object over which we dropped the circle.
var target = obj.dropTarget;
// If the target object exists the we ask the test_match function
// to compare moved obj and target where it was dropped.
if (target != null)
{
test_match(target, obj);
}
obj.stopDrag();
}
function test_match(target,obj) {
// test if the pairs match
if (dict[target] == obj)
{
// we got a hit
hits = hits+1;
textField.text = "Yes ! You got one !";
// make the object transparent
obj.alpha = 0.5;
// kill its event listeners - object can't be moved anymore
obj.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
obj.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
// Test if we are done
if (hits == max)
{
textField.text = "Excellent!";
}
}
else
{
textField.text = "Try Again :(";
}
}