# Flash/Flex学习笔记(56)：矩阵变换

As3.0中的Matix类跟这个类似：

tx,ty的平移示例：

```import fl.events.SliderEvent;

var box:Box = new Box();
var startX:Number = stage.stageWidth/2 ;
var startY:Number = stage.stageHeight/2 ;
box.x = startX;
box.y = startY;

function slider_tx_ChangeHandler(e:SliderEvent):void{
txt_tx.text = e.value.toString();
var tempMatrix:Matrix = box.transform.matrix;
tempMatrix.tx = startX + e.value;
box.transform.matrix = tempMatrix;

}

function slider_ty_ChangeHandler(e:SliderEvent):void{
txt_ty.text = e.value.toString();
var tempMatrix:Matrix = box.transform.matrix;
tempMatrix.ty = startY + e.value;
box.transform.matrix = tempMatrix;
}```

a,d缩放示例：

```import fl.events.SliderEvent;

var box:Box = new Box();
var startX:Number = stage.stageWidth/2;
var startY:Number = stage.stageHeight/2;
box.x = startX;
box.y = startY;

function silder_scaleX_ChangeHandler(e:SliderEvent):void{
txt_tx.text = e.value.toString();
var tempMatrix:Matrix = box.transform.matrix;
tempMatrix.a = e.value;//x轴缩放
box.transform.matrix = tempMatrix;

}

function silder_scaleY_ChangeHandler(e:SliderEvent):void{
txt_ty.text = e.value.toString();
var tempMatrix:Matrix = box.transform.matrix;
tempMatrix.d = e.value; //y轴缩放
box.transform.matrix = tempMatrix;
}```

a,b,c,d 旋转示例：

```import fl.events.SliderEvent;

var box:Box = new Box(50,100,0x00ff00);
var startX:Number = stage.stageWidth/2 ;
var startY:Number = stage.stageHeight/2 ;
box.x = startX;
box.y = startY;

var box2:Box = new Box(100,75,0xff6600);

box2.x = startX;
box2.y = startY;

function silder_Angle_ChangeHandler(e:SliderEvent):void{
txt_tx.text = e.value.toString();

var angle = e.value * Math.PI /180;
//trace(angle);

var sin = Math.sin(angle);
var cos = Math.cos(angle);

var tempMatrix:Matrix = box.transform.matrix;
tempMatrix.a = cos;
tempMatrix.b = sin;
tempMatrix.c = -sin;
tempMatrix.d = cos;
box.transform.matrix = tempMatrix;
box2.transform.matrix = tempMatrix;

}```

b,c 倾斜示例：

```import fl.events.SliderEvent;

var box:Box = new Box(50,50);
var startX:Number = stage.stageWidth/2 ;
var startY:Number = stage.stageHeight/2 ;
box.x = startX;
box.y = startY;

function silder_skewX_ChangeHandler(e:SliderEvent):void{
txt_tx.text = e.value.toString();
var angle = e.value * Math.PI /180;
var tan = Math.tan(angle);
var tempMatrix:Matrix = box.transform.matrix;
tempMatrix.c = tan;
box.transform.matrix = tempMatrix;
}

function silder_skewY_ChangeHandler(e:SliderEvent):void{
txt_ty.text = e.value.toString();
var angle = e.value * Math.PI /180;
var tan = Math.tan(angle);
var tempMatrix:Matrix = box.transform.matrix;
tempMatrix.b = tan;
box.transform.matrix = tempMatrix;
}```

992 篇文章76 人订阅

0 条评论

## 相关文章

1545

### 从零开始学 Web 之 CSS3（五）transform

transform 字面上就是变形，改变的意思。在CSS3中transform主要包括以下几种：移动 translate，缩放scale，旋转rotate，翻转...

1372

1505

963

3476

2267

1.5K13

2515

4135

2377