Hi,
I've been given the AS3 code in the attached zip file (CS4) and the movie clips are not dragging. I want them to drag, drop, and evaluate if they are in the correct drop target.
Hi,
I have this code now and the movie clips are draggable, but they do not release. Can someone please let me know what I'm doing wrong, it's probably something very easy!
import flash.display.MovieClip;
// you need to create the variables
var xstart:Number = 0;
var ystart:Number = 0;
var mcAnswer:MovieClip;
function onePress(evt:MouseEvent):void{
/*
evt.currentTarget refers to the object
on the EventListeners which has trigger
the event.
so for example if answer2_mc was pressed.
then the press is the event being triggered
and answer2_mc is what currentTarget
would be refering to.
*/
evt.currentTarget.startDrag(true);
setChildIndex(evt.currentTarget,numChildren-1);
textField.text="";
xstart = evt.currentTarget.x;
ystart = evt.currentTarget.y;
}
function oneRelease(evt:MouseEvent):void{
evt.currentTarget.stopDrag();
switch(evt.currentTarget){
case a1_mc:
mcAnswer=benefit2011001_mc;
break
case a2_mc:
mcAnswer=benefit2011001_mc;
break
case a3_mc:
mcAnswer=benefit2011001_mc;
break
case a4_mc:
mcAnswer=benefit2011001_mc;
break
case a5_mc:
mcAnswer=benefit2011002_mc;
break
case a6_mc:
mcAnswer=benefit2011002_mc;
break
case a7_mc:
mcAnswer=benefit2011002_mc;
break
case a8_mc:
mcAnswer=benefit2011002_mc;
break
case a9_mc:
mcAnswer=benefit2011003_mc;
break
case a10_mc:
mcAnswer=benefit2011003_mc;
break
case a11_mc:
mcAnswer=benefit2011003_mc;
break
case a12_mc:
mcAnswer=benefit2011003_mc;
break
case a13_mc:
mcAnswer=allPlans_mc;
break
case a14_mc:
mcAnswer=allPlans_mc;
break
case a15_mc:
mcAnswer=allPlans_mc;
break
case a16_mc:
mcAnswer=allPlans_mc;
break
}
if (evt.currentTarget.hitTestObject(mcAnswer)) {
textField.text="Correct!";
/*
numbers aren't strings so we convert it
to a string so we can use it for the textfield
*/
evt.currentTarget.enabled = false;
}
else {
textField.text="Incorrect.";
evt.currentTarget.x = xstart;
evt.currentTarget.y = ystart;
}
}
Try all instances of currentTarget - an event's target is going to be the thing you attached the listener to, while the currentTarget can be any children of that object that you might have clicked. In practice you'll usually want the target since it will predictably be the thing you were interfacing with when you added the listener.
You might also get the same result by setting mouseChildren to false for those draggable movieclips.
Please use [php] or [code] tags, and mark your threads resolved 8)
I suspect the registration points for your MovieClips are not in the center but rather in the corner of the MovieClips. I just did a test where I had a square MovieClip with the registration point being at (0, 0) and it won't release the drag, but once I move the point onto the actual graphics it works.
Originally Posted by neznein9
Try all instances of currentTarget - an event's target is going to be the thing you attached the listener to, while the currentTarget can be any children of that object that you might have clicked.
I thought it was the other way around? When I have a MovieClip with a TextField and a colored background both the same size so the TextField technically covers the whole MovieClip, e.target returns the TextField and e.currentTarget returns the MovieClip.