# How to split an image on nine equal rectangels?

**URL:** <https://forum.kirupa.com/t/how-to-split-an-image-on-nine-equal-rectangels/271147>\
**Category:** flash\
**Created:** [September 19, 2008, 2:39am UTC](https://forum.kirupa.com/t/how-to-split-an-image-on-nine-equal-rectangels/271147 "2008-09-19T02:39:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Birokrat](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@Birokrat](https://forum.kirupa.com/u/Birokrat)\
**Post date:** [September 19, 2008, 2:39am UTC](https://forum.kirupa.com/t/how-to-split-an-image-on-nine-equal-rectangels/271147/1 "2008-09-19T02:39:24Z")

</div>

Hello!

I m trying to split an image on nine equal restangels but i m having some problems due my lack of serious theorethical ground in actionscript

here 's the code:

```php

function createRectangels():Void
{

var widthOfRectangle:Number=218;
var heightOfRectangle:Number=165;

var i:Number;
var j:Number;

//I m attaching the image from the library

_root.attachMovie("nature","nature2",this.getNextHighestDepth());
var myBitmapData:BitmapData = new BitmapData(640,480)
myBitmapData.draw(nature2)

nature2._visible=false;

//Dinamicly creating the image rectangels
for(i=0;i<3;i++)
{

for(j=0;j<3;j++)
{

var Pic:BitmapData = new BitmapData(218,165,true,0xFFCCCCFF);
Pic.draw(myBitmapData, new Matrix(), null, null, new Rectangle(218*j,165*i, 218, 165));
this.createEmptyMovieClip("clip"+i+j, this.getNextHighestDepth());
this["clip"+i+j].attachBitmap(Pic,this["klipot"+i+j].getNextHighestDepth());
this["clip"+i+j]._x=j*widthOfRectangle;
this["clip"+i+j]._y=i*heightOfRectangle;

}
}
}

createRectangels();

```

I m getting visible only the upper left corner of the image.

I hope someone will reply.
