# Snapping to Grid

**URL:** <https://forum.kirupa.com/t/snapping-to-grid/220022>\
**Category:** flash\
**Created:** [March 21, 2007, 11:47pm UTC](https://forum.kirupa.com/t/snapping-to-grid/220022 "2007-03-21T23:47:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PrinceTaj](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@PrinceTaj](https://forum.kirupa.com/u/PrinceTaj)\
**Post date:** [March 21, 2007, 11:47pm UTC](https://forum.kirupa.com/t/snapping-to-grid/220022/1 "2007-03-21T23:47:07Z")

</div>

Hi Guys,

I have created a grid using a script that tiles “10"x"10” square across the stage:

```auto

function tileGrid(){
    
    grid_width = 10;
    grid_height = 10;
    //
    x_max = Math.round(Stage.width/grid_width);
    y_max = Math.round(Stage.height/grid_height);
    
    for (x=0; x<x_max; x++)
    {
        for (y=0; y<y_max; y++)
        {
            bg = _root.attachMovie("grid", "gd"+x+y, 
                this.getNextHighestDepth());
            bg._x = grid_width*x;
            bg._y = grid_height*y;
        }// End of inner loop
    }// End of outer loop
};

```

How can I go about making a movieClip object or graphic ‘snap’ to that grid? Is there a function out there, or a script? Please please please can anybody help me.

Many Thanks

PrinceTaj 🙂
