您的位置:首页 > 其它

Flex中如何利用Matrix类的rotate函数对图片进行旋转操作的例子

2010-04-23 09:54 686 查看
<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

layout="horizontal"

verticalAlign="middle"

backgroundColor="white">

<mx:String id="deg">°</mx:String>

<mx:Script>

<![CDATA[

import mx.core.UIComponent;

private function img1_effectEnd():void {

/* Set the appropriate Label text. */

lbl1.text = "img1.rotation = " + img1.rotation.toString() + deg;

}

private function img2_creationComplete():void {

/* "Copy" the existing matrix. */

var m1:Matrix = img2.transform.matrix;

/* Rotate the matrix 45 degrees (note that we have to

convert from degrees to radians since the rotate()

method expects radians. */

m1.rotate(degreesToRadians(45));

/* Concatenate the original matrix onto the rotated

matrix so we don't lose the original X and Y

coordinates and any other effects. */

m1.concat(img2.transform.matrix);

/* "Copy" the new matrix over the existing matrix. */

img2.transform.matrix = m1;

/* Set the appropriate Label text. */

lbl2.text = "img2.rotation = " + img2.rotation.toString() + deg;

}

private function img_rollOver(cTarget:UIComponent):void {

cTarget.toolTip = cTarget.name + ".rotation = " + cTarget.rotation.toString();

}

private function radiansToDegrees(radians:Number):Number {

var degrees:Number = radians * (180 / Math.PI);

return degrees;

}

private function degreesToRadians(degrees:Number):Number {

var radians:Number = degrees * (Math.PI / 180);

return radians;

}

]]>

</mx:Script>

<mx:Rotate id="rotate" angleFrom="0" angleTo="45" duration="1" />

<mx:ApplicationControlBar dock="true">

<mx:Label id="lbl1" />

<mx:Spacer width="50" />

<mx:Label id="lbl2" />

</mx:ApplicationControlBar>

<mx:Image id="img1"

source="http://www.helpexamples.com/flash/images/logo.png"

creationCompleteEffect="{rotate}"

effectEnd="img1_effectEnd();"

rollOver="img_rollOver(UIComponent(event.currentTarget));" />

<mx:Spacer width="50" />

<mx:Image id="img2"

source="http://www.helpexamples.com/flash/images/logo.png"

creationComplete="img2_creationComplete();"

rollOver="img_rollOver(UIComponent(event.currentTarget));" />

</mx:Application>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐