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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drag-n-drop using textBoxes doesn't work

Status
Not open for further replies.

cruise95

Programmer
Oct 7, 2003
56
US
Hi all,

I have a problem concerning the drag n drop ability using movie clips containing textBoxes.

My drag-n-drop works well and the text appears correctly. The problem arises when you click on the TEXT and then drag the movie clip OR when you drop a movie clip onto another movie clip's text.

For example: When you click outside of the text box and drag the movie clip, then place it on another movie clip (not another movie clip's text)...everything works well.

I think that I should somehow 'group' the text Box and movie clip so that they become one. Can anyone help me with this? Will that solve the problem? What should I do?

I really appreciate any help...I know that this isn't the easiest question. Also, for those that wouldn't mind, the actionscript is below. Just copy that in the main movie.

Thanks again...



//Global variables
var numrecords = 3;
var dragX;
var dragY;


//create some formatting for our text boxes
myTextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextFormat.size = 12;
myTextFormat.color=0x000000;//black


for (i=1; i<=numrecords; i++) {
// create the movies
thisMov = _root.createEmptyMovieClip("button"+i, 100+i); //name, depth
thisMov.lineStyle(2, 0x000000, 100); //width, black, alpha
thisMov.beginFill(0xF7837D, 100); //red, alpha
thisMov.lineTo(100, 0);
thisMov.lineTo(100, 23);
thisMov.lineTo(0, 23);
thisMov.endFill(100, 0);
thisMov._x=150;
thisMov._y=i*30;

//create text box
thisMov.createTextField("textBox" add i,i,0,0,80,18); //instance name, depth, x, y, width, height
var thisMovTitle = eval(thisMov+".textBox"+i);
trace(thisMovTitle);
thisMovTitle.multiline = false;
thisMovTitle.wordWrap = true;
thisMovTitle.border = false;
thisMovTitle.text = "my title" + i;
trace("thisMovTitle.text: " + thisMovTitle.text);
thisMovTitle._visible = true;
thisMovTitle.setTextFormat(myTextFormat);


//on press
_root["button"+i].onPress=function() {
this.startDrag();
this.swapDepths(1000);

var mDropTarget;
var mDragTarget;
for (j=1; j<=numrecords; j++) {
DT = eval("m"+j+"DropTarget");
_root.DT;
}
var dropX;
var dropY;

// variable declarations
for (j=1; j<=numrecords; j++) {
DT = eval("m"+j+"DropTarget");
_root.DT = eval("/button" add j);
}
dragX = getProperty(this, _x);
dragY = getProperty(this, _y);
}

//on release
_root["button"+i].onRelease=function(){
// loadVariables("text1.txt", "_root");
this.stopDrag();

for (j=1; j<=numrecords; j++) {
if(eval(this._droptarget) == eval("/button" add j)) {
mDropTarget = eval("/button" add j);
break;
}
}

// if dropped correctly
// if (this._droptarget == mDropTarget) {
if (eval(this._droptarget) == mDropTarget) {
trace(" --- dropped correctly ---");
// get X & Y values for drop img
dropX = getProperty(mDropTarget, _x);
dropY = getProperty(mDropTarget, _y);

// set drag img's X & Y to same as drop img's
setProperty(this, _x, dropX);
setProperty(this, _y, dropY);
// set drop img's X & Y to same as drag img's
setProperty(mDropTarget, _x, dragX);
setProperty(mDropTarget, _y, dragY);

// else dropped incorrectly
} else {
trace(" --- dropped incorrectly ---");
setProperty(this, _x, dragX);
setProperty(this, _y, dragY);
}
} //end onRelease
} //end for loop

stop();
 
My drag-n-drop works well and the text appears correctly. The problem arises when you click on the TEXT and then drag the movie clip OR when you drop a movie clip onto another movie clip's text.

But what is the problem that arises?
 
That's the same problem that I am having.

If I create a static drag-n-drop, then they work correctly. However, when I dynamically create the drag-n-drop movieclips using actionscript then i have the same problem that you have - dragging/dropping onto a text field doesn't work.

Do you know how to fix that?
 
What I want to do is be able to click and drag/drop anywhere. Right now I cannot do this where the text is at.

thanx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top