Hi,
I’m working on a simple math project for my students. It involves moving cubes to two different targets. I want the script to detect when a student places a cube on top of another and then respond to that. I figured out how to detect which target the cubes are on but I can’t figure out how to detect if a cube is on top of another cube. This is what I have so far:
var nMultiplier:Number = getRandomNumber(6, 3);
var nDepth:Number = 0;
var nLevel:Number = 100;
var nOFFSET:Number = 10;
var aList:Array = [“mcCubeButton1”, “mcCubeButton2”, “mcCubeButton3”, “mcCubeButton4”, “mcCubeButton5”, “mcCubeButton6”, “mcCubeButton7”, “mcCubeButton8”, “mcCubeButton9”];
function getRandomNumber(n1:Number, n2:Number):Number {
if (n2) {
return Math.floor(Math.random() * n1 + n2);
} else {
return Math.floor((Math.random() * n1));
}
}
function makeSquare():Void {
if (nDepth <= nMultiplier) {
var mcDuplicatedSquare:MovieClip = mcCubeButton.duplicateMovieClip(“mcCubeButton” + nDepth, nDepth++);
mcDuplicatedSquare._x += nOFFSET;
mcDuplicatedSquare._y -= nOFFSET;
mcDuplicatedSquare.focusEnabled = true;
mcDuplicatedSquare._focusrect = false;
Selection.setFocus(mcDuplicatedSquare);
var nLeft:Number = mcDragBoundary._x;
var nTop:Number = mcDragBoundary._y;
var nRight:Number = nLeft + mcDragBoundary._width;
var nBottom:Number = nTop + mcDragBoundary._height - 5;
mcDuplicatedSquare.onPress = function():Void {
mcDuplicatedSquare.startDrag(false, nLeft, nTop, nRight, nBottom);
mcDuplicatedSquare.swapDepths(nLevel);
nLevel++;
}
mcDuplicatedSquare.onRelease = function():Void {
stopDrag();
if(mcDuplicatedSquare.hitTest(mcDropTarget1)) {
mcDuplicatedSquare._y = mcDropTarget1._y + 12;
} else if (mcDuplicatedSquare.hitTest(mcDropTarget2)) {
mcDuplicatedSquare._y = mcDropTarget2._y + 12;
}
}
} else {
this.txtFeedback1.text = “You’ve reached the maximum number of cubes.”;
}
}
mcCubeButton.onPress = function() {
makeSquare();
}
I’m using FlashMX 2004. Any help would be greatly appreciated.
Thanks!