Here’s the basic question: How do you access every displayed object of a certain kind at once? Here’s the code.
var newBox:MovieClip = new Dirt();
Can I easily access every instance of “Dirt()”? Here’s the whole function.
stage.addEventListener(MouseEvent.CLICK, placeBox);
function placeBox(e:Event):void{
if (player.hitTestPoint(mouseX, mouseY, true) == false){
var boxType:String = "earth";
var xGrid:uint;
var yGrid:uint;
//Allocates a grid position based on mouse position
for (var i:int = 1; i < 18; i++){
if (mouseX < (i * 50) && mouseX > ((i-1) * 50)){
xGrid = i;
}
if (mouseY < (i * 50) && mouseY > ((i-1) * 50)){
yGrid = i;
}
}
//Converts the yGrid position to coordinates
var yCo:Number = (yGrid * 50) - 25;
//Converts the xGrid position to coordinates
var xCo:Number = (xGrid * 50) - 25;
//Gets a copy of the dirt
var newBox:MovieClip = new Dirt();
//Adds the child to the stage
addChild(newBox);
//Confirms the details of the box's details
trace("An " + boxType + " block has been added to [" + xGrid + "," + yGrid + "]");
//Places the box in its grid position
newBox.x = xCo;
newBox.y = yCo;
}else{
trace("There is already a block there.");
}
}
If you went through all that, the observant of you may have noticed:
if ([U]player[/U].hitTestPoint(mouseX, mouseY, true) == false){
I want to replace the underlined part so that it refers to every instance of the dirt symbol without an insane number of iterations. From that, I plan to make the player capable of standing on each dirt symbol as they are being created, as well as move all of the dirt symbols with ease.
Thanks!