Drag&Drop mit mouse over und einem target

Touya

Mitglied
Hi,

so, da ich seid kurzem (gestern) besitzer von Flash mx bin, habe ich mich heute schon fleißig dran gegeben und ein paar möglichkeiten die mir Flash in bezug auf drag and drop bietet ausprobiert.Eine funktionierende drag&drag navi ist mir auch schon gelungen (yeah..)
Bestehend aus 3 punkten. 2 davon sind punkte die in den 3ten punkt (target) gezogen werden können. Jetzt möchte ich allerdings ein paar modifikationen vornehmen wie zum Beispiel:
- wenn einer der 2 kleinen punkte über dem target schwebt, soll sich dieser weiter öffnen
- wenn bereits ein punkt im target ist, soll beim versuch einen 2ten punkt zu platzieren der alte rausgeworfen werden, damit der 2te platz hat.

das wäre es erstmal soweit. Ich hoffe auf eure hilfe! :confused:
hier noch der code:
Code:
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.targetCircle.gotoAndStop(2);
} else {
this.onTarget = false;
_root.targetCircle.gotoAndStop(1);
}
};

//the variables below will store the clips starting position
clip.myHomeX = clip._x;
clip.myHomeY = clip._y;
//the variables below will store the clips end position
clip.myFinalX = targ._x;
clip.myFinalY = targ._y;
clip.onEnterFrame = function() {
//all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)
// then move the MC back to its original starting point (with a smooth motion)"
if (!this.beingDragged && !this.onTarget) {
this._x -= (this._x-this.myHomeX)/5;
this._y -= (this._y-this.myHomeY)/5;
//if the circle is dropped on any part of the target it slides to the center of the target
} else if (!this.beingDragged && this.onTarget) {
this._x -= (this._x-this.myFinalX)/5;
this._y -= (this._y-this.myFinalY)/5;
}
};
} 
dragSetup(circle34_mc,targetCircle);
dragSetup(circle_mc,targetCircle);
 
Hi,

kannst Du die Datei (.fla) einmal posten? Es ist immer ziemlich umständlich, von reinem Code auf den tatsächlichen Film zu schliessen bzw. die alles auf gut Glück nachbauen zu müssen, um Modifikationen zu testen.

Gruß
.
 
dann wollen wir mal nicht so kniepig mit dem tutorials.de space sein -g-
hier ist also die fla:
 

Anhänge

  • dragndrop.zip
    4,4 KB · Aufrufe: 29
Hi,

so?
PHP:
function dragSetup(clip, targ, other) {
	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.targetCircle.gotoAndStop(2);
			other.onTarget = false;
			other.beingDragged = false;
		} else if (eval(this._droptarget) == other) {
			if (other.onTarget) {
				this.onTarget = true;
				_root.targetCircle.gotoAndStop(2);
				other.onTarget = false;
				other.beingDragged = false;
			}
		} else {
			this.onTarget = false;
			_root.targetCircle.gotoAndStop(1);
		}
	}
	clip.myHomeX = clip._x;
	clip.myHomeY = clip._y;
	clip.myFinalX = targ._x;
	clip.myFinalY = targ._y;
	clip.onEnterFrame = function() {
		if (!this.beingDragged && !this.onTarget) {
			this._x -= (this._x-this.myHomeX)/5;
			this._y -= (this._y-this.myHomeY)/5;
		} else if (!this.beingDragged && this.onTarget) {
			this._x -= (this._x-this.myFinalX)/5;
			this._y -= (this._y-this.myFinalY)/5;
		}
	}
} 
dragSetup(circle34_mc,targetCircle, circle_mc);
dragSetup(circle_mc,targetCircle, circle34_mc);

Bei einem anderen Setup ginge das noch um einiges kürzer, aber ich hab einfach mal so wenig geändert wie möglich.

Gruß
,
 
also erstmal vielen Dank, die Lösung ist sehr gut.
Ein Problem gibt es allerdings noch:
ich möchte die Anzahl der Punkte beliebig erweitern können. Wüßtest du da auch eine Lösung?
 
Ja, aber dann würde ich das a) mit Arrays und b) etwas anders angehen.

Ich schau mal, ob ich nachher einen Vorschlag zusammenbekomme und melde mich dann wieder.

Gruß
.
 
würde mich auf jeden fall riesig erleichtern, wenn du die erweiterung auch noch hinbekommen könntest. Danke im Vorraus!
 
Hi,

jetzt hatte ich eben mal Zeit (gestern war ich noch unterwegs).

Wenn Fragen zu dem Anhang auftauchen: Bitte noch einmal melden!

Gruß
.
 

Anhänge

  • droptarget2.zip
    7,9 KB · Aufrufe: 33
Hi Dratic,

die swf sieht wunderprächtig aus, genau so hatte ich´s mir vorgestellt!!
Leider kann ich die .fla nicht öffnen, ich denke das liegt an dem versionen unterschied. Ich benutze Flash MX vers. 6
 
Hi,

ja, ist für MX2004 veröffentlicht (bitte gebt deshalb immer schon im Eingangsposting die von Euch verwendete Version an). Ich exportier's Dir gerne nochmal für Flash MX, komme aber erst morgen dazu.

Gruß
.
 
Zurück