Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Mar 29, 2014 Mar 29, 2014

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;
    }
}

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 29, 2014 Mar 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

    }

}

Translate
Adobe Employee ,
Mar 29, 2014 Mar 29, 2014

Moving this discussion to flash forum.

Regards,

Devendra

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 29, 2014 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 29, 2014 Mar 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 29, 2014 Mar 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

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 01, 2014 Apr 01, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2014 Apr 02, 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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 02, 2014 Apr 02, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 02, 2014 Apr 02, 2014

Thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2014 Apr 03, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2014 Apr 03, 2014

Figured it out, thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 03, 2014 Apr 03, 2014
LATEST

Avoid using scenes while you are young.  Your older self will appreciate it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines