I am having a lot of trouble with finalising the coding for a drag and drop quiz.
I’d like to get the submit button working so the scoring functionality works: so when certain objects are in the wright/wrong target area the results show the correct/incorrect message.
Any help is hugely appreciated.
Thanks.
Here is my current code and .fla file:
stop();
import mx.transitions.;
import mx.transitions.easing.;
targetCount = 0;
dragCount = 0;
submitBtn._alpha = 40;
submitBtn.enabled = false;
function dragSetup(clip, targArray) {
clip.onPress = function() {
startDrag(this);
this.beingDragged = true;
};
clip.onRelease = clip.onReleaseOutside=function () {
stopDrag();
this.beingDragged = false;
for (i=0; i<targArray.length; i++) {
targ = targArray*;
if (eval(this._droptarget) == targ) {
this.myFinalX=targ._x
this.myFinalY=targ._y
this.onTarget = true;
_root.targ._alpha = 30;
break;
} else {
this.onTarget = false;
_root.targ._alpha = 0;
}
}
};
//the variables below will store the clips starting position
clip.myHomeX = clip._x;
clip.myHomeY = clip._y;
clip.myFinalX = 0;
clip.myFinalY = 0;
clip.onEnterFrame = function() {
//all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)
// then move the MC back to its original starting point (with a smooth motion)"
if (!this.beingDragged && !this.onTarget) {
this._x -= (this._x-this.myHomeX)/5;
this._y -= (this._y-this.myHomeY)/5;
//if the circle is dropped on any part of the target it slides to the center of the target
} else if (!this.beingDragged && this.onTarget) {
this._x -= (this._x-this.myFinalX)/5;
this._y -= (this._y-this.myFinalY)/5;
}
};
}
allTargets = new Array(target1, target2, target3, target4);
dragSetup(object1_mc,allTargets);
dragSetup(object2_mc,allTargets);
dragSetup(object3_mc,allTargets);
dragSetup(object4_mc,allTargets);
submitBtn.onPress = function() {
countDown++;
checkAnswers();
this._alpha = 40;
this.enabled = false;
if (count == dragCount) {
showBtn._alpha = 40;
showBtn.enabled = false;
attachMovie(“msgBox”, “msgBoxNew”, 1);
msgBoxNew.txtTitle = “Congratulations”;
msgBoxNew.txtMsg = “All of your answers are correct.”;
msgBoxNew.innerColor = 0xFFFFCC;
msgBoxNew.lineColor = 0x666666;
msgBoxNew.dropShadow = 333333;
msgBoxNew._x = 281;
msgBoxNew._y = 161;
} else if (countDown == 3 && count != dragCount) {
attachMovie(“msgBox”, “msgBoxNew”, 1);
msgBoxNew.txtTitle = “Correct Answers”;
msgBoxNew.txtMsg = “Here are the correct answers.”;
msgBoxNew.innerColor = 0xFFFFCC;
msgBoxNew.lineColor = 0x666666;
msgBoxNew.dropShadow = 333333;
msgBoxNew._x = 281;
msgBoxNew._y = 161;
showme();
} else {
attachMovie(“msgBox”, “msgBoxNew”, 1);
msgBoxNew.txtTitle = “Try Again”;
msgBoxNew.txtMsg = “Some of your answers are not correct. Try Again.”;
msgBoxNew.innerColor = 0xFFFFCC;
msgBoxNew.lineColor = 0x666666;
msgBoxNew.dropShadow = 333333;
msgBoxNew._x = 281;
msgBoxNew._y = 161;
}
};
showBtn.onPress = function() {
showme();
};
function checkAnswers() {
for (x=1; x<=dragCount; x++) {
for (i=0; i<=this[“drag”+x][“myAns”].length; i++) {
if (this[“drag”+x][“myAns”]* == this[“drag”+x].getName) {
this[“drag”+x].dragBtn.enabled = false;
this[“drag”+x].flag = 1;
changeColor = new Color(this[“drag”+x]);
changeColor.setRGB(0x499247);
break;
}
}
if (this[“drag”+x].flag != 1) {
howManyAreWrong++;
targetReset = this[“drag”+x].getName;
this[targetReset].prevFrame();
wrongID = this[“drag”+x]._name;
changeColor = new Color(this[“drag”+x]);
changeColor.setRGB(0x666666);
new Tween(this[wrongID], “_x”, Strong.easeInOut, this[wrongID]._x, this[wrongID].orgX, 28);
new Tween(this[wrongID], “_y”, Strong.easeInOut, this[wrongID]._y, this[wrongID].orgY, 36);
}
}
count = count-howManyAreWrong;
howManyAreWrong = 0;
}
function showme() {
showBtn._alpha = 40;
showBtn.enabled = false;
for (x=1; x<=dragCount; x++) {
findAns = this[“drag”+x].myAns.pop();
new Tween(this[“drag”+x], “_x”, Strong.easeInOut, this[“drag”+x]._x, this[findAns]._x, 28);
finalAni = new Tween(this[“drag”+x], “_y”, Strong.easeInOut, this[“drag”+x]._y, this[findAns]._y, 36);
finalAni.onMotionFinished = function() {
for (x=1; x<=dragCount; x++) {
changeColor = new Color(_root[“drag”+x]);
changeColor.setRGB(0x499247);
}
};
}
}