I cropped a jpg but need help to fix the scale

cropping a jpg image
I have created the following code below.

I want to load an external image. And break it into a specified number of rows and columns. I have successfully cropped it and assigned it to a movie clip that has actions attached, but I want to be able to split it into various numbers of columns and rows based on variables.

To do this I had to scale the “peice” to the correct size.

It currently works at generating the necessary size of each piece and placing the image where I want it when no scaling is needed. (300x300 image with a 100 x 100 cell) Yet when I scale the image, the jpg also gets scaled and distorted.

Trace statements show all positioning calculations to be correct. i have the offsets in x,y coordinates of the portion of the larger image i want and it does that correctly as well.

But how do I correct the scaling problem for the image that is inside the MC “piece”? While i want to MC container to scale, I want to leave the clipped image inside at 100% and not be scaled.

I was thinking I could somehow enlarge the inside image so that it offsets the reduction of the container, but not sure how to do that…

Any help would be greatly appreciated… I want to do this to create a variety of different puzzles…including a sliding puzzle.

an online version of the swf is here… so you can see what is happening…
http://www.vanishingcookies.com/fla…/testloader.swf

you can download the source files here
http://www.vanishingcookies.com/fla…/testloader.zip

Here is the source code in question…

id = 0;
puz=“puz1.jpg”;//source image
imagewidth=300;//width of source image
imageheight=300;//height of source image
rows=4; //number of rows – this will change
cols=4; //number of columns – this will change
xsize=imagewidth/cols; //calculate the size of each peice
ysize=imagewidth/rows;
map = new Array();
map[0] = [];
map[1] = [];
map[2] = [];
xstart = 20; //start coordinates of grid
ystart = 20;
pieceArray = [0];
//pieceArray[1]=id+1=_root.piece1;
scalex=imagewidth/100/cols; //calculate necessary scaling of target clip
trace (scalex);
scaley=imageheight/100/rows;
trace (scaley);

//Create and position pieces
for (var row = 0; row<rows; row++) {
for (var col = 0; col<cols; col++) {
id++; // peice number
attachMovie(“piece”, “piece”+id, id);
var clip = _root[“piece”+id];
// --------
trace (clip);
clip.id = id;
clip.row = row;
clip.col = col;
clip.orgRow = row;
clip.orgCol = col;
clip.numHint.txt = clip;
pieceArray.push(clip);
map[col][row] = clip;
clip._x = xsizecol+xstart;
clip._xscale = xsize;
clip._yscale = ysize;
clip._y = ysize
row+ystart;
loadMovie (“puz1.jpg”, “piece”+id+".loader");
picholder=“piece”+id+".loader"
xoffset=(-xsizecol);
yoffset=(-ysize
row);
trace (xoffset);
trace (yoffset);
setProperty (picholder, _x, xoffset);
setProperty (picholder, _y, yoffset);
}
}

here is the corrected code if it helps someone else… basic presumption was right… I just scale the jpg image it to the inverse of the previous scaling to the holder

id = 0;
puz="puz1.jpg"
imagewidth=300;
imageheight=300;
rows=10;
cols=10;
xsize=imagewidth/cols;
ysize=imagewidth/rows;
map = new Array();
xstart = 20;
ystart = 20;
pieceArray = [0];
//pieceArray[1]=id+1=_root.piece1;

for (var row = 0; row<rows; row++) {
for (var col = 0; col<cols; col++) {
id++;
attachMovie(“piece”, “piece”+id, id);
var clip = _root[“piece”+id];
// --------
trace (clip);
clip.id = id;
clip.row = row;
clip.col = col;
clip.orgRow = row;
clip.orgCol = col;
clip.numHint.txt = clip;
pieceArray.push(clip);
map[col][row] = clip;
clip._x = xsizecol+xstart;
clip._xscale = 3/cols
100;
clip._yscale = 3/rows100;
clip._y = ysize
row+ystart;
loadMovie (“puz1.jpg”, “piece”+id+".loader");
picholder=“piece”+id+".loader"
xoffset=(-xsizecolcols/3);
yoffset=(-ysizerowrows/3);
trace (xoffset);
trace (yoffset);
setProperty (picholder, _x, xoffset);
setProperty (picholder, _y, yoffset);
setProperty (picholder, _xscale, cols/3100);
setProperty (picholder, _yscale, rows/3
100);

 }

}