Specifying which array to filter through in function

Here’s a link to my project, to give an idea of what’s happening:

http://deliver.capstrat.com/development/capstrat/banner/index.html

I’ve had trouble in the past getting any direction or answers here - I want to specify that I’m not asking for explicit help; I know we’re all busy. I’m just wanting general, I’m-on-the-right-track-and-yes-this-is-possible direction…or conversely, dude-you’re-all-wrong-and-you-should-go-read-this-article-or-this-section-of-Flash-Help.
Thanks in advance…

I have a single function, which is to randomly place mc’s on stage. These mc’s are found in one of 3 arrays. To avoid overlap when placing the mc on the stage, I have a test set up within this function - the x-position randomly generated is to be checked against the x-positions of all other mc’s in that particular array; if overlap is found, then the generated x-position is thrown out and another generated, until an acceptable one is found.

Because I have 3 separate arrays of mc’s to pull from to populate the stage, I originally had 3 separate functions to call. But that seemed redundant, as each of the three needs to do the exact same thing. So now I’ve consolidated into one function, and am missing something very important, conceptually. My question is this: is it possible to have a variable as a parameter in my function call, which I can point to whichever of the 3 established arrays I want the function to look at? Here’s the line I’m referring to:

function getXposition(placement, objectType) {

where I’m thinking that objectType can be the reference to the array I want the function to focus on for that particular call. I’m using a for loop to cycle through each item in the array that I’m looking at:

for (var item in objectType) {

where previously I would have said

for (var item in directorsArray) {

for example. Here’s the function as is, followed by the onclip event script:

XXXXXXXXXXXXXXXXXXXXX
ARRAYS
XXXXXXXXXXXXXXXXXXXXX
_root.objectsArray = new Array();
_root.objectsArray = [“squirrel_mc”, “lava_mc”, “flag_mc”, “rocket_mc”, “cone_mc”, “boomerang_mc”];
_root.directorsArray = new Array();
_root.directorsArray = [“stephen_mc”, “lisa_mc”, “dchatham_mc”, “billy_mc”, “pmahoney_mc”, “sballew_mc”, “frank_mc”, “jodi_mc”];
_root.leadershipArray = new Array();
_root.leadershipArray = [“james_mc”, “debbie_mc”, “johnp_mc”, “todd_mc”, “karen1_mc”, “ken_mc”];

XXXXXXXXXXXXXXXXXXXX
FUNCTION
XXXXXXXXXXXXXXXXXXXX

function getXposition(placement, objectType) {
keepTesting = true;
var monkeyspunk:Array = new Array(); //make array
for (var item in objectType) { //loop thru hard coded array
if (objectType == “objectsArray”) {
if (object._x>(0-_root.foregroundWidth) && object._x<_root.foregroundWidth) { //if object is on stage
monkeyspunk.push = newXPos; //add it’s x pos to array
}
} else if (objectType == “directorsArray”) {
if (director._x>(0-_root.foregroundWidth) && director._x<_root.foregroundWidth) { //if object is on stage
monkeyspunk.push = newXPos; //add it’s x pos to array
}
} else if (objectType == _root.leadershipArray) {
if (leader._x>(0-_root.foregroundWidth) && leader._x<_root.foregroundWidth) { //if object is on stage
monkeyspunk.push = newXPos; //add it’s x pos to array
}
}
while (keepTesting == true) {
//test
if (placement == “init”) {
newXPos = (Math.random()(2_root.foregroundWidth))-_root.foregroundWidth;
//random formula;
} else if (placement == “left”) {
newXPos = 0-Math.random()_root.foregroundWidth;
//random formula;
} else if (placement == “right”) {
newXPos = _root.stageWidth+Math.random()
(_root.foregroundWidth-_root.stageWidth);
//random formula;
}
//random formula;
newXPosValid = true;
for (var item in monkeyspunk) {
//test
spaceLeft = item-100;
spaceRight = item+100;
if (newXPos>spaceLeft && newXPos<spaceRight) {
newXPosValid = false;
}
}
//can we escape the while loop?
if (newXPosValid == true) {
keepTesting = false;
}
}
}
return newXPos;
}
stop();

XXXXXXXXXXXXXXXXX
THE ON CLIP EVENT ACTIONS
XXXXXXXXXXXXXXXXX

onClipEvent (load) {
// add all the objects at random, from -X to X
for (i=0; i<_root.objectsArray.length; i++) {
object = this.attachMovie(root.objectsArray*, "object"+i, 100+i);
object._y = Math.random()((_root.stageHeight-object._height)+30);
object._x = getXposition(“init”, “objectsArray”);
// set a depth for parallax effect
object._xscale = object._yscale=_root.objectMinScale+(Math.random()
(_root.objectMaxScale-_root.objectMinScale));
}
// add all the directors at random, from -X to X
for (i=0; i<_root.directorsArray.length; i++) {
director = this.attachMovie(root.directorsArray*, "director"+i, 300+i);
director._xscale = director._yscale=root.directorMinScale+(Math.random()(_root.directorMaxScale-_root.directorMinScale));
director._y = (_root.stageHeight-director._height);
director._x = getXposition.apply(“init”, directorsArray);
}
for (i=0; i<_root.leadershipArray.length; i++) {
leader = this.attachMovie(_root.leadershipArray
, "leader
"+i, 350+i);
leader._y = (_root.stageHeight-leader._height);
leader._x = getXposition();
}
}
onClipEvent (enterFrame) {
// move each object at a rate relative to their parallax
for (i=0; i<root.objectsArray.length; i++) {
object = eval("this.object
"+i);
object._x += 0.75*(_root.xVelocity+_root.xVelocity*((object._xscale-_root.objectMinScale)/_root.objectMaxScale));
if (object._x>_root.foregroundWidth) {
object._x = 0-Math.random()_root.foregroundWidth;
object._y = Math.random()
((_root.stageHeight-object._height)+30);
} else if (object._x<0-_root.foregroundWidth) {
object._x = _root.stageWidth+Math.random()(_root.foregroundWidth-_root.stageWidth);
object._y = Math.random()
((_root.stageHeight-object._height)+30);
}
}
// move each object at a rate relative to their parallax
for (i=0; i<root.directorsArray.length; i++) {
director = eval("this.director
"+i);
director._x += _root.xVelocity+_root.xVelocity*((director._xscale-_root.directorMinScale)/_root.directorMaxScale);
if (director._x>_root.foregroundWidth) {
director._x = getXposition(“left”);
//director._x = 0 - Math.random() * _root.foregroundWidth;
} else if (director._x<0-_root.foregroundWidth) {
director._x = getXposition(“right”);
//director._x = _root.stageWidth+Math.random()(_root.foregroundWidth-_root.stageWidth);
}
}
// if the object is beyond x or -x, send it off stage, somewhere random
for (i=0; i<root.leadershipArray.length; i++) {
leader = eval("this.leader
"+i);
leader._x += 1.5
_root.xVelocity;
if (leader._x>_root.foregroundWidth) {
leader._x = 0-Math.random()_root.foregroundWidth;
} else if (leader._x<0-_root.foregroundWidth) {
leader._x = _root.stageWidth+Math.random()
(_root.foregroundWidth-_root.stageWidth);
}
}
}

NOTE - monkeyspunk is the name of a temporary array I’m creating to populate with valid x-positions; it’s scope is limited to the function itself. It gets tossed out at the end of the function