Skip to main content
October 23, 2008
Question

complicated drap and drop

  • October 23, 2008
  • 2 replies
  • 291 views
Hello, I am trying to do something with my drag and drop game that is too complicated for me to find on any tutorial.

I am trying to set it up so that when the item is being dragged and it is over the correct drop area, the item blinks (which I have animated on the 2nd frame and beyond in each item). The problem is, I can't seem to run a hitTest while the item is being dragged, or onPress of the item. I have even tried to set an interval so that my indicator function runs every 50 milliseconds. I have included the sample script below, if anyone could help me it would be greatly appreciated.

//------//var intervalId:Number
function indicator(item,labels){
if(eval(item).target_mc.hitTest(eval(labels).target_mc)){
eval(item).gotoAndStop(2);
}}
//-------//intervalId = setInterval(indicator, 50);

function labelsTest(item,labels){
eval(item).stopDrag();
if(eval(item).target_mc.hitTest(eval(labels).target_mc)){
eval(labels).gotoAndStop(2);
eval(item).enabled=false;
eval(item)._visible=false;
counter++;
if (counter==7){gotoAndStop("continue");
}
}}
item1_mc.onPress = function () {
item1_mc.startDrag();
item1_mc.swapDepths(this.getNextHighestDepth());
indicator("item1_mc","label1_mc");
}

item1_mc.onRelease = function () {
labelsTest("item1_mc","label1_mc");
}
This topic has been closed for replies.

2 replies

October 23, 2008
Allright, the reason why I am setting them as strings is because I have a lot more movie clip(draggable items) than I included the code for. I have tried a couple of your suggestions and it doesn't seem like the hitTest is operating at all while the mouse is pressed. here are a couple things that I have tried

function indicator(item,labels){
if(eval(item).target_mc.hitTest(eval(labels).target_mc)){
eval(item).gotoAndPlay(2);
}}

function labelsTest(item,labels){
eval(item).stopDrag();
if(eval(item).target_mc.hitTest(eval(labels).target_mc)){
eval(labels).gotoAndStop(2);
eval(item)._x=eval(labels)._x;
eval(item)._y=eval(labels)._y;
eval(item).enabled=false;
eval(item)._visible=false;
clearinterval(intervalId);
counter++;
if (counter==7){gotoAndStop("continue");
}
}}
item1_mc.onPress = function () {
item1_mc.startDrag();
item1_mc.swapDepths(this.getNextHighestDepth());
var intervalId:Number
indicator("item1_mc","label1_mc");
intervalId = setInterval(indicator, 50);
}

I have also tried to set my interval like this

intervalId = setInterval(indicator("item1_mc","label1_mc"), 50);

Thanks a bunch for your feedback on this,

kglad
Community Expert
Community Expert
October 23, 2008
:

kglad
Community Expert
Community Expert
October 23, 2008
indicator() needs to repeatedly execute after your onPress handler executes. eg, start an onEnterFrame or setInterval() loop from your onPress handler and clear that loop in your onRelease.

p.s. there's no need to convert those movieclip names to strings and then re-convert them to movieclips. just pass the movieclips to indicator().