Всем привет. Есть прога, должна по введенным данным растягивать и крутить прямоугольник вокруг любой вершины. Ошибся где-то в коде, который поворачивает фигуру. Видимо надо просчитывать точку вершины... Если, кто знает в чем проблема и как ее решить, жду Ваших советов.

Код AS1/AS2:
depth = 1;
x0=0;
y0=0;
w=100;
h=100;
a=0;
createClassObject(mx.controls.Label, "rectSize", depth, {text:"Размеры"});
rectSize._x = 55;
rectSize._y = 10;
depth++;
createClassObject(mx.controls.Label, "rectWidth", depth, {text:"Длина:"});
rectWidth._x = 10;
rectWidth._y = 30;
depth++;
createClassObject(mx.controls.Label, "rectHeight", depth, {text:"Ширина:"});
rectHeight._x = 10;
rectHeight._y = 60;
depth++;
createClassObject(mx.controls.TextInput, "Txt1", depth, {text:"100"});
Txt1._x = 70;
Txt1._y = 30;
depth++;
createClassObject(mx.controls.TextInput, "Txt2", depth, {text:"60"});
Txt2._x = 70;
Txt2._y = 60;
depth++;
createClassObject(mx.controls.Label, "rectRot", depth, {text:"Поворот"});
rectRot._x = 58;
rectRot._y = 90;
depth++;
createClassObject(mx.controls.Label, "num", depth, {text:"Вершина:"});
num._x = 10;
num._y = 110;
depth++;
createClassObject(mx.controls.Label, "angle", depth, {text:"Угол:"});
angle._x = 10;
angle._y = 140;
depth++;
createClassObject(mx.controls.TextInput, "Txt3", depth, {text:"1"});
Txt3._x = 70;
Txt3._y = 110;
depth++;
createClassObject(mx.controls.TextInput, "Txt4", depth, {text:"15"});
Txt4._x = 70;
Txt4._y = 140;
depth++;
this.createEmptyMovieClip("square_mc", this.getNextHighestDepth());
this.square_mc.beginFill(0xCCCCCC, 100);
this.square_mc.moveTo(x0, y0);
this.square_mc.lineTo(x0+w, y0);
this.square_mc.lineTo(x0+w, y0+h);
this.square_mc.lineTo(x0, y0+h);
this.square_mc.endFill();
this.square_mc._x=this.square_mc._y=100;
this.square_mc.setRotation = function (rotation, x_center, y_center)
{
var old_obj = {x:x_center, y:y_center}
var new_obj = {x:x_center, y:y_center}
this.localToGlobal(old_obj)
this._rotation = rotation
this.localToGlobal(new_obj)
this._x +=old_obj.x-new_obj.x
this._y +=old_obj.y-new_obj.y
}
this.square_mc.onPress = function()
{
w=parseInt(Txt1.text);//длина
h=parseInt(Txt2.text);//ширина
p=parseInt(Txt3.text);//номер вершины 1234
r=parseInt(Txt4.text);//угол поворота
a+=r;
if(a/360==0) a=0;
//изменение назмеров мовиклипа
/*if((w!=this._width)|(h!=this._height))
{
trace("dgdfgdfhfghfghfh");
this.setRotation(0, 0, 0);
this._width=w;
this._height=h;
}*/
trace("Ширина: "+this._height);
trace("Длина: "+this._width);
if(p==1)
{
this.setRotation(a, 0, 0);
}
else
if(p==2)
{
this.setRotation(a, this._width, 0);
}
else
if(p==3)
{
this.setRotation(a, this._width, this._height);
}
else
{
this.setRotation(a, 0, this._height);
}
trace(a);
}