Hi guys…I am trying to create some more generic code for a project im on…infact you guys have already helped me lots in getting it up and running!
I have basicly got it where all the dragObjects and assigned functions within a for loop and therefore been assigned to their own dropTargets…all working fine, however a situation is needed where if a user drops a clip onto anything rather than a hit area it doesnt just register as an incorrect drop…at the moment a drag that misses a dropTarget will be the same as one that is dropped onto an incorrect drop target and thats just a bit unfair for them as it means they have used up one of only two chances!!!
basicly I need to know if its possible to obtain using the coding style that i already have been whether a drop is onto any of the drop targets before than going to chec if its the correct one or not…sorry for the long winded talk but seemed the only way i could explain!!!
the code i’m using is below
var Xpos:Number;
var Ypos:Number;
var objects:Number = 2;
for (i = 1; i <= objects; i++) {
// assigning the on press events to the dragObjects
this["dragObject"+i+"_mc"].onPress = function() {
this.startDrag(true);
// assigning the original X and Y of the dragged clips
Xpos = this._x;
Ypos = this._y;
}
// assinging the on release events to the dragObjects
this["dragObject"+i+"_mc"].onRelease = function() {
// finding the number of the dragObject to use in the submitAnswer function
objName = this._name
dragNumber = Number(objName.substr(10, 1));
submitAnswer(dragNumber);
}
}
// function to assertain whether the drop was a successful one - whether dropObecjt1 was dragged on dropTarget1 and so on
// the number is passed from the onRealease function
function submitAnswer(dragNumber:Number) {
this.stopDrag();
// if its dropped onto its correct target then turn the button off, place ontop of its target
if (this["dragObject"+dragNumber+"_mc"].hitTest(this["dragTarget"+dragNumber+"_mc"])) {
this["dragObject"+dragNumber+"_mc"].enabled = false;
this["dragObject"+dragNumber+"_mc"]._x = this["dragTarget"+dragNumber+"_mc"]._x+50;
this["dragObject"+dragNumber+"_mc"]._y = this["dragTarget"+dragNumber+"_mc"]._y+50;
trace ("knob jockey");
} else {
// if it is dropped onto a wrong target then chuck it back to where it started!
this["dragObject"+dragNumber+"_mc"]._x = Xpos;
this["dragObject"+dragNumber+"_mc"]._y = Ypos;
}
}
thanks for any help!!