Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

difficulty with drag and drop

Status
Not open for further replies.

rdoor

Technical User
May 4, 2002
43
0
0
US
I'm using Flash MX and working on a drag and drop problem. This is a geography problem to correctly identify the countries of the world and I want the users to drag a text movie clip (the name of the country) and drop it over the correct location on an outline map of the continent. It's not working well and I have used the trace function to try to figure it out:

on(press){
startDrag(this,true);
}
on(release, releaseOutside){
stopDrag();
trace("Drag Stopped");
trace("Dropped. droptarget =" +this._droptarget);
}

The image has each country in its own movie clip with a static text superimposed. So, whenever I drop over the country, the trace comes up empty. However, when I drop over the text box, I get the appropriate "droptarget = /instance46" or whatever the system has labeled the particular text box. Each country movie clip is in its own timeline. The movie clip contains a graphic of the shape of that country.

How come the text boxes are correctly identified and the movie clips containing the shapes of the countries are ignored? Any suggestions?

Roy
 
The set up:
You have the graphic of the countrys in movie clips and the text with the name of the country in other movie clips...
Give the movie clip with the frist country the instance name country_1 and to the text corresponding to the first country give the instance name text_1...
For the second country use : country_2 ; text_2
I hope you get the idea...
countrysNum is the number of the countrys...
If you have 10 countrys var countrysNum = 10;
Copy the following code into the first frame of the timeline where you have the countrys and their names...

Code:
var countrysNum = 3;
var position = 0;
var xPos:Array = Array();
var yPos:Array = Array();
for (i = 1; i <= countrysNum; i++) {
		if (position == 0) {
			xPos[i-1] = eval("text_" + i)._x;
			yPos[i-1] = eval("text_" + i)._y;
		}
		this["text_" + i].onPress = function() {
			n = this._name.substring(5);
			this.startDrag(false);
			position = 1;
		}
		this["text_" + i].onRelease = function() {
			this.stopDrag(); 
			for (var j = 1; j <= countrysNum; j++) {
   				if (eval(this._droptarget) ==  eval("country_"+j)) {
					m = eval("country_"+j)._name.substring(8);
				}
			}
				if (eval(this._droptarget) ==  eval("country_"+m)) {
					eval("text_"+n)._x = eval("country_"+m)._x;
					eval("text_"+n)._y = eval("country_"+m)._y;
					if (n == m) {
						trace("correct country");
					} else {
						trace("incorrect country");
					}
				}  else {
					eval("text_" + n)._x = xPos[n-1]; 
					eval("text_" + n)._y = yPos[n-1];
				}
			
		}
}
stop();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top