Groups | Blog | Home
all groups > flash actionscript > march 2007 >

flash actionscript : Draggable Movie Clips


Social Psyence
3/18/2007 9:59:13 PM
hey there, is it possible to make a draggable text box that can later have
input text entered into it. You can't enter type in the box when the movie clip
it resides in becomes draggable.

I've pinned the ._x and ._y values of the text box to a draggable move clip so
it sort of "follows" it when it's released, but it doesn't look very nice at
all.

Surely there is some other way? Any ideas are most welcome..
kglad
3/18/2007 11:38:42 PM
you can enter text into a draggable textfield. you just can't use mouse
handlers on the parent movieclip.

for example, using a hitTest() between the mouse and movieclip (onMouseDown
would be good) to initiate a startDrag() should be fine. use an onMouseUp to
stopDrag().
Social Psyence
3/19/2007 2:31:26 PM
Maybe I don't quite understand. So which movie clip is being made dragable when
you say not the parent, an isntance of the movie clip? Here's the code I
currently have.

I'm pretty much a noob at ActionScripting, learning stuff as I encounter each
problem. So you are recommending that instead of using the onPress I use
hitTest()? I'm not familiar with function but I'll look it up. Any more info
you can give will be most appreciated.

mcDrag.onPress = function():Void {
this.startDrag();
bubble1A._x = mcDrag._x + 30;
bubble1A._y = mcDrag._y;
};

mcDrag.onRelease = function():Void {
this.stopDrag();

};
kglad
3/19/2007 10:24:14 PM
correct. you cannot use onPress and onRelease handlers or your textfield in
mcDrag cannot respond to the mouse. (you could, however, use the Selection
class and its setFocus() method to allow text input upon your movieclip's
release. that may, or may not be satisfactory.)
Social Psyence
3/22/2007 12:00:00 AM
Sorry for the delayed repsponse, very busy these days. So with the setFocus()
method, this can be invoked during the the movie clip's onRelease event,
meaning that I can drag the movieclip, and when the user lets go, it allows for
text entry?

But I'm guessing that means when the .swf first loads they couldn't enter
text. They would have to click and move the clip first?
kglad
3/22/2007 2:58:14 PM
you're not limited to one block of code. you can still code for your textfield
to have focus when the frame containing your textfield plays:



mcDrag.onPress = function() {
this.startDrag();
};
mcDrag.onRelease = function() {
this.stopDrag();
Selection.setFocus(this.tf); // <- if your textfield has instance name tf in
mcDrag
};
Selection.setFocus(mc.tf); // <-- tf
AddThis Social Bookmark Button