A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Drag and drop problem

  1. #1
    Senior Member
    Join Date
    May 2009
    Posts
    280

    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?

  2. #2
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    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.

  3. #3
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    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_DOWNstartDragging1);
    my1_mc.my2_mc.addEventListener(MouseEvent.MOUSE_DOWNstartDragging2);
    stage.addEventListener(MouseEvent.MOUSE_UPstopDragging);

    function 
    startDragging1(e:MouseEvent):void{
        
    my1_mc.startDrag(falsenull);
    }

    function 
    startDragging2(e:MouseEvent):void{
        
    my1_mc.removeEventListener(MouseEvent.MOUSE_DOWNstartDragging1);
        
    my1_mc.my2_mc.startDrag(truenull);
        
    trace("2 clicked");
    }


    function 
    stopDragging(e:MouseEvent){
        
    my1_mc.addEventListener(MouseEvent.MOUSE_DOWNstartDragging1);
        
    my1_mc.stopDrag();
        
    my1_mc.my2_mc.stopDrag();

    hope that makes sense
    Mark
    Attached Files Attached Files

  4. #4
    Junior Member
    Join Date
    Jun 2008
    Posts
    25
    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)
    }

  5. #5
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    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

  6. #6
    Junior Member
    Join Date
    Jun 2008
    Posts
    25
    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/
    Last edited by er_gagan_deep; 11-25-2009 at 03:21 AM.

  7. #7
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    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

  8. #8
    Junior Member
    Join Date
    Jun 2008
    Posts
    25
    Hi I am gagan from India (Punjab). You can have my Id its
    [email protected]
    [email protected]
    [email protected]

    feel free to contact me ..........

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center