# Need help with arrays and hitTest

**URL:** <https://forum.kirupa.com/t/need-help-with-arrays-and-hittest/177587>\
**Category:** flash\
**Created:** [February 3, 2006, 3:52am UTC](https://forum.kirupa.com/t/need-help-with-arrays-and-hittest/177587 "2006-02-03T03:52:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gpdematteo](https://avatars.discourse-cdn.com/v4/letter/g/3bc359/32.png) [@gpdematteo](https://forum.kirupa.com/u/gpdematteo)\
**Post date:** [February 3, 2006, 3:52am UTC](https://forum.kirupa.com/t/need-help-with-arrays-and-hittest/177587/1 "2006-02-03T03:52:17Z")

</div>

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!
