CS3 Learning Interactions

From Wikicliki
Revision as of 00:27, 7 October 2011 by WikiSysop (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Modifying Drag and Drop Learning INteraction (as2)

to make sure the items cannot be dropped on each other:

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;
					}
				}
			}
		}
	}
}