-
Drag and drop problem
hey, im having this problem with my movieclips. one is container_mc and inside it is picture_mc. They both have drag and drop functions. Container drags when it is clicked...but when i try to drag and drop picture_mc, i end up dragging the whole container itself. picture_mc is inside container_mc. Is there any way i can get by this?
-
Because container has a drag on it it will be selected every time, even if you appear to be clicking on the picture.
It is effectively on top of the picture so it registers the mouse click.
Could you check if the mouse is inside the boundary of the picture and if it is temporarily remove the mouse down listener from the container.
Add it back once the mouse is outside the picture.
-
1 Attachment(s)
I decided to give it a try.
there is an easier solution.
use the mouse down event of picture to remove the mouse down listener of container.
it works, I am attaching a simple fla
in the code below my1_mc = container and my2_mc = picture
PHP Code:
my1_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging1);
my1_mc.my2_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging2);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
function startDragging1(e:MouseEvent):void{
my1_mc.startDrag(false, null);
}
function startDragging2(e:MouseEvent):void{
my1_mc.removeEventListener(MouseEvent.MOUSE_DOWN, startDragging1);
my1_mc.my2_mc.startDrag(true, null);
trace("2 clicked");
}
function stopDragging(e:MouseEvent){
my1_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging1);
my1_mc.stopDrag();
my1_mc.my2_mc.stopDrag();
}
hope that makes sense
Mark
-
say you use a main_mc and inside that main_mc is the mc movieclip which holds the picture.
So use this code below hope it will work
//////////////////////////////////////////////////////////////////////////////////////////////////
main_mc.addEventListener(MouseEvent.MOUSE_DOWN,cli ck1)
main_mc.mc.addEventListener(MouseEvent.MOUSE_DOWN, click2)
stage.addEventListener(MouseEvent.MOUSE_UP,stopdra g)
function stopdrag(evt:MouseEvent)
{
main_mc.stopDrag()
main_mc.mc.stopDrag()
}
function click1(evt:MouseEvent)
{
evt.currentTarget.startDrag(false)
}
function click2(evt:MouseEvent)
{
evt.stopImmediatePropagation()
evt.currentTarget.startDrag(false)
}
-
Very nice er_gagan_deep.
achieved basically the same thing I was doing with WAY less code.
I am more of a designer than a coder, can you explain the stopImmediatePropogate a bit, in the Flash help it says
"Prevents processing of any event listeners in the current node and any subsequent nodes in the event flow. This method takes effect immediately, and it affects event listeners in the current node. In contrast, the stopPropagation() method doesn't take effect until all the event listeners in the current node finish processing."
I guess I am a bit unclear on what they mean by node, and current node etc.
also if you have time, I have a post up that also involves a dragging problem.
http://board.flashkit.com/board/show...81#post4218881
thanks
Mark
-
Respected Sir for this first you have to study about the event flow in Flash.
basicaly event flow takes place in three phases :
Capture phase
Target Phase
Bubbling Phase
jus check the link below, it will be helpful.
http://livedocs.adobe.com/flash/9.0/...=00000137.html
http://labs.almerblank.com/2009/11/a...st-event-flow/
-
Thanks very much
I will read those articles.
you are extremely helpful, a great addition to this community.
I am curious, I notice your posts are in the middle of the night where I live.
Where are you?
I am an Australian living in Minneapolis USA.
Thanks again
Mark
-
Hi I am gagan from India (Punjab). You can have my Id its
[email protected]
[email protected]
[email protected]
feel free to contact me ..........