Copy link to clipboard
Copied
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;
}
}
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
}
}
Copy link to clipboard
Copied
Moving this discussion to flash forum.
Regards,
Devendra
Copy link to clipboard
Copied
What would be involved with displaying a tick? Whatever that is, you would add it to the code in the conditional of each function.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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
}
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thank you.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Figured it out, thanks
Copy link to clipboard
Copied
Avoid using scenes while you are young. Your older self will appreciate it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now