# Class Interaction

**URL:** <https://forum.kirupa.com/t/class-interaction/327472>\
**Category:** flash\
**Created:** [March 2, 2012, 11:27pm UTC](https://forum.kirupa.com/t/class-interaction/327472 "2012-03-02T23:27:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheOtherTedium](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@TheOtherTedium](https://forum.kirupa.com/u/TheOtherTedium)\
**Post date:** [March 2, 2012, 11:27pm UTC](https://forum.kirupa.com/t/class-interaction/327472/1 "2012-03-02T23:27:55Z")

</div>

Here’s the basic question: How do you access every displayed object of a certain kind at once? Here’s the code.

```auto

var newBox:MovieClip = new Dirt();

```

Can I easily access every instance of “Dirt()”? Here’s the whole function.

```auto

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:

```auto

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!
