Hello,
I am trying to create a concise piece of code for a drag and drop that I can
reuse again and again. The dragged item should be able to land on any target
(but only one target is correct - although I would like it to be easy to set
more than one target).
I want it to be customisable just by changing parameters in functions (so
people that don't know actionscript very well can use it). I am not really an
expert at actionscript so any help would be gratefully received!
This is as far as I have got although the drag items only stay on the correct
targets:
_root.result=0;
function dragSetup(clip, targ) {
clip.onPress = function() {
startDrag(this);
this.beingDragged=true;
};
clip.onRelease = clip.onReleaseOutside=function () {
stopDrag();
this.beingDragged=false;
if (eval(this._droptarget) == targ) {
this.onTarget = true;
_root.result++;
_root.targ.gotoAndStop(2);
} else {
this.onTarget = false;
_root.targ.gotoAndStop(1);
}
};
clip.startX = clip._x;
clip.startY = clip._y;
clip.endX = targ._x;
clip.endY = targ._y;
clip.onEnterFrame = function() {
if (!this.beingDragged && !this.onTarget) {
this._x -= (this._x-this.startX)/2;
this._y -= (this._y-this.startY)/2;
} else if (!this.beingDragged && this.onTarget) {
this._x -= (this._x-this.endX)/2;
this._y -= (this._y-this.endY)/2;
}
};
}
dragSetup(option1,target1);
dragSetup(option2,target2);
dragSetup(option3,target3);
dragSetup(option4,target4);
dragSetup(option5,target5);
dragSetup(option6,target6);
dragSetup(option7,target7);
thanks
Jo
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com