Skip to main content
Known Participant
March 29, 2014
Answered

Drag and Drop with a response in Flash..please help

  • March 29, 2014
  • 5 replies
  • 1302 views

Hi

I have just started with flash and actionscript3 about 5 weeks ago. I'm in my first year uni and I have a drag and drop assignment (for a kindergarten class). Its "little Red Hen" and they have place the correct picture in right holder.

I have gotten the drag and drop working but I can't seem to figure out how to display a tick when they have place it in the correct holder.

Please help....

This is my script (it may seem messy...still new)

import flash.events.MouseEvent;

/*Mouse Event that ensures the function of hen movieclip to start dragging
  when mouse is pressed*/

hen1_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragStart);
hen2_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragStart);
hen3_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragStart);
hen4_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragStart);
hen5_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragStart);
hen6_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragStart);


function dragStart (event: MouseEvent):void
{
    event.target.startDrag();
}

/*Mouse Event that ensures the function of hen movieclip to drop
when the mouse button is realeased with Condition statement, if
hen = holder, hen snaps into place*/

hen1_mc.addEventListener(MouseEvent.MOUSE_UP, dragStop1);
function dragStop1 (event:MouseEvent):void
{
    hen1_mc.stopDrag();
    if (hen1_mc.hitTestObject (holder1_mc)==true)
       
    {
        hen1_mc.x=holder1_mc.x;
        hen1_mc.y=holder1_mc.y;
    }
}


hen2_mc.addEventListener(MouseEvent.MOUSE_UP, dragStop2);
function dragStop2 (event:MouseEvent):void
{
    hen2_mc.stopDrag();
    if(hen2_mc.hitTestObject (holder2_mc)==true)
    {
        hen2_mc.x=holder2_mc.x;
        hen2_mc.y=holder2_mc.y;
    }
}


hen3_mc.addEventListener(MouseEvent.MOUSE_UP, dragStop3);
function dragStop3 (event:MouseEvent):void
{
    hen3_mc.stopDrag();
    if(hen3_mc.hitTestObject (holder3_mc)==true)
    {
        hen3_mc.x=holder3_mc.x;
        hen3_mc.y=holder3_mc.y;
    }
}

hen4_mc.addEventListener(MouseEvent.MOUSE_UP, dragStop4);
function dragStop4 (event:MouseEvent):void
{
    hen4_mc.stopDrag();
    if(hen4_mc,hitTestObject (holder4_mc)==true)
    {
        hen4_mc.x=holder4_mc.x;
        hen4_mc.y=holder4_mc.y;
    }
}

hen5_mc.addEventListener(MouseEvent.MOUSE_UP, dragStop5);
function dragStop5 (event:MouseEvent):void
{
    hen5_mc.stopDrag();
    if(hen5_mc.hitTestObject (holder5_mc)==true)
    {
        hen5_mc.x=holder5_mc.x;
        hen5_mc.y=holder5_mc.y;
    }
}

hen6_mc.addEventListener(MouseEvent.MOUSE_UP, dragStop6);
function dragStop6 (event:MouseEvent):void
{
    hen6_mc.stopDrag();
    if(hen6_mc.hitTestObject (holder6_mc)==true)
    {
        hen6_mc.x=holder6_mc.x;
        hen6_mc.y=holder6_mc.y;
    }
}

This topic has been closed for replies.
Correct answer Ned Murphy

You alreadsy have the conditionals in place as far as I can tell, you just need to add the actionscript to display the tick...

function dragStop1 (event:MouseEvent):void

{

    hen1_mc.stopDrag();

    if (hen1_mc.hitTestObject (holder1_mc))

    {

        hen1_mc.x=holder1_mc.x;

        hen1_mc.y=holder1_mc.y;

       // display the tick code goes here

    }

}

5 replies

Known Participant
April 3, 2014

Ok last thing and then I'm done...

Once again thank you for your help.

I have created a "well done" animation clip in scene 2

How do I then get to play scene 2 once the drag and drop puzzle is complete

in scene 1?

Known Participant
April 3, 2014

Figured it out, thanks

Inspiring
April 2, 2014

and also if u're changing the alpha property dynamically, its between 0 and 1, not 100.

I know it has nothing to do with ur problem, just wanted to notice as u mentioned.

GL

Known Participant
April 2, 2014

Thank you.

Known Participant
April 2, 2014

Ok so I figured it out, thank you Ned.

I have made the tick_mc alpha 0 in the beginning of the script and then in my conditional I have made the alpha = 100

So it works...yay!

Now all I have left, if the piece is placed in the wrong holder then it needs to go back into its orignal position.

I have tried

Written above the script

var startX:Number;

var startY:Number;

then just below my dragStart code

startX = event.target.x = startX;

startY = event.target.y = startY;

then after each if statement I placed an else statement

else

{

      hen1_mc.x = startX;

      hen1_mc.y = startY;

}

Its clearly not working, please could you tell me what I am doing wrong?

thank you

Ned Murphy
Legend
April 2, 2014

Having just one set of startX/startY won't work if you have several objects.  You need to assign a startX and startY property to each draggable object and then use those values to reassign the object location back to where it started from. 

The following lines make no sense, essentially assigning a value to equal itself...

startX = event.target.x = startX;

startY = event.target.y = startY;

Ned Murphy
Legend
March 29, 2014

What would be involved with displaying a tick?  Whatever that is, you would add it to the code in the conditional of each function.

Known Participant
March 29, 2014

a "tick" meaning a correction mark underneath each holder. I'm not quite sure as to what conditional statement I can use. (thank you for your response)

Ned Murphy
Ned MurphyCorrect answer
Legend
March 29, 2014

You alreadsy have the conditionals in place as far as I can tell, you just need to add the actionscript to display the tick...

function dragStop1 (event:MouseEvent):void

{

    hen1_mc.stopDrag();

    if (hen1_mc.hitTestObject (holder1_mc))

    {

        hen1_mc.x=holder1_mc.x;

        hen1_mc.y=holder1_mc.y;

       // display the tick code goes here

    }

}

Devendra Kumar
Participating Frequently
March 29, 2014

Moving this discussion to flash forum.

Regards,

Devendra