CS3 Learning Interactions
Modifying Drag and Drop Learning Interaction (as2)
my folly was to use a very old cs3 "drag and drop" learning interaction in an as2 project because i wanted to speed up the process of building it. but then... i had to fix some odd features of it. for example it allows you to drag multiple objects into the same dropzone. preposterous!
i woke up late and realised i had half an hour to sort this problem out. the simpliest hack to it? if it walks like a duck and quacks like a duck, it must be a duck. i noticed that if you trace the object below it, it will always return if it is a target, or a drag object. They were all named Target1, Target2, etc, and Drag1, Drag2... so if i could take that first alphabet of the name of the object below and check it then i could make such that you could only drop on the dropzone when the object below was a T (target). if there was another drag object below it would be D and thus we would prevent you from dropping it then.
as meerkat would say: "SIMPLES!"
the only place you have to edit is this onDDinit function:
function onDDinit(){
var router = _parent.SessionArray[_parent.session];
var len = router.drag_objects.length;
for (var i=0; i < len; i++){
_parent[router.drag_objects[i]].onPress = function() {
if(router.scoreFlag != true){
router.setComponentState(router.Assets.ResetButton,true);
if(!_parent.topDepth) _parent.topDepth = 100;
if (!this.dragStart){
this.startDepth = this.getDepth();
this.startX = this._x;
this.startY = this._y;
this.dragStart = true;
}
if (this.finished != true){
this.swapDepths(_parent.topDepth);
_parent.topDepth++;
this.startDrag();
}
}
}
_parent[router.drag_objects[i]].onRelease = function() {
if(router.scoreFlag != true){
this.stopDrag();
var len = router.target_objects.length;
var target = eval(this._droptarget)._name;
if( target != undefined ){
for(var i=0; i < len; i++){
if (target == router.target_objects[i]){
this.dropValue = router.target_object_key[i];
this.dropZone = true;
break;
}
if (_parent[target] == _parent[router.drag_objects[i]]){
if(_parent[target].dropValue != undefined){
this.dropValue = _parent[target].dropValue;
this.dropZone = true;
break;
}
}
}
}
//my addition
var temp_str = [target];
temp_var = String(temp_str);
temp_letter = temp_var.slice(0,1);
trace("temp_letter = "+temp_letter);
if (this.dropZone == true && temp_letter == "T") {
router.setComponentState(router.Assets.ControlButton, true);
router.setFeedback(1);
this._x = _parent[target]._x;
this._y = _parent[target]._y;
this.finished = true;
}
else{
if(router.snapToStart == true){
this._x = this.startX;
this._y = this.startY;
}
}
}
}
}
}