Parapal Design Flash

A A A Text size

Actionscript source code and FLA files

Drag and DropActionscript with components.

Download Drag and Drop eLearning activity with component labels and targets. Download drag and drop fla and xml file.

Main timeline script

_root.createEmptyMovieClip("topBut", 200); //sets height for top drag button
_root.createEmptyMovieClip("warningLayer", 300);
_root.warning.swapDepths("_root.warningLayer");//moves the warning layer above all objects
complete = false; //exercise not started
loadMovie("veg.jpg", _root.picture); //loads bg picture
//Set requireComplete to true if you want students to try every item before they can check the answer.
requireComplete = true;
//Set clickInPlace to false if you don't want users to see which answers are correct until they finish;
clickInPlace = false;
_global.topMovie = "topBut";
_global.itemsArray = new Array(); //list of drag buttons
_global.posArray = new Array(); //position of drag buttons
_global.completeArray = new Array(); //correctly placed labels
tries = 0;
score = 0;
function checkEx() {
tries++;
tempScore = 0;
checkScore = 0;
for (name in _global.itemsArray) {
checkScore++;
if (_global.itemsArray[name] == true) {
if (clickInPlace == true) {
eval(name)._alpha = 20; //fade out
eval(name).but.enabled = false; //stop dragging
}
tempScore++;
}
}
if (clickInPlace == false) {
_root.feedback = "You have got "+tempScore+" out of "+checkScore+" correct. Try again!!";
_root.warning._visible = true;
}
score = score+((tempScore/checkScore)*100);
if (tempScore == checkScore && complete == true) {
if (tries == 1) {
dispTries = " try.";
} else {
dispTries = " tries.";
}
_root.feedback = "Well Done!! You have completed this exercise.";
_root.feedback += " Your score is "+Math.round(score/tries);
_root.feedback += "%. You needed "+tries+dispTries;
_root.warning.printer._visible = true;
_root.warning._visible = true;
}
}

Code on label component buttons (dragButComp in library)

on (press) {
this.startDrag();
this.swapDepths(eval("_root."+_global.topMovie)); //move to top
_global.topMovie = this._name; //remember next selected button needs to swap with this one
}
on (release, releaseOutside) {
_global.completeArray[this._name] = true;
for (name in _global.completeArray) {
if (_global.completeArray[name] == false) {
_root.complete = false;
break;
}
_root.complete = true;
}
this.stopDrag();
if (eval(this._dropTarget)._name == "bg") {
if ((eval(this._dropTarget)._parent.category) == this.category) {
_global.itemsArray[this._name] = true; //if correct
} else {
_global.itemsArray[this._name] = false; //if false
}
this._x = eval(this._dropTarget)._parent._x+8; //just aligns drop labels
} else {
_root.feedback = "You haven't dropped this on a target. Use the down arrow buttons to make the targets larger";
_root.warning._visible = true;
}
}

 

Code on component labels

_global.posArray[this._name] = new Array(this._x, this._y); //sends name and position to position array
_global.completeArray[this._name] = false; //sends name to tracking array
stop();