Groups | Blog | Home
all groups > flash actionscript > february 2005 >

flash actionscript : Drag and Drop with end result feedback



Eric K.
2/14/2005 8:43:59 PM
I have built a drag and drop exercise that has four items being draged to 4
hit areas. When all four are done correctly i want to immediatly display
feedback to the user without them having to do anything further. What is the
best approach for doing this.
In the past i have done this using a frame loop to check for updated
variables- im sure there is a better way.
Using MX 2004 .
Thanks
Jon Moyles
2/15/2005 9:06:51 AM
myDragThing.onRelease = function(){
if(myVariables){
doFeedbackThing();
}
}

Eric Kuhn
2/15/2005 11:01:08 AM
Thanks - that kicked me in the right direction. Working like a charm now.

Eric


[quoted text, click to view]

mandingo
2/16/2005 2:48:50 AM
I made a similar thing once...

stop();

// setup an array to hold your objects
testObjectArray = ["cola", "food", "spanner", "rings", "bottle"];
fCheckBinState = function () {
// decalare a variable for the rubbishInBin
rubbishInBin = 0;
for (rubbish in testObjectArray) {
trace("testing ... " + testObjectArray[rubbish] + " ... awaiting
verification");
if (this[testObjectArray[rubbish]]._visible == false) {
trace(testObjectArray[rubbish] + " is in the bin");
rubbishInBin++;
}
}
trace("the number of items now in the bin are: " + rubbishInBin);
if (rubbishInBin == testObjectArray.length) {
// everything is right to go
gotoAndPlay("cleanedup");
} else {
trace("we aren't all in the bin yet");
}
};
// Use a single For...In loop to establish all the .startDrag() behaviours
for (itemsToDrag in testObjectArray) {
this[testObjectArray[itemsToDrag]].onPress = function() {
this.startDrag();
};
}
// this part can be done a number of ways but doing it individually for the
moment might be easier to understand
cola.onRelease = function() {
// once inside this behaviour, we can refer to the movieClip as 'this'
if (this.hitTest(metal) == true) {
// unless you are using an old version, instead of setProperty, you can
reference this way
this._x = 450.3;
this._y = 340.3;
this._visible = false;
// call the function fCheckBinState to see if all items are in the bin IF
this item hitTest = true
fCheckBinState();
} else {
this._x = 40.5;
this._y = 67.5;
}
stopDrag();
};
food.onRelease = function() {
if (this.hitTest(junk) == true) {
this._x = 450.3;
this._y = 340.3;
this._visible = false;
fCheckBinState();
} else {
this._x = 40.5;
this._y = 67.5;
}
stopDrag();
};
spanner.onRelease = function() {
if (this.hitTest(metal) == true) {
this._x = 450.3;
this._y = 340.3;
this._visible = false;
fCheckBinState();
} else {
this._x = 40.5;
this._y = 67.5;
}
stopDrag();
};
rings.onRelease = function() {
if (this.hitTest(plastic) == true) {
this._x = 100.3;
this._y = 340.3;
this._visible = false;
fCheckBinState();
} else {
this._x = 40.5;
this._y = 67.5;
}
stopDrag();
};
bottle.onRelease = function() {
if (this.hitTest(glass) == true) {
this._x = 100.3;
this._y = 340.3;
this._visible = false;
fCheckBinState();
} else {
this._x = 40.5;
this._y = 67.5;
}
stopDrag();
};


the four movieClips to drop onto were given instanceNames of
"metal","junk","plastic" and "glass".

it may help,

cheers,
Jon Moyles
2/16/2005 10:30:06 AM
AddThis Social Bookmark Button