A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Tracing Drag and Drop issue

  1. #1
    Senior Member
    Join Date
    May 2005
    Location
    Wisconsin
    Posts
    181

    Tracing Drag and Drop issue

    I cant figure out my drag and drop issue here.
    How do you trace your Mc your draggiing your mc to.

    I tried these with no sucess.
    trace("in the drop for boxers "+dropTarget );
    trace("in the drop for boxers "+dropTarget.name );

    This one give me instance360. What is that?
    trace("in the drop for boxers "+MyToolBox_mc.Close_mc.dropTarget.name );


    code:

    MyToolBox_mc.Close_mc.addEventListener(MouseEvent. MOUSE_DOWN, BoxersCloseUpPICK);
    MyToolBox_mc.Close_mc.addEventListener(MouseEvent. MOUSE_UP, BoxersCloseUpDROP);

    function BoxersCloseUpPICK(event:MouseEvent):void
    {
    startX = event.target.x;
    startY = event.target.y;
    event.target.startDrag(true);
    }

    function BoxersCloseUpDROP(event:MouseEvent):void
    {
    trace("in the drop for boxers "+dropTarget );
    event.target.stopDrag();
    BoxersClose_mc.visible = true;

    if (event.target.hitTestObject(Mid1_mc.Mid1boxers_mc) )
    {
    trace("Hit the close up Now What????");
    event.target.x = startX;
    event.target.y = startY;
    BoxersClose_mc.visible = true;

    event.target.removeEventListener(MouseEvent.MOUSE_ DOWN, pickUp2);
    event.target.removeEventListener(MouseEvent.MOUSE_ UP, dropIt2);
    }
    else
    {
    event.target.x = startX;
    event.target.y = startY;
    }
    }


    Josh
    Multimedia Programmer
    flashmajic.com

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    dropTarget is a property of Sprite, it is set to
    the display object over which the sprite is being dragged, or on which the sprite was dropped
    Since your main timeline is a MovieClip, it is also a Sprite, and has a dropTarget property. But that's not the dropTarget you want, since you were not dragging the root. You need the dropTarget property of the instance you were dragging.

    So you need
    Code:
    Sprite(event.target).dropTarget
    (Actually, I'd suggest saving the cast event.target as a Sprite into a variable at the start of the event handler.) When you trace the name property of that dropTarget, it traces "instance360" because you never gave that instance a name. That's okay, names are just Strings and should never* be used for program logic. If you want to see some pretty output there, you'll have to give your targets names. But the existence or non-existence of a name property will have no effect on the fact that it's the same object either way.

  3. #3
    Senior Member
    Join Date
    May 2005
    Location
    Wisconsin
    Posts
    181
    Thanks for the help. Im still getting instance 370.

    I have a movie clip named Mid1_mc and a MC inside named boxersmidHit_mc
    This code isnt working.
    Actionscript Code:
    if (event.currentTarget.hitTestObject(Mid1_mc.boxersmidHit_mc))

    I can Hit Mid1_mc and it executes my if statement but not
    Mid1_mc.boxersmidHit_mc

    Actionscript Code:
    function BoxersCloseUpDROP(event:MouseEvent):void
    {
        trace("in the drop for boxers "+MyToolBox_mc.Close_mc.dropTarget.name );
        trace("in the drop for boxers "+Sprite(MyToolBox_mc.Close_mc).dropTarget.name);
        event.target.stopDrag();

        if (event.currentTarget.hitTestObject(Mid1_mc.boxersmidHit_mc))
        //if (event.target.hitTestObject(Mid1_mc.boxersmidHit_mc))
        {
            trace("In boxers hti");
            event.target.x = startX;
            event.target.y = startY;
            BoxersClose_mc.visible = true;

            event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
            event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt2);
        }
        else
        {
            event.target.x = startX;
            event.target.y = startY;
        }
    }
    Josh
    Multimedia Programmer
    flashmajic.com

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If you have instances inside the MovieClip that you think is the drop target (such as graphic Shapes), those may be the actual dropTarget. That would explain the trace. But that should not prevent the hitTest from working. In what way is it not working?

  5. #5
    Senior Member
    Join Date
    May 2005
    Location
    Wisconsin
    Posts
    181
    Well my hit is a shape that i created a MC out of and gave it the name boxersmidHit_mc
    Mid1_mc is a picture that i converted to a MC.
    I can hit Mid1_mc just fine but when i try to hit the inner MC boxersmidHit_mc
    it does not work.
    Josh
    Multimedia Programmer
    flashmajic.com

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I still don't know why you can't detect the hit, but the point about the dropTarget being a Shape still applies.

    Trace whether the target is a Sprite, or whether it is a Shape, and you'll probably see that it is a Shape. You may be able to prevent this by setting mouseChildren = false on the dropTarget MovieClip. I would expect the hit test to still work regardless, though.

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